mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-06-28 22:30:04 +00:00
Move PHPUnit tests into a tests/phpunit directory.
wp-tests-config.php can/should reside in the root of a develop checkout. `phpunit` should be run from the root. see #25088. git-svn-id: https://develop.svn.wordpress.org/trunk@25165 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
79
tests/phpunit/tests/user/query.php
Normal file
79
tests/phpunit/tests/user/query.php
Normal file
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
/**
|
||||
* Test WP_User Query, in wp-includes/user.php
|
||||
*
|
||||
* @group user
|
||||
*/
|
||||
class Tests_User_Query extends WP_UnitTestCase {
|
||||
|
||||
protected $user_id;
|
||||
|
||||
function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->user_id = $this->factory->user->create( array(
|
||||
'role' => 'author'
|
||||
) );
|
||||
}
|
||||
|
||||
function test_get_and_set() {
|
||||
$users = new WP_User_Query();
|
||||
|
||||
$this->assertEquals( '', $users->get( 'fields' ) );
|
||||
$this->assertEquals( '', $users->query_vars['fields'] );
|
||||
|
||||
$users->set( 'fields', 'all' );
|
||||
|
||||
$this->assertEquals( 'all', $users->get( 'fields' ) );
|
||||
$this->assertEquals( 'all', $users->query_vars['fields'] );
|
||||
|
||||
$users->set( 'fields', '' );
|
||||
$this->assertEquals( '', $users->get( 'fields' ) );
|
||||
$this->assertEquals( '', $users->query_vars['fields'] );
|
||||
|
||||
$this->assertNull( $users->get( 'does-not-exist' ) );
|
||||
}
|
||||
|
||||
function test_include() {
|
||||
$users = new WP_User_Query();
|
||||
$users->set( 'fields', '' );
|
||||
$users->set( 'include', $this->user_id );
|
||||
$users->prepare_query();
|
||||
$users->query();
|
||||
|
||||
$ids = $users->get_results();
|
||||
$this->assertEquals( array( $this->user_id ), $ids );
|
||||
|
||||
}
|
||||
|
||||
function test_exclude() {
|
||||
$users = new WP_User_Query();
|
||||
$users->set( 'fields', '' );
|
||||
$users->set( 'exclude', $this->user_id );
|
||||
$users->prepare_query();
|
||||
$users->query();
|
||||
|
||||
$ids = $users->get_results();
|
||||
$this->assertNotContains( $this->user_id, $ids );
|
||||
}
|
||||
|
||||
function test_get_all() {
|
||||
$this->factory->user->create_many( 10, array(
|
||||
'role' => 'author'
|
||||
) );
|
||||
|
||||
$users = new WP_User_Query( array( 'blog_id' => get_current_blog_id() ) );
|
||||
$users = $users->get_results();
|
||||
$this->assertEquals( 12, count( $users ) );
|
||||
foreach ( $users as $user ) {
|
||||
$this->assertInstanceOf( 'WP_User', $user );
|
||||
}
|
||||
|
||||
$users = new WP_User_Query( array( 'blog_id' => get_current_blog_id(), 'fields' => 'all_with_meta' ) );
|
||||
$users = $users->get_results();
|
||||
$this->assertEquals( 12, count( $users ) );
|
||||
foreach ( $users as $user ) {
|
||||
$this->assertInstanceOf( 'WP_User', $user );
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user