mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2025-10-16 12:05:38 +00:00
Adds a `public` visibility to test fixtures, tests, data providers, and callbacks methods. Adds a `private` visibility to helper methods within test classes. Renames callbacks and helpers that previously started with a `_` prefix. Why? For consistency and to leverage using the method visibility. Further naming standardizations is beyond the scope of this commit. Props costdev, jrf, hellofromTonya. Fixes #54177. git-svn-id: https://develop.svn.wordpress.org/trunk@52010 602fd350-edb4-49c9-b593-d223f7449a82
53 lines
2.0 KiB
PHP
53 lines
2.0 KiB
PHP
<?php
|
|
/**
|
|
* Test WP_Session_Tokens and WP_User_Meta_Session_Tokens, in wp-includes/session.php
|
|
*
|
|
* @group user
|
|
* @group session
|
|
*/
|
|
class Tests_User_Session extends WP_UnitTestCase {
|
|
|
|
public function set_up() {
|
|
parent::set_up();
|
|
remove_all_filters( 'session_token_manager' );
|
|
$user_id = self::factory()->user->create();
|
|
$this->manager = WP_Session_Tokens::get_instance( $user_id );
|
|
$this->assertInstanceOf( 'WP_Session_Tokens', $this->manager );
|
|
$this->assertInstanceOf( 'WP_User_Meta_Session_Tokens', $this->manager );
|
|
}
|
|
|
|
public function test_verify_and_destroy_token() {
|
|
$expiration = time() + DAY_IN_SECONDS;
|
|
$token = $this->manager->create( $expiration );
|
|
$this->assertFalse( $this->manager->verify( 'foo' ) );
|
|
$this->assertTrue( $this->manager->verify( $token ) );
|
|
$this->manager->destroy( $token );
|
|
$this->assertFalse( $this->manager->verify( $token ) );
|
|
}
|
|
|
|
public function test_destroy_other_tokens() {
|
|
$expiration = time() + DAY_IN_SECONDS;
|
|
$token_1 = $this->manager->create( $expiration );
|
|
$token_2 = $this->manager->create( $expiration );
|
|
$token_3 = $this->manager->create( $expiration );
|
|
$this->assertTrue( $this->manager->verify( $token_1 ) );
|
|
$this->assertTrue( $this->manager->verify( $token_2 ) );
|
|
$this->assertTrue( $this->manager->verify( $token_3 ) );
|
|
$this->manager->destroy_others( $token_2 );
|
|
$this->assertFalse( $this->manager->verify( $token_1 ) );
|
|
$this->assertTrue( $this->manager->verify( $token_2 ) );
|
|
$this->assertFalse( $this->manager->verify( $token_3 ) );
|
|
}
|
|
|
|
public function test_destroy_all_tokens() {
|
|
$expiration = time() + DAY_IN_SECONDS;
|
|
$token_1 = $this->manager->create( $expiration );
|
|
$token_2 = $this->manager->create( $expiration );
|
|
$this->assertTrue( $this->manager->verify( $token_1 ) );
|
|
$this->assertTrue( $this->manager->verify( $token_2 ) );
|
|
$this->manager->destroy_all();
|
|
$this->assertFalse( $this->manager->verify( $token_1 ) );
|
|
$this->assertFalse( $this->manager->verify( $token_2 ) );
|
|
}
|
|
}
|