Make WordPress Core

Changeset 49604


Ignore:
Timestamp:
11/15/2020 02:17:31 PM (4 years ago)
Author:
johnbillion
Message:

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

File:
1 edited

Legend:

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

    r49603 r49604  
    99class Tests_User_Capabilities extends WP_UnitTestCase {
    1010
    11     protected static $users       = array(
     11    /**
     12     * @var WP_User[] $users
     13     */
     14    protected static $users = array(
    1215        'administrator' => null,
    1316        'editor'        => null,
     
    1619        'subscriber'    => null,
    1720    );
     21
     22    /**
     23     * @var WP_User $super_admin
     24     */
    1825    protected static $super_admin = null;
    1926
     27    /**
     28     * @var int $block_id
     29     */
    2030    protected static $block_id;
    2131
     
    533543                }
    534544            }
    535         }
    536 
    537         $this->assertFalse( $user->has_cap( 'start_a_fire' ), "User with the {$role} role should not have a custom capability" );
    538         $this->assertFalse( user_can( $user, 'start_a_fire' ), "User with the {$role} role should not have a custom capability" );
    539 
    540         $this->assertFalse( $user->has_cap( 'do_not_allow' ), "User with the {$role} role should not have the do_not_allow capability" );
    541         $this->assertFalse( user_can( $user, 'do_not_allow' ), "User with the {$role} role should not have the do_not_allow capability" );
    542 
    543         $this->assertTrue( $user->has_cap( 'exist' ), "User with the {$role} role should have the exist capability" );
    544         $this->assertTrue( user_can( $user, 'exist' ), "User with the {$role} role should have the exist capability" );
     545
     546            $this->assertFalse( $user->has_cap( 'start_a_fire' ), "User with the {$role} role should not have a custom capability" );
     547            $this->assertFalse( user_can( $user, 'start_a_fire' ), "User with the {$role} role should not have a custom capability" );
     548
     549            $this->assertFalse( $user->has_cap( 'do_not_allow' ), "User with the {$role} role should not have the do_not_allow capability" );
     550            $this->assertFalse( user_can( $user, 'do_not_allow' ), "User with the {$role} role should not have the do_not_allow capability" );
     551
     552            $this->assertTrue( $user->has_cap( 'exist' ), "User with the {$role} role should have the exist capability" );
     553            $this->assertTrue( user_can( $user, 'exist' ), "User with the {$role} role should have the exist capability" );
     554        }
    545555    }
    546556
Note: See TracChangeset for help on using the changeset viewer.