Make WordPress Core

Changeset 35872


Ignore:
Timestamp:
12/11/2015 09:59:01 PM (8 years ago)
Author:
johnbillion
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/user/capabilities.php

    r35871 r35872  
    232232    }
    233233
     234    // test the tests
     235    function test_all_caps_of_users_are_being_tested() {
     236        $users = array(
     237            'administrator' => self::factory()->user->create_and_get( array( 'role' => 'administrator' ) ),
     238            'editor'        => self::factory()->user->create_and_get( array( 'role' => 'editor' ) ),
     239            'author'        => self::factory()->user->create_and_get( array( 'role' => 'author' ) ),
     240            'contributor'   => self::factory()->user->create_and_get( array( 'role' => 'contributor' ) ),
     241            'subscriber'    => self::factory()->user->create_and_get( array( 'role' => 'subscriber' ) ),
     242        );
     243        $caps = $this->getCapsAndRoles();
     244
     245        // `manage_links` is a special case
     246        $this->assertSame( '0', get_option( 'link_manager_enabled' ) );
     247        // `unfiltered_upload` is a special case
     248        $this->assertFalse( defined( 'ALLOW_UNFILTERED_UPLOADS' ) );
     249
     250        foreach ( $users as $role => $user ) {
     251
     252            // make sure the user is valid
     253            $this->assertTrue( $user->exists(), "User with {$role} role does not exist" );
     254
     255            $user_caps = $user->allcaps;
     256
     257            unset(
     258                // `manage_links` is a special case
     259                $user_caps['manage_links'],
     260                // `unfiltered_upload` is a special case
     261                $user_caps['unfiltered_upload']
     262            );
     263
     264            $diff = array_diff( array_keys( $user_caps ), array_keys( $caps ) );
     265
     266            $this->assertEquals( array(), $diff, "User with {$role} role has capabilities that aren't being tested" );
     267
     268        }
     269
     270    }
     271
    234272    // test the default roles and caps
    235273    function test_all_roles_and_caps() {
Note: See TracChangeset for help on using the changeset viewer.