Skip to content

Tests: Add coverage for the Toolbar icon, sidebar toggle and command palette items. - #15525

Open
hmbashar wants to merge 1 commit into
WordPress:trunkfrom
hmbashar:66491-admin-bar-tests-sidebar-icon-palette
Open

hmbashar wants to merge 1 commit into
WordPress:trunkfrom
hmbashar:66491-admin-bar-tests-sidebar-icon-palette

Conversation

@hmbashar

@hmbashar hmbashar commented Nov 5, 2026

Copy link
Copy Markdown

Adds unit tests for the Toolbar (Admin Bar) icon helper, sidebar toggle and command palette button in tests/phpunit/tests/adminbar.php. This is the last group of the test coverage work proposed in the ticket, and is independent from the other groups. No behavior is changed.

Functions covered:

  • _wp_admin_bar_icon()
    • Wraps the SVG of a registered icon in the ab-icon svg-icon element.
    • Returns an empty string for an icon that is not registered.
  • wp_admin_bar_sidebar_toggle()
    • Added in the admin, with its icon, URL and hidden label.
    • Not added on the front end.
  • wp_admin_bar_command_palette_menu()
    • Added in the admin when the wp-core-commands script is enqueued: icon, URL, onclick, class, label and inline script.
    • The Ctrl+K label by default and the ⌘K label for an Apple user agent.
    • Not added when the script is not enqueued, or on the front end.

The tests that depend on the enqueued scripts use a fresh WP_Scripts instance, which is restored afterwards, and the user agent is restored too.

Testing:

  • vendor/bin/phpunit --filter Tests_AdminBar
  • vendor/bin/phpunit -c tests/phpunit/multisite.xml --filter Tests_AdminBar
  • vendor/bin/phpcs tests/phpunit/tests/adminbar.php

I also temporarily broke the related lines in src/wp-includes/admin-bar.php (sidebar toggle admin guard, command palette script and admin guards, Apple user agent detection, icon empty check and wrapper class) and confirmed that a new test fails for each one.

Trac ticket: https://core.trac.wordpress.org/ticket/66491

Use of AI Tools

AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Sonnet 5.5
Used for: Written with AI and manually reviewed by me.


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

…palette items.

Adds tests for `_wp_admin_bar_icon()`, `wp_admin_bar_sidebar_toggle()` and `wp_admin_bar_command_palette_menu()`, covering the icon markup, the admin only behavior of the sidebar toggle, and the conditions, keyboard shortcut label and script of the command palette button.

See #66491.
@github-actions

github-actions Bot commented Nov 5, 2026

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs.

Core Committers: Use this line as a base for the props when committing in SVN:

Props hmbashar.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

There are no active review issues for the added Admin Bar test coverage.

No open issues 🎉

What changed in this PR

Adds Toolbar (Admin Bar) test coverage for Trac ticket #66491 without changing production behavior.

Changes:

  • Tests registered and unknown icon markup, plus sidebar toggle visibility and attributes.
  • Covers command palette visibility, button metadata, inline script presence, and Windows/Apple shortcut labels.
  • Isolates script state and restores modified globals after command palette setup.
File Description
tests/​phpunit/​tests/​adminbar.php Adds eight tests covering icons, the sidebar toggle, and command palette items.

Review effort: Balanced

@huzaifaalmesbah huzaifaalmesbah left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this, @hmbashar! I really appreciate you taking the time to cover the Toolbar icon helper, sidebar toggle, and command palette button—these items add important admin functionality and had no direct tests before.

I reviewed the changes against Core standards, verified fixture hygiene (including clean restoration of scripts, user agent, and icon registry state), and checked all scenarios. Everything looks solid, cleanly isolated, and ready to go.

AI Review: Gemini 3.8 Flash

@lancewillett lancewillett left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Windows and Apple shortcut cases and the script-enqueue guard are worth keeping. Please simplify their setup. I ran the six sidebar and command-palette cases with a fresh WP_Admin_Bar and a direct call to the callback under test. Their node assertions passed in both single-site and multisite without logging in an editor or running every Toolbar callback. One integration case can still cover hook registration if that is part of the intended coverage.

Please also drop the exact sourceURL assertion. Renaming that debugger label would fail the test even if the command palette still opens and displays the correct shortcut. The node and shortcut assertions cover the behavior users see.

AI review · gpt-6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In review

Development

Successfully merging this pull request may close these issues.

4 participants