Skip to content

Commit f57dee8

Browse files
committed
Tests: Cover REST authentication cookie status.
Verify `rest_cookie_collect_status()` records successful authentication and the failure status associated with cookie validation actions. Developed in: #15293 Props shailu25. See #65819. git-svn-id: https://develop.svn.wordpress.org/trunk@65143 602fd350-edb4-49c9-b593-d223f7449a82
1 parent d1a9996 commit f57dee8

1 file changed

Lines changed: 53 additions & 0 deletions

File tree

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
/**
4+
* Tests for rest_cookie_collect_status().
5+
*
6+
* @group restapi
7+
*
8+
* @covers ::rest_cookie_collect_status
9+
*/
10+
class Tests_REST_API_RestCookieCollectStatus extends WP_UnitTestCase {
11+
12+
public function tear_down() {
13+
unset( $GLOBALS['wp_rest_auth_cookie'] );
14+
parent::tear_down();
15+
}
16+
17+
/**
18+
* @ticket 65819
19+
*/
20+
public function test_sets_true_when_auth_cookie_valid() {
21+
do_action( 'auth_cookie_valid' );
22+
23+
$this->assertTrue( $GLOBALS['wp_rest_auth_cookie'] );
24+
}
25+
26+
/**
27+
* @ticket 65819
28+
*
29+
* @dataProvider data_auth_cookie_failure_actions
30+
*
31+
* @param string $action Auth cookie action name.
32+
* @param string $expected Stored failure status.
33+
*/
34+
public function test_stores_failure_status_from_action( $action, $expected ) {
35+
do_action( $action );
36+
37+
$this->assertSame( $expected, $GLOBALS['wp_rest_auth_cookie'] );
38+
}
39+
40+
/**
41+
* Data provider.
42+
*
43+
* @return array[]
44+
*/
45+
public static function data_auth_cookie_failure_actions() {
46+
return array(
47+
'malformed' => array( 'auth_cookie_malformed', 'malformed' ),
48+
'expired' => array( 'auth_cookie_expired', 'expired' ),
49+
'bad username' => array( 'auth_cookie_bad_username', 'bad_username' ),
50+
'bad hash' => array( 'auth_cookie_bad_hash', 'bad_hash' ),
51+
);
52+
}
53+
}

0 commit comments

Comments
 (0)