Repository navigation
Conversation
…u_page_url(). See #66557.
|
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: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
|
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are identified in the added PHPUnit coverage for admin menu registration and URL generation.
No open issues 🎉
What changed in this PR
Adds PHPUnit coverage for WordPress admin menu registration and URL generation, complementing the existing tests in includesPlugin.php. No production code is changed.
Changes:
- Tests menu structure, icons, slug normalization, permissions, callbacks, and page registration.
- Covers menu position handling, collisions, and submenu parent behavior.
- Tests URL output, missing pages, parent routing, and escaping.
| File | Description |
|---|---|
tests/phpunit/tests/admin/includes/plugin/menuPageUrl.php |
Adds tests for menu page URL generation and output. |
tests/phpunit/tests/admin/includes/plugin/addMenuPage.php |
Adds tests for top-level menu and submenu registration and positioning. |
Review effort: Balanced
huzaifaalmesbah
left a comment
There was a problem hiding this comment.
Thanks for the patch, @hmbashar! Excellent coverage for add_menu_page(), add_submenu_page(), and menu_page_url().
The global menu state backup and teardown ($menu, $submenu, $_parent_pages, $_registered_pages) are very well-handled, preventing test pollution. All 96 CI checks pass.
Looks great to me!
AI Review: Gemini 3.8 Flash
Summary
Adds tests for
add_menu_page(),add_submenu_page()andmenu_page_url(). The positions of submenus, the helper functions (add_options_page()and the others),wp_admin_page_exists()and the URLs of a few pages are already tested inincludesPlugin.php, so these tests add the structure of the menus and the cases that were missing.addMenuPage.phpadd_menu_page()adds the menu with all its keys and the hook name, with the default icon or with an icon (dashicon, data URI, URL with its scheme,none), and makes a slug in the plugins directory relative.$admin_page_hooks,$_registered_pagesand$_parent_pages, and hooks the callback only for a user who can access the page.add_submenu_page()starts the submenu with the parent menu (only when the user can access it), makes the slugs relative, uses the real file of a parent, records a page that the user cannot access, and registers the page and its callback.menuPageUrl.phpmenu_page_url()outputs the URL by default and not when$displayis false, returns an empty string for a page that does not exist, adds the page to the file of the parent, usesadmin.phpfor a parent that is a page, and escapes the URL.Testing
Mutation check: 24 changes to the three functions (the slug, the icon, the callback and its capability, the collision avoider, the registries, the real parent file, the pages that the user cannot access, the parent menu copy, the positions and the URL) were each caught by a test, on single-site and multisite.
One change was not caught and is equivalent: in
add_menu_page(),$position = null;after the notice about a position that is not a number. The condition that follows treats a position that is not numeric likenull.Trac ticket: https://core.trac.wordpress.org/ticket/66557
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.