[ Index ] |
PHP Cross Reference of YOURLS |
[Summary view] [Print] [Text view]
1 <?php declare(strict_types=1); 2 3 trait LoginAssertionTrait 4 { 5 /** 6 * Check that user, as submitted by REQUEST (see phpunit XML config file), is valid 7 * 8 * @since 0.1 9 */ 10 public function test_login() { 11 $pre_login = yourls_did_action( 'pre_login' ); 12 $login = yourls_did_action( 'login' ); 13 $login_failed = yourls_did_action( 'login_failed' ); 14 15 $this->assertTrue( yourls_is_valid_user() ); 16 17 $this->assertEquals( $pre_login + 1, yourls_did_action( 'pre_login' ) ); 18 $this->assertEquals( $login + 1, yourls_did_action( 'login' ) ); 19 $this->assertEquals( $login_failed, yourls_did_action( 'login_failed' ) ); 20 } 21 22 /** 23 * Check that auth is shuntable 24 * 25 * @since 0.1 26 */ 27 public function test_login_shunt() { 28 yourls_add_filter( 'shunt_is_valid_user', 'yourls_return_empty_array' ); 29 $this->assertSame( array(), yourls_is_valid_user() ); 30 yourls_remove_filter( 'shunt_is_valid_user', 'yourls_return_empty_array' ); 31 } 32 33 /** 34 * Check that auth returns false with no credential 35 * 36 * @since 0.1 37 */ 38 public function test_login_with_no_credential() { 39 $_REQUEST = array(); 40 $login = yourls_did_action( 'login' ); 41 $login_failed = yourls_did_action( 'login_failed' ); 42 43 $this->assertNotTrue( yourls_is_valid_user() ); 44 45 $this->assertEquals( $login, yourls_did_action( 'login' ) ); 46 $this->assertEquals( $login_failed + 1, yourls_did_action( 'login_failed' ) ); 47 } 48 49 /** 50 * Check that auth returns false with empty credential 51 * 52 * @since 0.1 53 */ 54 public function test_login_with_empty_credential() { 55 $_REQUEST = array( 'username' => '', 'password' => '' ); 56 $login = yourls_did_action( 'login' ); 57 $login_failed = yourls_did_action( 'login_failed' ); 58 59 $this->assertNotTrue( yourls_is_valid_user() ); 60 61 $this->assertEquals( $login, yourls_did_action( 'login' ) ); 62 $this->assertEquals( $login_failed + 1, yourls_did_action( 'login_failed' ) ); 63 } 64 65 /** 66 * Check that auth returns false with incorrect credentials 67 * 68 * @since 0.1 69 */ 70 public function test_login_with_random_credentials() { 71 $_REQUEST = array( 'username' => rand_str(), 'password' => rand_str() ); 72 $login = yourls_did_action( 'login' ); 73 $login_failed = yourls_did_action( 'login_failed' ); 74 75 // with "normal" logins, we simulate the login forms and the presence of a nonce 76 if (get_class($this) == 'LoginNormalTest') { 77 $this->expectException(Exception::class); 78 $this->expectExceptionMessage('I have died'); 79 // intercept yourls_die() before it actually dies 80 yourls_add_action( 'pre_yourls_die', function() { throw new Exception( 'I have died' ); } ); 81 } 82 83 $this->assertNotTrue( yourls_is_valid_user() ); 84 } 85 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Mon Mar 31 05:10:02 2025 | Cross-referenced by PHPXref 0.7.1 |