Merge "Update docs/hooks.txt for ShowSearchHitTitle"
[mediawiki.git] / tests / phpunit / includes / auth / TemporaryPasswordAuthenticationRequestTest.php
blob05c5165b441d850aab3e71e8d38b9eaa3b305450
1 <?php
3 namespace MediaWiki\Auth;
5 /**
6 * @group AuthManager
7 * @covers MediaWiki\Auth\TemporaryPasswordAuthenticationRequest
8 */
9 class TemporaryPasswordAuthenticationRequestTest extends AuthenticationRequestTestCase {
11 protected function getInstance( array $args = [] ) {
12 $ret = new TemporaryPasswordAuthenticationRequest;
13 $ret->action = $args[0];
14 return $ret;
17 public static function provideGetFieldInfo() {
18 return [
19 [ [ AuthManager::ACTION_CREATE ] ],
20 [ [ AuthManager::ACTION_CHANGE ] ],
21 [ [ AuthManager::ACTION_REMOVE ] ],
25 public function testNewRandom() {
26 global $wgPasswordPolicy;
28 $this->stashMwGlobals( 'wgPasswordPolicy' );
29 $wgPasswordPolicy['policies']['default'] += [
30 'MinimalPasswordLength' => 1,
31 'MinimalPasswordLengthToLogin' => 1,
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 );
41 public function testNewInvalid() {
42 $ret = TemporaryPasswordAuthenticationRequest::newInvalid();
43 $this->assertNull( $ret->password );
46 public function provideLoadFromSubmission() {
47 return [
48 'Empty request' => [
49 [ AuthManager::ACTION_REMOVE ],
50 [],
51 false,
53 'Create, empty request' => [
54 [ AuthManager::ACTION_CREATE ],
55 [],
56 false,
58 'Create, mailpassword set' => [
59 [ AuthManager::ACTION_CREATE ],
60 [ 'mailpassword' => 1 ],
61 [ 'mailpassword' => true, 'action' => AuthManager::ACTION_CREATE ],
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', $ret['provider'] );
74 $this->assertSame( 'authmanager-provider-temporarypassword', $ret['provider']->getKey() );
75 $this->assertArrayHasKey( 'account', $ret );
76 $this->assertInstanceOf( 'Message', $ret['account'] );
77 $this->assertSame( [ 'UTSysop' ], $ret['account']->getParams() );