wiki.techinc.nl/tests/phpunit/includes/auth/TemporaryPasswordAuthenticationRequestTest.php
Aryeh Gregor 09eee138e1 Deprecate MediaWikiTestCase::stashMwGlobals
This method encourages directly editing configuration variables.  It's a
better idea to use setMwGlobals() (or other set wrappers) so that we can
be intelligent in the future, for instance resetting services after the
config change.  Plus, a lot of the callers come out cleaner this way
anyway.

Depends-On: I8a1e81acc5c42a8d7f30938a72cface0acea4a70
Depends-On: I4105dbcf9c5399fe7239478c460ec57c015a98d4
Depends-On: I1b220996acf2f66cf7b0f092b341584663df32f9
Depends-On: Ie2d1ea65c0cb334bbde1666d00781474b7ac4dab
Change-Id: I23d77398e401f4986b1d5bd1c9e11a8a40da16f8
2018-10-07 19:39:47 +03:00

81 lines
2.3 KiB
PHP

<?php
namespace MediaWiki\Auth;
/**
* @group AuthManager
* @covers MediaWiki\Auth\TemporaryPasswordAuthenticationRequest
*/
class TemporaryPasswordAuthenticationRequestTest extends AuthenticationRequestTestCase {
protected function getInstance( array $args = [] ) {
$ret = new TemporaryPasswordAuthenticationRequest;
$ret->action = $args[0];
return $ret;
}
public static function provideGetFieldInfo() {
return [
[ [ AuthManager::ACTION_CREATE ] ],
[ [ AuthManager::ACTION_CHANGE ] ],
[ [ AuthManager::ACTION_REMOVE ] ],
];
}
public function testNewRandom() {
global $wgPasswordPolicy;
$policy = $wgPasswordPolicy;
$policy['policies']['default'] += [
'MinimalPasswordLength' => 1,
'MinimalPasswordLengthToLogin' => 1,
];
$this->setMwGlobals( 'wgPasswordPolicy', $policy );
$ret1 = TemporaryPasswordAuthenticationRequest::newRandom();
$ret2 = TemporaryPasswordAuthenticationRequest::newRandom();
$this->assertNotSame( '', $ret1->password );
$this->assertNotSame( '', $ret2->password );
$this->assertNotSame( $ret1->password, $ret2->password );
}
public function testNewInvalid() {
$ret = TemporaryPasswordAuthenticationRequest::newInvalid();
$this->assertNull( $ret->password );
}
public function provideLoadFromSubmission() {
return [
'Empty request' => [
[ AuthManager::ACTION_REMOVE ],
[],
false,
],
'Create, empty request' => [
[ AuthManager::ACTION_CREATE ],
[],
false,
],
'Create, mailpassword set' => [
[ AuthManager::ACTION_CREATE ],
[ 'mailpassword' => 1 ],
[ 'mailpassword' => true, 'action' => AuthManager::ACTION_CREATE ],
],
];
}
public function testDescribeCredentials() {
$req = new TemporaryPasswordAuthenticationRequest;
$req->action = AuthManager::ACTION_LOGIN;
$req->username = 'UTSysop';
$ret = $req->describeCredentials();
$this->assertInternalType( 'array', $ret );
$this->assertArrayHasKey( 'provider', $ret );
$this->assertInstanceOf( \Message::class, $ret['provider'] );
$this->assertSame( 'authmanager-provider-temporarypassword', $ret['provider']->getKey() );
$this->assertArrayHasKey( 'account', $ret );
$this->assertInstanceOf( \Message::class, $ret['account'] );
$this->assertSame( [ 'UTSysop' ], $ret['account']->getParams() );
}
}