WordPress.org

Make WordPress Core

Changeset 49932


Ignore:
Timestamp:
01/04/2021 11:32:49 PM (11 months ago)
Author:
peterwilsoncc
Message:

Tests: Increase use of shared fixtures in capability checks.

See #51802.

Location:
trunk/tests/phpunit/tests/user
Files:
2 edited

Legend:

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

    r48937 r49932  
    1616        self::$author_id = $factory->user->create(
    1717            array(
    18                 'role'        => 'author',
    19                 'user_login'  => 'test_author',
    20                 'description' => 'test_author',
     18                'role'         => 'author',
     19                'user_login'   => 'test_author',
     20                'display_name' => 'Test Author',
     21                'description'  => 'test_author',
    2122            )
    2223        );
     
    4950
    5051        $this->assertSame( $user->display_name, $author_name );
    51         $this->assertSame( 'test_author', $author_name );
     52        $this->assertSame( 'Test Author', $author_name );
    5253    }
    5354
     
    5556        $this->assertSame( 'test_author', get_the_author_meta( 'login' ) );
    5657        $this->assertSame( 'test_author', get_the_author_meta( 'user_login' ) );
    57         $this->assertSame( 'test_author', get_the_author_meta( 'display_name' ) );
     58        $this->assertSame( 'Test Author', get_the_author_meta( 'display_name' ) );
    5859
    5960        $this->assertSame( 'test_author', trim( get_the_author_meta( 'description' ) ) );
     
    111112     */
    112113    public function test_get_the_author_posts_link_no_permalinks() {
    113         $author = self::factory()->user->create_and_get(
    114             array(
    115                 'display_name'  => 'Foo',
    116                 'user_nicename' => 'bar',
    117             )
    118         );
     114        $author = get_userdata( self::$author_id );
    119115
    120116        $GLOBALS['authordata'] = $author->data;
     
    125121
    126122        $this->assertContains( $url, $link );
    127         $this->assertContains( 'Posts by Foo', $link );
    128         $this->assertContains( '>Foo</a>', $link );
     123        $this->assertContains( 'Posts by Test Author', $link );
     124        $this->assertContains( '>Test Author</a>', $link );
    129125
    130126        unset( $GLOBALS['authordata'] );
     
    137133        $this->set_permalink_structure( '/%postname%/' );
    138134
    139         $author = self::factory()->user->create_and_get(
    140             array(
    141                 'display_name'  => 'Foo',
    142                 'user_nicename' => 'bar',
    143             )
    144         );
     135        $author = get_userdata( self::$author_id );
    145136
    146137        $GLOBALS['authordata'] = $author;
     
    153144
    154145        $this->assertContains( $url, $link );
    155         $this->assertContains( 'Posts by Foo', $link );
    156         $this->assertContains( '>Foo</a>', $link );
     146        $this->assertContains( 'Posts by Test Author', $link );
     147        $this->assertContains( '>Test Author</a>', $link );
    157148
    158149        unset( $GLOBALS['authordata'] );
  • trunk/tests/phpunit/tests/user/capabilities.php

    r49605 r49932  
    10051005    function test_user_add_cap() {
    10061006        // There are two contributors.
    1007         $id_1 = self::factory()->user->create( array( 'role' => 'contributor' ) );
     1007        $id_1 = self::$users['contributor']->ID;
    10081008        $id_2 = self::factory()->user->create( array( 'role' => 'contributor' ) );
    10091009
     
    10441044    function test_user_remove_cap() {
    10451045        // There are two contributors.
    1046         $id_1 = self::factory()->user->create( array( 'role' => 'contributor' ) );
     1046        $id_1 = self::$users['contributor']->ID;
    10471047        $id_2 = self::factory()->user->create( array( 'role' => 'contributor' ) );
    10481048
     
    10761076    function test_user_level_update() {
    10771077        // User starts as an author.
    1078         $id   = self::factory()->user->create( array( 'role' => 'author' ) );
     1078        $id   = self::$users['author']->ID;
    10791079        $user = new WP_User( $id );
    10801080        $this->assertTrue( $user->exists(), "Problem getting user $id" );
     
    10991099    function test_user_remove_all_caps() {
    11001100        // User starts as an author.
    1101         $id   = self::factory()->user->create( array( 'role' => 'author' ) );
     1101        $id   = self::$users['author']->ID;
    11021102        $user = new WP_User( $id );
    11031103        $this->assertTrue( $user->exists(), "Problem getting user $id" );
     
    11541154
    11551155        // Add some other users.
    1156         $admin       = new WP_User( self::factory()->user->create( array( 'role' => 'administrator' ) ) );
     1156        $admin       = self::$users['administrator'];
    11571157        $author_2    = new WP_User( self::factory()->user->create( array( 'role' => 'author' ) ) );
    1158         $editor      = new WP_User( self::factory()->user->create( array( 'role' => 'editor' ) ) );
    1159         $contributor = new WP_User( self::factory()->user->create( array( 'role' => 'contributor' ) ) );
     1158        $editor      = self::$users['editor'];
     1159        $contributor = self::$users['contributor'];
    11601160
    11611161        // Administrators, editors and the post owner can edit it.
     
    19011901     */
    19021902    function test_wp_logout_should_clear_current_user() {
    1903         $user_id = self::factory()->user->create();
     1903        $user_id = self::$users['author']->ID;
    19041904        wp_set_current_user( $user_id );
    19051905
Note: See TracChangeset for help on using the changeset viewer.