Move ResultWrapper subclasses to Rdbms
[mediawiki.git] / tests / phpunit / includes / auth / PasswordAuthenticationRequestTest.php
blob3387e7c9acfa00d8dce4607f56b232f9eef7343f
1 <?php
3 namespace MediaWiki\Auth;
5 /**
6 * @group AuthManager
7 * @covers MediaWiki\Auth\PasswordAuthenticationRequest
8 */
9 class PasswordAuthenticationRequestTest extends AuthenticationRequestTestCase {
11 protected function getInstance( array $args = [] ) {
12 $ret = new PasswordAuthenticationRequest();
13 $ret->action = $args[0];
14 return $ret;
17 public static function provideGetFieldInfo() {
18 return [
19 [ [ AuthManager::ACTION_LOGIN ] ],
20 [ [ AuthManager::ACTION_CREATE ] ],
21 [ [ AuthManager::ACTION_CHANGE ] ],
22 [ [ AuthManager::ACTION_REMOVE ] ],
26 public function testGetFieldInfo2() {
27 $info = [];
28 foreach ( [
29 AuthManager::ACTION_LOGIN,
30 AuthManager::ACTION_CREATE,
31 AuthManager::ACTION_CHANGE,
32 AuthManager::ACTION_REMOVE,
33 ] as $action ) {
34 $req = new PasswordAuthenticationRequest();
35 $req->action = $action;
36 $info[$action] = $req->getFieldInfo();
39 $this->assertSame( [], $info[AuthManager::ACTION_REMOVE], 'No data needed to remove' );
41 $this->assertArrayNotHasKey( 'retype', $info[AuthManager::ACTION_LOGIN],
42 'No need to retype password on login' );
43 $this->assertArrayHasKey( 'retype', $info[AuthManager::ACTION_CREATE],
44 'Need to retype when creating new password' );
45 $this->assertArrayHasKey( 'retype', $info[AuthManager::ACTION_CHANGE],
46 'Need to retype when changing password' );
48 $this->assertNotEquals(
49 $info[AuthManager::ACTION_LOGIN]['password']['label'],
50 $info[AuthManager::ACTION_CHANGE]['password']['label'],
51 'Password field for change is differentiated from login'
53 $this->assertNotEquals(
54 $info[AuthManager::ACTION_CREATE]['password']['label'],
55 $info[AuthManager::ACTION_CHANGE]['password']['label'],
56 'Password field for change is differentiated from create'
58 $this->assertNotEquals(
59 $info[AuthManager::ACTION_CREATE]['retype']['label'],
60 $info[AuthManager::ACTION_CHANGE]['retype']['label'],
61 'Retype field for change is differentiated from create'
65 public function provideLoadFromSubmission() {
66 return [
67 'Empty request, login' => [
68 [ AuthManager::ACTION_LOGIN ],
69 [],
70 false,
72 'Empty request, change' => [
73 [ AuthManager::ACTION_CHANGE ],
74 [],
75 false,
77 'Empty request, remove' => [
78 [ AuthManager::ACTION_REMOVE ],
79 [],
80 false,
82 'Username + password, login' => [
83 [ AuthManager::ACTION_LOGIN ],
84 $data = [ 'username' => 'User', 'password' => 'Bar' ],
85 $data + [ 'action' => AuthManager::ACTION_LOGIN ],
87 'Username + password, change' => [
88 [ AuthManager::ACTION_CHANGE ],
89 [ 'username' => 'User', 'password' => 'Bar' ],
90 false,
92 'Username + password + retype' => [
93 [ AuthManager::ACTION_CHANGE ],
94 [ 'username' => 'User', 'password' => 'Bar', 'retype' => 'baz' ],
95 [ 'password' => 'Bar', 'retype' => 'baz', 'action' => AuthManager::ACTION_CHANGE ],
97 'Username empty, login' => [
98 [ AuthManager::ACTION_LOGIN ],
99 [ 'username' => '', 'password' => 'Bar' ],
100 false,
102 'Username empty, change' => [
103 [ AuthManager::ACTION_CHANGE ],
104 [ 'username' => '', 'password' => 'Bar', 'retype' => 'baz' ],
105 [ 'password' => 'Bar', 'retype' => 'baz', 'action' => AuthManager::ACTION_CHANGE ],
107 'Password empty, login' => [
108 [ AuthManager::ACTION_LOGIN ],
109 [ 'username' => 'User', 'password' => '' ],
110 false,
112 'Password empty, login, with retype' => [
113 [ AuthManager::ACTION_LOGIN ],
114 [ 'username' => 'User', 'password' => '', 'retype' => 'baz' ],
115 false,
117 'Retype empty' => [
118 [ AuthManager::ACTION_CHANGE ],
119 [ 'username' => 'User', 'password' => 'Bar', 'retype' => '' ],
120 false,
125 public function testDescribeCredentials() {
126 $req = new PasswordAuthenticationRequest;
127 $req->action = AuthManager::ACTION_LOGIN;
128 $req->username = 'UTSysop';
129 $ret = $req->describeCredentials();
130 $this->assertInternalType( 'array', $ret );
131 $this->assertArrayHasKey( 'provider', $ret );
132 $this->assertInstanceOf( 'Message', $ret['provider'] );
133 $this->assertSame( 'authmanager-provider-password', $ret['provider']->getKey() );
134 $this->assertArrayHasKey( 'account', $ret );
135 $this->assertInstanceOf( 'Message', $ret['account'] );
136 $this->assertSame( [ 'UTSysop' ], $ret['account']->getParams() );