Unit Tests: better fixtures for Tests_User_WpSetCurrentUser
.
See #30017, #33968. git-svn-id: https://develop.svn.wordpress.org/trunk@35248 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
721d4c5a77
commit
80b732819b
@ -4,40 +4,46 @@
|
|||||||
* @group user
|
* @group user
|
||||||
*/
|
*/
|
||||||
class Tests_User_WpSetCurrentUser extends WP_UnitTestCase {
|
class Tests_User_WpSetCurrentUser extends WP_UnitTestCase {
|
||||||
|
protected static $user_id;
|
||||||
|
protected static $user_id2;
|
||||||
|
protected static $user_ids = array();
|
||||||
|
|
||||||
|
public static function wpSetUpBeforeClass( $factory ) {
|
||||||
|
self::$user_ids[] = self::$user_id = $factory->user->create();
|
||||||
|
self::$user_ids[] = self::$user_id2 = $factory->user->create( array( 'user_login' => 'foo', ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function wpTearDownAfterClass() {
|
||||||
|
foreach ( self::$user_ids as $id ) {
|
||||||
|
self::delete_user( $id );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function test_set_by_id() {
|
public function test_set_by_id() {
|
||||||
$u = self::factory()->user->create();
|
$user = wp_set_current_user( self::$user_id );
|
||||||
|
|
||||||
$user = wp_set_current_user( $u );
|
$this->assertSame( self::$user_id, $user->ID );
|
||||||
|
|
||||||
$this->assertSame( $u, $user->ID );
|
|
||||||
$this->assertEquals( $user, wp_get_current_user() );
|
$this->assertEquals( $user, wp_get_current_user() );
|
||||||
$this->assertSame( $u, get_current_user_id() );
|
$this->assertSame( self::$user_id, get_current_user_id() );
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_name_should_be_ignored_if_id_is_not_null() {
|
public function test_name_should_be_ignored_if_id_is_not_null() {
|
||||||
$u = self::factory()->user->create();
|
$user = wp_set_current_user( self::$user_id, 'foo' );
|
||||||
|
|
||||||
$user = wp_set_current_user( $u, 'foo' );
|
$this->assertSame( self::$user_id, $user->ID );
|
||||||
|
|
||||||
$this->assertSame( $u, $user->ID );
|
|
||||||
$this->assertEquals( $user, wp_get_current_user() );
|
$this->assertEquals( $user, wp_get_current_user() );
|
||||||
$this->assertSame( $u, get_current_user_id() );
|
$this->assertSame( self::$user_id, get_current_user_id() );
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_should_set_by_name_if_id_is_null_and_current_user_is_nonempty() {
|
public function test_should_set_by_name_if_id_is_null_and_current_user_is_nonempty() {
|
||||||
$u1 = self::factory()->user->create();
|
wp_set_current_user( self::$user_id );
|
||||||
wp_set_current_user( $u1 );
|
$this->assertSame( self::$user_id, get_current_user_id() );
|
||||||
$this->assertSame( $u1, get_current_user_id() );
|
|
||||||
|
|
||||||
$u2 = self::factory()->user->create( array(
|
|
||||||
'user_login' => 'foo',
|
|
||||||
) );
|
|
||||||
|
|
||||||
$user = wp_set_current_user( null, 'foo' );
|
$user = wp_set_current_user( null, 'foo' );
|
||||||
|
|
||||||
$this->assertSame( $u2, $user->ID );
|
$this->assertSame( self::$user_id2, $user->ID );
|
||||||
$this->assertEquals( $user, wp_get_current_user() );
|
$this->assertEquals( $user, wp_get_current_user() );
|
||||||
$this->assertSame( $u2, get_current_user_id() );
|
$this->assertSame( self::$user_id2, get_current_user_id() );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -49,15 +55,11 @@ class Tests_User_WpSetCurrentUser extends WP_UnitTestCase {
|
|||||||
wp_set_current_user( 0 );
|
wp_set_current_user( 0 );
|
||||||
$this->assertSame( 0, get_current_user_id() );
|
$this->assertSame( 0, get_current_user_id() );
|
||||||
|
|
||||||
$u = self::factory()->user->create( array(
|
|
||||||
'user_login' => 'foo',
|
|
||||||
) );
|
|
||||||
|
|
||||||
$user = wp_set_current_user( null, 'foo' );
|
$user = wp_set_current_user( null, 'foo' );
|
||||||
|
|
||||||
$this->assertSame( $u, $user->ID );
|
$this->assertSame( self::$user_id2, $user->ID );
|
||||||
$this->assertEquals( $user, wp_get_current_user() );
|
$this->assertEquals( $user, wp_get_current_user() );
|
||||||
$this->assertSame( $u, get_current_user_id() );
|
$this->assertSame( self::$user_id2, get_current_user_id() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user