Repository navigation
Tests: Add unit test coverage for user_can_access_admin_page() - #14372
huzaifaalmesbah wants to merge 1 commit into
Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the 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. |
mukeshpanchal27
left a comment
There was a problem hiding this comment.
The tests look good, and the global handling in set_up() and tear_down() is careful. One optional suggestion inline.
| 'editor', | ||
| true, | ||
| ), | ||
| 'top-level plugin page marked as not accessible' => array( |
There was a problem hiding this comment.
Optional: this case returns false from the _wp_menu_nopriv check. It would also return false if the hook name did not match _registered_pages. A paired case without _wp_menu_nopriv that returns true would prove the test hits the intended branch:
'top-level plugin page not in a menu' => array(
array(
'pagenow' => 'admin.php',
'plugin_page' => 'hidden-plugin',
'_registered_pages' => array( 'admin_page_hidden-plugin' => true ),
),
'administrator',
true,
),
lancewillett
left a comment
There was a problem hiding this comment.
Reviewed the tests against the implementation and existing coverage, including the unit-tests audit. No blocking findings. The affected classes passed locally in randomized order on single site (21 tests) and multisite (21 tests); PHPCS and current CI pass.
Optional follow-up: pair the hidden-plugin denial case with an accessible case lacking _wp_menu_nopriv, to isolate the denial branch.
AI review · gpt-6
Check capability and registration decisions for core submenus, plugin pages, hidden pages, and parent-menu fallbacks. Restore menu and request globals between cases. Developed in: #14372 Props huzaifaalmesbah, mukesh27. See #65819. git-svn-id: https://develop.svn.wordpress.org/trunk@64464 602fd350-edb4-49c9-b593-d223f7449a82
|
PR #14372 landed in https://core.trac.wordpress.org/changeset/64464 |
Check capability and registration decisions for core submenus, plugin pages, hidden pages, and parent-menu fallbacks. Restore menu and request globals between cases. Developed in: WordPress/wordpress-develop#14372 Props huzaifaalmesbah, mukesh27. See #65819. Built from https://develop.svn.wordpress.org/trunk@64464 git-svn-id: http://core.svn.wordpress.org/trunk@63614 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Description
Adds tests for
user_can_access_admin_page(), which decides whether the current user may load the current admin screen and had no direct coverage.The data provider sets up a menu, submenus and admin page hooks like those built in
wp-admin/menu.php, then checks each path through the function with administrator, editor and subscriber users:$_wp_submenu_nopriv;$_wp_menu_nopriv;$_wp_menu_noprivor any$_wp_submenu_nopriventry lists them;Removing each guard or capability check in the function makes at least one dataset fail, except the
$_wp_submenu_nopriv[ $pagenow ][ $pagenow ]check for pages without a parent, which the loop over all$_wp_submenu_noprivkeys that follows already covers.All menu globals used by the function are saved in
set_up()and restored intear_down().This is a test-only change; no production code is modified.
Testing Instructions
npm run test:php -- --filter 'Tests_Admin_Includes_Plugin_UserCanAccessAdminPage'npm run test:php -- --filter 'Tests_Admin_Includes_Plugin_UserCanAccessAdminPage' -c tests/phpunit/multisite.xmlnpm run test:php -- --filter 'Tests_Admin_Includes_Plugin_UserCanAccessAdminPage' --order-by=randomnpm run test:php -- --group pluginsnode ./tools/local-env/scripts/docker.js run --rm php ./vendor/bin/phpcs tests/phpunit/tests/admin/includes/plugin/userCanAccessAdminPage.phpTrac ticket: https://core.trac.wordpress.org/ticket/65819
Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5.5
Used for: Brainstorming edge-case scenarios and drafting test boilerplate; test architecture, assertions, and local PHPUnit verification were written and validated by me.