Skip to content

Commit d1cde1a

Browse files
committed
WP/Capabilities: add tests for namespaced names
1 parent b09073a commit d1cde1a

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

WordPress/Tests/WP/CapabilitiesUnitTest.1.inc

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ add_menu_page( $pagetitle, 'menu_title', 'foo_bar', 'handle', 'function', 'icon_
6363
* Roles found instead of capabilities.
6464
*/
6565
add_posts_page( 'page_title', 'menu_title', 'administrator', 'menu_slug', 'function' ); // Error.
66-
add_media_page( 'page_title', 'menu_title', 'editor', 'menu_slug', 'function' ); // Error.
67-
add_pages_page( 'page_title', 'menu_title', 'author', 'menu_slug', 'function' ); // Error.
66+
\aDd_MeDiA_pAgE( 'page_title', 'menu_title', 'editor', 'menu_slug', 'function' ); // Error.
67+
ADD_PAGES_PAGE( 'page_title', 'menu_title', 'author', 'menu_slug', 'function' ); // Error.
6868
add_comments_page( 'page_title', 'menu_title', 'contributor', 'menu_slug', 'function' ); // Error.
6969
add_theme_page( 'page_title', $menu_title, 'subscriber', 'menu_slug', 'function' ); // Error.
7070
add_plugins_page( 'page_title', 'menu_title', 'super_admin', 'menu_slug', 'function' ); // Error.
@@ -111,4 +111,12 @@ add_menu_page( $p, $t, /* deliberately empty */, $slug, );
111111
add_menu_page( [] ); // Should bow out because the parameter is not found.
112112

113113
$obj->current_user_can( 'foo_bar' ); // Ok. We're not checking for method calls.
114-
My\NamespaceS\add_posts_page( 'page_title', 'menu_title', 'administrator', 'menu_slug', 'function' ); // Ok. We're not checking namespaced functions.
114+
115+
/*
116+
* Safeguard correct handling of all types of namespaced function calls.
117+
*/
118+
\add_posts_page( 'page_title', 'menu_title', 'administrator', 'menu_slug', 'function' ); // Bad.
119+
My\NamespaceS\current_user_can( 'administrator' ); // Ok.
120+
\MyNamespace\add_comments_page( 'page_title', 'menu_title', 'administrator', 'menu_slug', 'function' ); // Ok.
121+
namespace\author_can( $post, 'administrator' ); // The sniff should start flagging this once it can resolve relative namespaces.
122+
namespace\Sub\add_posts_page( 'page_title', 'menu_title', 'administrator', 'menu_slug', 'function' ); // Ok.

WordPress/Tests/WP/CapabilitiesUnitTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ public function getErrorList( $testFile = '' ) {
7373
78 => 1,
7474
85 => 1,
7575
106 => 1,
76+
118 => 1,
7677
);
7778

7879
case 'CapabilitiesUnitTest.3.inc':

0 commit comments

Comments
 (0)