Localisation updates from https://translatewiki.net.
[mediawiki.git] / tests / phpunit / includes / auth / RememberMeAuthenticationRequestTest.php
blob99a6537152939917e7f601973c83557eca70e777
1 <?php
3 namespace MediaWiki\Tests\Auth;
5 use MediaWiki\Auth\RememberMeAuthenticationRequest;
6 use Wikimedia\TestingAccessWrapper;
8 /**
9 * @group AuthManager
10 * @covers \MediaWiki\Auth\RememberMeAuthenticationRequest
12 class RememberMeAuthenticationRequestTest extends AuthenticationRequestTestCase {
14 public static function provideGetFieldInfo() {
15 return [
16 [ [ 1 ] ],
17 [ [ null ] ],
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] );
56 } else {
57 $req = new RememberMeAuthenticationRequest();
59 $reqWrapper = TestingAccessWrapper::newFromObject( $req );
60 $reqWrapper->expiration = $args[0];
61 return $req;
64 public static function provideLoadFromSubmission() {
65 return [
66 'Empty request' => [
67 [ 30 * 24 * 3600 ],
68 [],
69 [ 'expiration' => 30 * 24 * 3600, 'rememberMe' => false ]
71 'RememberMe present' => [
72 [ 30 * 24 * 3600 ],
73 [ 'rememberMe' => '' ],
74 [ 'expiration' => 30 * 24 * 3600, 'rememberMe' => true ]
76 'RememberMe present but session provider cannot remember' => [
77 [ null ],
78 [ 'rememberMe' => '' ],
79 false
81 'Empty request (CHOOSE_REMEMBER)' => [
82 [ 30 * 24 * 3600, RememberMeAuthenticationRequest::CHOOSE_REMEMBER ],
83 [],
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' => '' ],
94 false
96 'Empty request (FORCE_CHOOSE_REMEMBER)' => [
97 [ 30 * 24 * 3600, RememberMeAuthenticationRequest::FORCE_CHOOSE_REMEMBER ],
98 [],
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 ],
109 false