3 namespace MediaWiki\Tests\Auth
;
5 use MediaWiki\Auth\RememberMeAuthenticationRequest
;
6 use Wikimedia\TestingAccessWrapper
;
10 * @covers \MediaWiki\Auth\RememberMeAuthenticationRequest
12 class RememberMeAuthenticationRequestTest
extends AuthenticationRequestTestCase
{
14 public static function provideGetFieldInfo() {
21 public function testGetFieldInfo_2() {
22 $req = new RememberMeAuthenticationRequest();
23 $reqWrapper = TestingAccessWrapper
::newFromObject( $req );
25 $reqWrapper->expiration
= 30 * 24 * 3600;
26 $this->assertNotEmpty( $req->getFieldInfo() );
28 $reqWrapper->expiration
= null;
29 $this->assertSame( [], $req->getFieldInfo() );
32 public function testNoChoice() {
33 $req = new RememberMeAuthenticationRequest(
34 RememberMeAuthenticationRequest
::ALWAYS_REMEMBER
36 $reqWrapper = TestingAccessWrapper
::newFromObject( $req );
37 $this->assertSame( [], $req->getFieldInfo() );
38 $this->assertNotNull( $reqWrapper->expiration
);
40 $req = new RememberMeAuthenticationRequest(
41 RememberMeAuthenticationRequest
::NEVER_REMEMBER
43 $reqWrapper = TestingAccessWrapper
::newFromObject( $req );
44 $this->assertSame( [], $req->getFieldInfo() );
45 $this->assertNull( $reqWrapper->expiration
);
48 public function testInvalid() {
49 $this->expectException( '\UnexpectedValueException' );
50 new RememberMeAuthenticationRequest( 'invalid value' );
53 protected function getInstance( array $args = [] ) {
54 if ( isset( $args[1] ) ) {
55 $req = new RememberMeAuthenticationRequest( $args[1] );
57 $req = new RememberMeAuthenticationRequest();
59 $reqWrapper = TestingAccessWrapper
::newFromObject( $req );
60 $reqWrapper->expiration
= $args[0];
64 public static function provideLoadFromSubmission() {
69 [ 'expiration' => 30 * 24 * 3600, 'rememberMe' => false ]
71 'RememberMe present' => [
73 [ 'rememberMe' => '' ],
74 [ 'expiration' => 30 * 24 * 3600, 'rememberMe' => true ]
76 'RememberMe present but session provider cannot remember' => [
78 [ 'rememberMe' => '' ],
81 'Empty request (CHOOSE_REMEMBER)' => [
82 [ 30 * 24 * 3600, RememberMeAuthenticationRequest
::CHOOSE_REMEMBER
],
84 [ 'expiration' => 30 * 24 * 3600, 'rememberMe' => false ]
86 'RememberMe present (CHOOSE_REMEMBER)' => [
87 [ 30 * 24 * 3600, RememberMeAuthenticationRequest
::CHOOSE_REMEMBER
],
88 [ 'rememberMe' => '' ],
89 [ 'expiration' => 30 * 24 * 3600, 'rememberMe' => true ]
91 'RememberMe present but session provider cannot remember (CHOOSE_REMEMBER)' => [
92 [ null, RememberMeAuthenticationRequest
::CHOOSE_REMEMBER
],
93 [ 'rememberMe' => '' ],
96 'Empty request (FORCE_CHOOSE_REMEMBER)' => [
97 [ 30 * 24 * 3600, RememberMeAuthenticationRequest
::FORCE_CHOOSE_REMEMBER
],
99 [ 'expiration' => 30 * 24 * 3600, 'rememberMe' => false, 'skippable' => false ]
101 'RememberMe present (FORCE_CHOOSE_REMEMBER)' => [
102 [ 30 * 24 * 3600, RememberMeAuthenticationRequest
::FORCE_CHOOSE_REMEMBER
],
103 [ 'rememberMe' => '' ],
104 [ 'expiration' => 30 * 24 * 3600, 'rememberMe' => true, 'skippable' => false ]
106 'RememberMe present but session provider cannot remember (FORCE_CHOOSE_REMEMBER)' => [
107 [ null, RememberMeAuthenticationRequest
::FORCE_CHOOSE_REMEMBER
],
108 [ 'rememberMe' => '', 'skippable' => false ],