Skip to content

Tests: Add coverage for the Toolbar My Account and My Sites menus. - #15521

Open
hmbashar wants to merge 2 commits into
WordPress:trunkfrom
hmbashar:66491-admin-bar-tests-account-my-sites
Open

hmbashar wants to merge 2 commits into
WordPress:trunkfrom
hmbashar:66491-admin-bar-tests-account-my-sites

Conversation

@hmbashar

@hmbashar hmbashar commented Nov 5, 2026 •

Copy link
Copy Markdown

Adds unit tests for the Toolbar (Admin Bar) My Account and My Sites menus in tests/phpunit/tests/adminbar.php. This is the first group of the test coverage work proposed in the ticket. No behavior is changed.

Functions covered:

  • wp_admin_bar_my_account_item() and wp_admin_bar_my_account_menu()
    • Nothing is added for logged-out visitors.
    • Node hierarchy: my-account, user-actions, user-info and logout.
    • "Edit Profile" label and tabindex, with and without a profile link.
    • Avatar vs. fallback icon, depending on show_avatars.
  • wp_admin_bar_my_sites_menu()
    • Not added on single site installs, for logged-out visitors, or for users with no sites.
    • Single site user: node hierarchy, titles and URLs of the site and its Dashboard, New Post, Manage Comments and Visit Site items.
    • Multiple sites: each site links to its own admin and front end.
    • Site where the user lacks the read capability: links to the front end and only offers "Visit Site".
    • Site name fallback to the URL (without scheme and www.) when the name is empty.
    • Site icon and the wp_admin_bar_show_site_icons filter.
    • Network Admin item URLs and the secondary class on the site list for super admins.

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 (avatar class, logged-out guard, no-sites guard, read capability branch, site name fallback, site icon filter, secondary 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.

Adds tests for `wp_admin_bar_my_account_item()`, `wp_admin_bar_my_account_menu()` and `wp_admin_bar_my_sites_menu()`, covering logged-out users, the node hierarchy, avatar and fallback icon handling, the "Edit Profile" label, single and multiple site users, sites without the `read` capability, the site name fallback, site icons and the Network Admin URLs.

See #66491.
@hmbashar
hmbashar marked this pull request as ready for review November 5, 2026 18:04
@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, huzaifaalmesbah.

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

No active review issues are reported for the added PHPUnit coverage of the Toolbar’s My Account and My Sites menus.

No open issues 🎉

What changed in this PR

Adds PHPUnit coverage for the Toolbar’s My Account and My Sites menus, supporting the test coverage work in Trac #66491 without changing production behavior.

Changes:

  • Tests My Account visibility, node hierarchy, profile labels, keyboard focus, and avatar behavior.
  • Tests My Sites visibility, site-specific links, capability restrictions, and site-name fallback.
  • Covers network admin links, secondary styling, site icons, and the icon visibility filter.
File Description
tests/​phpunit/​tests/​adminbar.php Adds My Account and My Sites menu tests for single-site and multisite installations.

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 My Account and My Sites menus—these build essential parts of the admin bar across single-site and multisite installs and had no direct test coverage before.

I reviewed the changes against Core standards, verified fixture hygiene, and ran through both single-site and multisite scenarios. Everything looks solid, cleanly isolated, and ready to go.

AI Review: Gemini 3.8 Flash

…into 66491-admin-bar-tests-account-my-sites

# Conflicts:
#	tests/phpunit/tests/adminbar.php

@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.

Please fold the single-site “no profile link” assertions into test_admin_bar_contains_correct_links_for_users_with_no_role(). That test already logs in the same no-role user, builds the Toolbar, and reads both nodes. I tried moving the tabindex and “Edit Profile” checks there and removing the second method. The randomized single-site class still passed.

For the network-admin links, please extend the existing super-admin test and its provider with the new URL expectations. That keeps the new destination checks alongside the eight node IDs already covered. The remaining parent and secondary-group assertions can stay focused. This also addresses the overlap John called out on Trac.

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