Ensure that all the capabilities that any users have are being tested. This ensures that if new capabilities are introduced in the future, tests will be required for them.

See #35024


git-svn-id: https://develop.svn.wordpress.org/trunk@35872 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
johnbillion 2015-12-11 21:59:01 +00:00
parent a7f713f45d
commit 3348774d3a
1 changed files with 38 additions and 0 deletions

View File

@ -231,6 +231,44 @@ class Tests_User_Capabilities extends WP_UnitTestCase {
$this->assertEquals( array_keys( $single ), array_keys( $multi ) );
}
// test the tests
function test_all_caps_of_users_are_being_tested() {
$users = array(
'administrator' => self::factory()->user->create_and_get( array( 'role' => 'administrator' ) ),
'editor' => self::factory()->user->create_and_get( array( 'role' => 'editor' ) ),
'author' => self::factory()->user->create_and_get( array( 'role' => 'author' ) ),
'contributor' => self::factory()->user->create_and_get( array( 'role' => 'contributor' ) ),
'subscriber' => self::factory()->user->create_and_get( array( 'role' => 'subscriber' ) ),
);
$caps = $this->getCapsAndRoles();
// `manage_links` is a special case
$this->assertSame( '0', get_option( 'link_manager_enabled' ) );
// `unfiltered_upload` is a special case
$this->assertFalse( defined( 'ALLOW_UNFILTERED_UPLOADS' ) );
foreach ( $users as $role => $user ) {
// make sure the user is valid
$this->assertTrue( $user->exists(), "User with {$role} role does not exist" );
$user_caps = $user->allcaps;
unset(
// `manage_links` is a special case
$user_caps['manage_links'],
// `unfiltered_upload` is a special case
$user_caps['unfiltered_upload']
);
$diff = array_diff( array_keys( $user_caps ), array_keys( $caps ) );
$this->assertEquals( array(), $diff, "User with {$role} role has capabilities that aren't being tested" );
}
}
// test the default roles and caps
function test_all_roles_and_caps() {
$users = array(