Merge "Add SPARQL client to core"
[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 $this->stashMwGlobals( 'wgPasswordPolicy' );
29 $wgPasswordPolicy['policies']['default'] += [
30 'MinimalPasswordLength' => 1,
31 'MinimalPasswordLengthToLogin' => 1,
32 ];
33
34 $ret1 = TemporaryPasswordAuthenticationRequest::newRandom();
35 $ret2 = TemporaryPasswordAuthenticationRequest::newRandom();
36 $this->assertNotSame( '', $ret1->password );
37 $this->assertNotSame( '', $ret2->password );
38 $this->assertNotSame( $ret1->password, $ret2->password );
39 }
40
41 public function testNewInvalid() {
42 $ret = TemporaryPasswordAuthenticationRequest::newInvalid();
43 $this->assertNull( $ret->password );
44 }
45
46 public function provideLoadFromSubmission() {
47 return [
48 'Empty request' => [
49 [ AuthManager::ACTION_REMOVE ],
50 [],
51 false,
52 ],
53 'Create, empty request' => [
54 [ AuthManager::ACTION_CREATE ],
55 [],
56 false,
57 ],
58 'Create, mailpassword set' => [
59 [ AuthManager::ACTION_CREATE ],
60 [ 'mailpassword' => 1 ],
61 [ 'mailpassword' => true, 'action' => AuthManager::ACTION_CREATE ],
62 ],
63 ];
64 }
65
66 public function testDescribeCredentials() {
67 $req = new TemporaryPasswordAuthenticationRequest;
68 $req->action = AuthManager::ACTION_LOGIN;
69 $req->username = 'UTSysop';
70 $ret = $req->describeCredentials();
71 $this->assertInternalType( 'array', $ret );
72 $this->assertArrayHasKey( 'provider', $ret );
73 $this->assertInstanceOf( \Message::class, $ret['provider'] );
74 $this->assertSame( 'authmanager-provider-temporarypassword', $ret['provider']->getKey() );
75 $this->assertArrayHasKey( 'account', $ret );
76 $this->assertInstanceOf( \Message::class, $ret['account'] );
77 $this->assertSame( [ 'UTSysop' ], $ret['account']->getParams() );
78 }
79 }