From 3348774d3a5ae3f9b97e7dbaf6a751650742e726 Mon Sep 17 00:00:00 2001 From: johnbillion Date: Fri, 11 Dec 2015 21:59:01 +0000 Subject: [PATCH] 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 --- tests/phpunit/tests/user/capabilities.php | 38 +++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/tests/phpunit/tests/user/capabilities.php b/tests/phpunit/tests/user/capabilities.php index 329ef7aa62..77ec3b1056 100644 --- a/tests/phpunit/tests/user/capabilities.php +++ b/tests/phpunit/tests/user/capabilities.php @@ -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(