Deprecate MediaWikiTestCase::stashMwGlobals
[lhc/web/wiklou.git] / tests / phpunit / includes / auth / TemporaryPasswordAuthenticationRequestTest.php
1 <?php
2
3 namespace MediaWiki\Auth;
4
5 /**
6 * @group AuthManager
7 * @covers MediaWiki\Auth\TemporaryPasswordAuthenticationRequest
8 */
9 class TemporaryPasswordAuthenticationRequestTest extends AuthenticationRequestTestCase {
10
11 protected function getInstance( array $args = [] ) {
12 $ret = new TemporaryPasswordAuthenticationRequest;
13 $ret->action = $args[0];
14 return $ret;
15 }
16
17 public static function provideGetFieldInfo() {
18 return [
19 [ [ AuthManager::ACTION_CREATE ] ],
20 [ [ AuthManager::ACTION_CHANGE ] ],
21 [ [ AuthManager::ACTION_REMOVE ] ],
22 ];
23 }
24
25 public function testNewRandom() {
26 global $wgPasswordPolicy;
27
28 $policy = $wgPasswordPolicy;
29 $policy['policies']['default'] += [
30 'MinimalPasswordLength' => 1,
31 'MinimalPasswordLengthToLogin' => 1,
32 ];
33
34 $this->setMwGlobals( 'wgPasswordPolicy', $policy );
35
36 $ret1 = TemporaryPasswordAuthenticationRequest::newRandom();
37 $ret2 = TemporaryPasswordAuthenticationRequest::newRandom();
38 $this->assertNotSame( '', $ret1->password );
39 $this->assertNotSame( '', $ret2->password );
40 $this->assertNotSame( $ret1->password, $ret2->password );
41 }
42
43 public function testNewInvalid() {
44 $ret = TemporaryPasswordAuthenticationRequest::newInvalid();
45 $this->assertNull( $ret->password );
46 }
47
48 public function provideLoadFromSubmission() {
49 return [
50 'Empty request' => [
51 [ AuthManager::ACTION_REMOVE ],
52 [],
53 false,
54 ],
55 'Create, empty request' => [
56 [ AuthManager::ACTION_CREATE ],
57 [],
58 false,
59 ],
60 'Create, mailpassword set' => [
61 [ AuthManager::ACTION_CREATE ],
62 [ 'mailpassword' => 1 ],
63 [ 'mailpassword' => true, 'action' => AuthManager::ACTION_CREATE ],
64 ],
65 ];
66 }
67
68 public function testDescribeCredentials() {
69 $req = new TemporaryPasswordAuthenticationRequest;
70 $req->action = AuthManager::ACTION_LOGIN;
71 $req->username = 'UTSysop';
72 $ret = $req->describeCredentials();
73 $this->assertInternalType( 'array', $ret );
74 $this->assertArrayHasKey( 'provider', $ret );
75 $this->assertInstanceOf( \Message::class, $ret['provider'] );
76 $this->assertSame( 'authmanager-provider-temporarypassword', $ret['provider']->getKey() );
77 $this->assertArrayHasKey( 'account', $ret );
78 $this->assertInstanceOf( \Message::class, $ret['account'] );
79 $this->assertSame( [ 'UTSysop' ], $ret['account']->getParams() );
80 }
81 }