From ea852af1513d05452a35a05a9022e8bc4bd6a157 Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Sun, 15 Nov 2020 14:17:31 +0000 Subject: [PATCH] Build/Test Tools: Ensure user capability assertions are performed for all default roles. The existing assertions were erroneously placed outside the iteration of all users, and therefore were only run against the last user in the list, which is the Subscriber role. See #51344, #32394 git-svn-id: https://develop.svn.wordpress.org/trunk@49604 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/tests/user/capabilities.php | 30 +++++++++++++++-------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/tests/phpunit/tests/user/capabilities.php b/tests/phpunit/tests/user/capabilities.php index b2d667b505..9a731b9477 100644 --- a/tests/phpunit/tests/user/capabilities.php +++ b/tests/phpunit/tests/user/capabilities.php @@ -8,15 +8,25 @@ */ class Tests_User_Capabilities extends WP_UnitTestCase { - protected static $users = array( + /** + * @var WP_User[] $users + */ + protected static $users = array( 'administrator' => null, 'editor' => null, 'author' => null, 'contributor' => null, 'subscriber' => null, ); + + /** + * @var WP_User $super_admin + */ protected static $super_admin = null; + /** + * @var int $block_id + */ protected static $block_id; public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) { @@ -532,16 +542,16 @@ class Tests_User_Capabilities extends WP_UnitTestCase { $this->assertFalse( user_can( $user, $cap ), "User with the {$role} role should not have the {$cap} capability" ); } } + + $this->assertFalse( $user->has_cap( 'start_a_fire' ), "User with the {$role} role should not have a custom capability" ); + $this->assertFalse( user_can( $user, 'start_a_fire' ), "User with the {$role} role should not have a custom capability" ); + + $this->assertFalse( $user->has_cap( 'do_not_allow' ), "User with the {$role} role should not have the do_not_allow capability" ); + $this->assertFalse( user_can( $user, 'do_not_allow' ), "User with the {$role} role should not have the do_not_allow capability" ); + + $this->assertTrue( $user->has_cap( 'exist' ), "User with the {$role} role should have the exist capability" ); + $this->assertTrue( user_can( $user, 'exist' ), "User with the {$role} role should have the exist capability" ); } - - $this->assertFalse( $user->has_cap( 'start_a_fire' ), "User with the {$role} role should not have a custom capability" ); - $this->assertFalse( user_can( $user, 'start_a_fire' ), "User with the {$role} role should not have a custom capability" ); - - $this->assertFalse( $user->has_cap( 'do_not_allow' ), "User with the {$role} role should not have the do_not_allow capability" ); - $this->assertFalse( user_can( $user, 'do_not_allow' ), "User with the {$role} role should not have the do_not_allow capability" ); - - $this->assertTrue( $user->has_cap( 'exist' ), "User with the {$role} role should have the exist capability" ); - $this->assertTrue( user_can( $user, 'exist' ), "User with the {$role} role should have the exist capability" ); } /**