forked from WordPress/wordpress-develop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsession.php
More file actions
52 lines (48 loc) · 1.96 KB
/
session.php
File metadata and controls
52 lines (48 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?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 {
function setUp() {
parent::setUp();
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 );
}
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 ) );
}
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 ) );
}
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 ) );
}
}