@@ -27,6 +27,8 @@ class Test_ClassTwoFactorCore extends WP_UnitTestCase {
27
27
*/
28
28
public static function wpSetUpBeforeClass () {
29
29
set_error_handler ( array ( 'Test_ClassTwoFactorCore ' , 'error_handler ' ) ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_set_error_handler
30
+ add_action ( 'set_auth_cookie ' , [ __CLASS__ , 'set_auth_cookie ' ] );
31
+ add_action ( 'set_logged_in_cookie ' , [ __CLASS__ , 'set_logged_in_cookie ' ] );
30
32
}
31
33
32
34
/**
@@ -36,6 +38,17 @@ public static function wpSetUpBeforeClass() {
36
38
*/
37
39
public static function wpTearDownAfterClass () {
38
40
restore_error_handler ();
41
+ remove_action ( 'set_auth_cookie ' , [ __CLASS__ , 'set_auth_cookie ' ] );
42
+ remove_action ( 'set_logged_in_cookie ' , [ __CLASS__ , 'set_logged_in_cookie ' ] );
43
+ }
44
+
45
+ /**
46
+ * Cleanup after each test.
47
+ */
48
+ public function tearDown (): void {
49
+ parent ::tearDown ();
50
+
51
+ unset( $ _COOKIE [ AUTH_COOKIE ], $ _COOKIE [ LOGGED_IN_COOKIE ] );
39
52
}
40
53
41
54
/**
@@ -56,6 +69,20 @@ public static function error_handler( $errno, $errstr ) {
56
69
return true ;
57
70
}
58
71
72
+ /**
73
+ * Simulate the auth cookie having being sent.
74
+ */
75
+ public static function set_auth_cookie ( $ auth_cookie ) {
76
+ $ _COOKIE [ AUTH_COOKIE ] = $ auth_cookie ;
77
+ }
78
+
79
+ /**
80
+ * Simulate the logged_in cookie having being sent.
81
+ */
82
+ public static function set_logged_in_cookie ( $ logged_in_cookie ) {
83
+ $ _COOKIE [ LOGGED_IN_COOKIE ] = $ logged_in_cookie ;
84
+ }
85
+
59
86
/**
60
87
* Get a dummy user object.
61
88
*
0 commit comments