From 23b1296432c78669640024ba66137834d75a92f9 Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Tue, 3 Oct 2017 16:01:16 +0000 Subject: [PATCH] Login and Registration: Add unit tests for `wp_auth_check()`. Props pbearne, birgire Fixes #41860 git-svn-id: https://develop.svn.wordpress.org/trunk@41710 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/tests/functions/wpAuthCheck.php | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 tests/phpunit/tests/functions/wpAuthCheck.php diff --git a/tests/phpunit/tests/functions/wpAuthCheck.php b/tests/phpunit/tests/functions/wpAuthCheck.php new file mode 100644 index 0000000000..85e26fb867 --- /dev/null +++ b/tests/phpunit/tests/functions/wpAuthCheck.php @@ -0,0 +1,64 @@ + false, + ); + + $this->assertFalse( is_user_logged_in() ); + $this->assertSame( $expected, wp_auth_check( array() ) ); + } + + /** + * Run with user logged in. + * + * @ticket 41860 + */ + function test_wp_auth_check_user_logged_in() { + // log user in + wp_set_current_user( 1 ); + + $expected = array( + 'wp-auth-check' => true, + ); + + $this->assertTrue( is_user_logged_in() ); + $this->assertSame( $expected, wp_auth_check( array() ) ); + } + + /** + * Run with user logged in but with expired state. + * + * @ticket 41860 + */ + function test_wp_auth_check_user_logged_in_login_grace_period_set() { + // log user in + wp_set_current_user( 1 ); + + $GLOBALS['login_grace_period'] = 1; + + $expected = array( + 'wp-auth-check' => false, + ); + $actual = wp_auth_check( array() ); + $logged_in = is_user_logged_in(); + + // Leave the global state unchanged + unset( $GLOBALS['login_grace_period'] ); + + $this->assertTrue( $logged_in ); + $this->assertSame( $expected, $actual ); + } +}