Unit tests verifying the filling of the 'roles' and 'caps' user properties during WP_User_Query
.
See #31878. git-svn-id: https://develop.svn.wordpress.org/trunk@32000 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
667899569f
commit
86f074ffde
@ -521,4 +521,82 @@ class Tests_User_Query extends WP_UnitTestCase {
|
||||
|
||||
$this->assertEquals( array( $author_ids[0], $author_ids[1] ), $query->get_results() );
|
||||
}
|
||||
|
||||
public function test_roles_and_caps_should_be_populated_for_default_value_of_blog_id() {
|
||||
$u = $this->factory->user->create( array( 'role' => 'author' ) );
|
||||
|
||||
$query = new WP_User_Query( array(
|
||||
'include' => $u,
|
||||
) );
|
||||
|
||||
$found = $query->get_results();
|
||||
|
||||
$this->assertNotEmpty( $found );
|
||||
$user = reset( $found );
|
||||
$this->assertSame( array( 'author' ), $user->roles );
|
||||
$this->assertSame( array( 'author' => true ), $user->caps );
|
||||
}
|
||||
|
||||
public function test_roles_and_caps_should_be_populated_for_explicit_value_of_blog_id_on_nonms() {
|
||||
if ( is_multisite() ) {
|
||||
$this->markTestSkipped( __METHOD__ . ' is a non-multisite-only test.' );
|
||||
}
|
||||
|
||||
$u = $this->factory->user->create( array( 'role' => 'author' ) );
|
||||
|
||||
$query = new WP_User_Query( array(
|
||||
'include' => $u,
|
||||
'blog_id' => get_current_blog_id(),
|
||||
) );
|
||||
|
||||
$found = $query->get_results();
|
||||
|
||||
$this->assertNotEmpty( $found );
|
||||
$user = reset( $found );
|
||||
$this->assertSame( array( 'author' ), $user->roles );
|
||||
$this->assertSame( array( 'author' => true ), $user->caps );
|
||||
}
|
||||
|
||||
public function test_roles_and_caps_should_be_populated_for_explicit_value_of_current_blog_id_on_ms() {
|
||||
if ( ! is_multisite() ) {
|
||||
$this->markTestSkipped( __METHOD__ . ' is a multisite-only test.' );
|
||||
}
|
||||
|
||||
$u = $this->factory->user->create( array( 'role' => 'author' ) );
|
||||
|
||||
$query = new WP_User_Query( array(
|
||||
'include' => $u,
|
||||
'blog_id' => get_current_blog_id(),
|
||||
) );
|
||||
|
||||
$found = $query->get_results();
|
||||
|
||||
$this->assertNotEmpty( $found );
|
||||
$user = reset( $found );
|
||||
$this->assertSame( array( 'author' ), $user->roles );
|
||||
$this->assertSame( array( 'author' => true ), $user->caps );
|
||||
}
|
||||
|
||||
public function test_roles_and_caps_should_be_populated_for_explicit_value_of_different_blog_id_on_ms_when_fields_all_with_meta() {
|
||||
if ( ! is_multisite() ) {
|
||||
$this->markTestSkipped( __METHOD__ . ' is a multisite-only test.' );
|
||||
}
|
||||
|
||||
$b = $this->factory->blog->create();
|
||||
$u = $this->factory->user->create();
|
||||
add_user_to_blog( $b, $u, 'author' );
|
||||
|
||||
$query = new WP_User_Query( array(
|
||||
'include' => $u,
|
||||
'blog_id' => $b,
|
||||
'fields' => 'all_with_meta',
|
||||
) );
|
||||
|
||||
$found = $query->get_results();
|
||||
|
||||
$this->assertNotEmpty( $found );
|
||||
$user = reset( $found );
|
||||
$this->assertSame( array( 'author' ), $user->roles );
|
||||
$this->assertSame( array( 'author' => true ), $user->caps );
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user