Make WordPress Core

Changeset 32000


Ignore:
Timestamp:
04/03/2015 02:13:11 PM (9 years ago)
Author:
boonebgorges
Message:

Unit tests verifying the filling of the 'roles' and 'caps' user properties during WP_User_Query.

See #31878.

File:
1 edited

Legend:

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

    r31669 r32000  
    522522        $this->assertEquals( array( $author_ids[0], $author_ids[1] ), $query->get_results() );
    523523    }
     524
     525    public function test_roles_and_caps_should_be_populated_for_default_value_of_blog_id() {
     526        $u = $this->factory->user->create( array( 'role' => 'author' ) );
     527
     528        $query = new WP_User_Query( array(
     529            'include' => $u,
     530        ) );
     531
     532        $found = $query->get_results();
     533
     534        $this->assertNotEmpty( $found );
     535        $user = reset( $found );
     536        $this->assertSame( array( 'author' ), $user->roles );
     537        $this->assertSame( array( 'author' => true ), $user->caps );
     538    }
     539
     540    public function test_roles_and_caps_should_be_populated_for_explicit_value_of_blog_id_on_nonms() {
     541        if ( is_multisite() ) {
     542            $this->markTestSkipped( __METHOD__ . ' is a non-multisite-only test.' );
     543        }
     544
     545        $u = $this->factory->user->create( array( 'role' => 'author' ) );
     546
     547        $query = new WP_User_Query( array(
     548            'include' => $u,
     549            'blog_id' => get_current_blog_id(),
     550        ) );
     551
     552        $found = $query->get_results();
     553
     554        $this->assertNotEmpty( $found );
     555        $user = reset( $found );
     556        $this->assertSame( array( 'author' ), $user->roles );
     557        $this->assertSame( array( 'author' => true ), $user->caps );
     558    }
     559
     560    public function test_roles_and_caps_should_be_populated_for_explicit_value_of_current_blog_id_on_ms() {
     561        if ( ! is_multisite() ) {
     562            $this->markTestSkipped( __METHOD__ . ' is a multisite-only test.' );
     563        }
     564
     565        $u = $this->factory->user->create( array( 'role' => 'author' ) );
     566
     567        $query = new WP_User_Query( array(
     568            'include' => $u,
     569            'blog_id' => get_current_blog_id(),
     570        ) );
     571
     572        $found = $query->get_results();
     573
     574        $this->assertNotEmpty( $found );
     575        $user = reset( $found );
     576        $this->assertSame( array( 'author' ), $user->roles );
     577        $this->assertSame( array( 'author' => true ), $user->caps );
     578    }
     579
     580    public function test_roles_and_caps_should_be_populated_for_explicit_value_of_different_blog_id_on_ms_when_fields_all_with_meta() {
     581        if ( ! is_multisite() ) {
     582            $this->markTestSkipped( __METHOD__ . ' is a multisite-only test.' );
     583        }
     584
     585        $b = $this->factory->blog->create();
     586        $u = $this->factory->user->create();
     587        add_user_to_blog( $b, $u, 'author' );
     588
     589        $query = new WP_User_Query( array(
     590            'include' => $u,
     591            'blog_id' => $b,
     592            'fields' => 'all_with_meta',
     593        ) );
     594
     595        $found = $query->get_results();
     596
     597        $this->assertNotEmpty( $found );
     598        $user = reset( $found );
     599        $this->assertSame( array( 'author' ), $user->roles );
     600        $this->assertSame( array( 'author' => true ), $user->caps );
     601    }
    524602}
Note: See TracChangeset for help on using the changeset viewer.