Make WordPress Core

Changeset 38731


Ignore:
Timestamp:
10/05/2016 04:56:32 PM (8 years ago)
Author:
johnbillion
Message:

Role/Capability: Reuse some user account fixtures in the user capability tests.

See #38235

File:
1 edited

Legend:

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

    r38698 r38731  
    975975     */
    976976    function test_create_posts_caps() {
    977         $author = new WP_User( self::factory()->user->create( array( 'role' => 'author' ) ) );
    978         $admin = new WP_User( self::factory()->user->create( array( 'role' => 'administrator' ) ) );
    979         $author_2 = new WP_User( self::factory()->user->create( array( 'role' => 'author' ) ) );
    980         $editor = new WP_User( self::factory()->user->create( array( 'role' => 'editor' ) ) );
    981         $contributor = new WP_User( self::factory()->user->create( array( 'role' => 'contributor' ) ) );
     977        $admin       = self::$users['administrator'];
     978        $author      = self::$users['author'];
     979        $editor      = self::$users['editor'];
     980        $contributor = self::$users['contributor'];
    982981
    983982        // create_posts isn't a real cap.
     
    985984        $this->assertFalse($author->has_cap('create_posts'));
    986985        $this->assertFalse($editor->has_cap('create_posts'));
    987         $this->assertFalse($author_2->has_cap('create_posts'));
    988986        $this->assertFalse($contributor->has_cap('create_posts'));
    989987
     
    992990
    993991        $this->assertEquals( 'edit_posts', $cap->create_posts );
    994 
    995         $this->assertTrue($admin->has_cap( $cap->create_posts ));
    996992
    997993        $this->assertTrue($admin->has_cap( $cap->create_posts ));
    998994        $this->assertTrue($author->has_cap( $cap->create_posts ));
    999995        $this->assertTrue($editor->has_cap( $cap->create_posts ));
    1000         $this->assertTrue($author_2->has_cap( $cap->create_posts ));
    1001996        $this->assertTrue($contributor->has_cap( $cap->create_posts ));
    1002997
     
    10121007        $this->assertFalse($author->has_cap( $cap->create_posts ));
    10131008        $this->assertFalse($editor->has_cap( $cap->create_posts ));
    1014         $this->assertFalse($author_2->has_cap( $cap->create_posts ));
    10151009        $this->assertFalse($contributor->has_cap( $cap->create_posts ));
    10161010
     
    10211015        $this->assertFalse($author->has_cap( $cap->create_posts ));
    10221016        $this->assertFalse($editor->has_cap( $cap->create_posts ));
    1023         $this->assertFalse($author_2->has_cap( $cap->create_posts ));
    10241017        $this->assertFalse($contributor->has_cap( $cap->create_posts ));
     1018
     1019        $admin->remove_cap( 'edit_foobars' );
    10251020
    10261021        _unregister_post_type( 'foobar' );
     
    12011196     */
    12021197    function test_negative_caps() {
    1203         $author = new WP_User( self::factory()->user->create( array( 'role' => 'author' ) ) );
     1198        $author = self::$users['author'];
    12041199        $author->add_cap( 'foo', false );
    12051200        $this->assertTrue ( isset( $author->caps['foo'] ) );
     
    12121207     */
    12131208    function test_set_role_same_role() {
    1214         $user = new WP_User( self::factory()->user->create( array( 'role' => 'administrator' ) ) );
     1209        $user = self::$users['administrator'];
    12151210        $caps = $user->caps;
    12161211        $this->assertNotEmpty( $user->caps );
     
    12231218        global $wpdb;
    12241219
    1225         $user = new WP_User( self::factory()->user->create( array( 'role' => 'administrator' ) ) );
     1220        $user = self::$users['administrator'];
    12261221        $old_uid = get_current_user_id();
    12271222        wp_set_current_user( $user->ID );
Note: See TracChangeset for help on using the changeset viewer.