Skip to content

Tests: Add coverage for the Toolbar edit, Edit Site and appearance menus. - #15522

Open
hmbashar wants to merge 3 commits into
WordPress:trunkfrom
hmbashar:66491-admin-bar-tests-edit-appearance
Open

hmbashar wants to merge 3 commits into
WordPress:trunkfrom
hmbashar:66491-admin-bar-tests-edit-appearance

Conversation

@hmbashar

@hmbashar hmbashar commented Nov 5, 2026

Copy link
Copy Markdown

Adds unit tests for the Toolbar (Admin Bar) edit, Edit Site and appearance menus in tests/phpunit/tests/adminbar.php. This is the second group of the test coverage work proposed in the ticket, and is independent from the first group in #15521. No behavior is changed.

Functions covered:

  • wp_admin_bar_edit_menu()
    • Front end: the "Edit" link for the queried post, page, term and user, including the title, URL and icon.
    • Front end: no link without the edit capability, for post types hidden from the Toolbar, or when nothing is queried.
    • Admin: "View Post" for a published post, "Preview" for a draft, nothing on the screen for adding a post, and "View Post" on the Comments screen for a single post.
    • Admin: "View Category" for a publicly viewable term and nothing for a term that is not, and "View User" on the user edit screen.
  • wp_admin_bar_edit_site_menu()
    • "Edit Site" link and its URL for block themes.
    • Not added for classic themes, for users who cannot edit theme options, or in the admin.
  • wp_admin_bar_appearance_menu()
    • The group is always added, with no items for users without theme capabilities.
    • Themes link for users who can switch themes.
    • Widgets, Menus, Background and Header links depending on the theme features.

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 (draft preview branch, edit_theme_options guard, Edit Site admin guard, publicly viewable term check, user view link) 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.

…nus.

Adds tests for `wp_admin_bar_edit_menu()`, `wp_admin_bar_edit_site_menu()` and `wp_admin_bar_appearance_menu()`, covering the front end edit links for posts, terms and users, the view and preview links in the admin, block and classic themes, capability checks and the theme feature dependent items.

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

🟡 Changes recommended

The cleanup unsets background/header globals without restoring them, causing later tests to emit undefined-global warnings and making the suite order-dependent.

1 open issue
What changed in this PR

Adds the second group of Toolbar test coverage for ticket #66491, complementing #15521 without changing production behavior.

Changes:

  • Covers front-end Edit links and admin View/Preview links across queried objects and capability checks.
  • Tests Edit Site availability for block themes, permissions, and admin contexts.
  • Tests appearance menu links based on user capabilities and theme support.
File Description
tests/​phpunit/​tests/​adminbar.php Adds tests for the Toolbar edit, Edit Site, and appearance menus.

Review effort: Balanced

Comment thread tests/phpunit/tests/adminbar.php Resolved
…ppearance menu test.

`remove_theme_support()` unsets `$custom_background` and `$custom_image_header`, which restoring `$_wp_theme_features` does not bring back, so a later test reading them emitted an undefined global error. `add_theme_support()` only stores the feature, so restoring the saved features is enough.

See #66491.

@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, and for the quick update! I really appreciate you taking the time to add comprehensive coverage for the Toolbar edit, Edit Site, and appearance menus—these functions build key parts of the admin bar and had very little direct test coverage before.

I left a small note inline.

AI Review: Gemini 3.8 Flash

Comment thread tests/phpunit/tests/adminbar.php Resolved
…te menu test.

Calling `unset()` on a variable declared with `global` only removes the local reference, so `$_wp_current_template_id` stayed set for the tests that run afterwards.

See #66491.

@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 the quick follow-up, @hmbashar! The global template ID cleanup in e6b044b2 looks great. Everything in this PR is now completely clean, well-tested, and ready to go.

AI Review: Gemini 3.8 Flash

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants