Merge "Update docs/hooks.txt for ShowSearchHitTitle"
[mediawiki.git] / tests / phpunit / includes / auth / PasswordDomainAuthenticationRequestTest.php
blobf746515b093f46e279782d4ba66863a01bfd00a3
1 <?php
3 namespace MediaWiki\Auth;
5 /**
6 * @group AuthManager
7 * @covers MediaWiki\Auth\PasswordDomainAuthenticationRequest
8 */
9 class PasswordDomainAuthenticationRequestTest extends AuthenticationRequestTestCase {
11 protected function getInstance( array $args = [] ) {
12 $ret = new PasswordDomainAuthenticationRequest( [ 'd1', 'd2' ] );
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 PasswordDomainAuthenticationRequest( [ 'd1', 'd2' ] );
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( 'domain', $info[AuthManager::ACTION_LOGIN],
44 'Domain needed on login' );
45 $this->assertArrayHasKey( 'retype', $info[AuthManager::ACTION_CREATE],
46 'Need to retype when creating new password' );
47 $this->assertArrayHasKey( 'domain', $info[AuthManager::ACTION_CREATE],
48 'Domain needed on account creation' );
49 $this->assertArrayHasKey( 'retype', $info[AuthManager::ACTION_CHANGE],
50 'Need to retype when changing password' );
51 $this->assertArrayNotHasKey( 'domain', $info[AuthManager::ACTION_CHANGE],
52 'Domain not needed on account creation' );
54 $this->assertNotEquals(
55 $info[AuthManager::ACTION_LOGIN]['password']['label'],
56 $info[AuthManager::ACTION_CHANGE]['password']['label'],
57 'Password field for change is differentiated from login'
59 $this->assertNotEquals(
60 $info[AuthManager::ACTION_CREATE]['password']['label'],
61 $info[AuthManager::ACTION_CHANGE]['password']['label'],
62 'Password field for change is differentiated from create'
64 $this->assertNotEquals(
65 $info[AuthManager::ACTION_CREATE]['retype']['label'],
66 $info[AuthManager::ACTION_CHANGE]['retype']['label'],
67 'Retype field for change is differentiated from create'
71 public function provideLoadFromSubmission() {
72 $domainList = [ 'domainList' => [ 'd1', 'd2' ] ];
73 return [
74 'Empty request, login' => [
75 [ AuthManager::ACTION_LOGIN ],
76 [],
77 false,
79 'Empty request, change' => [
80 [ AuthManager::ACTION_CHANGE ],
81 [],
82 false,
84 'Empty request, remove' => [
85 [ AuthManager::ACTION_REMOVE ],
86 [],
87 false,
89 'Username + password, login' => [
90 [ AuthManager::ACTION_LOGIN ],
91 $data = [ 'username' => 'User', 'password' => 'Bar' ],
92 false,
94 'Username + password + domain, login' => [
95 [ AuthManager::ACTION_LOGIN ],
96 $data = [ 'username' => 'User', 'password' => 'Bar', 'domain' => 'd1' ],
97 $data + [ 'action' => AuthManager::ACTION_LOGIN ] + $domainList,
99 'Username + password + bad domain, login' => [
100 [ AuthManager::ACTION_LOGIN ],
101 $data = [ 'username' => 'User', 'password' => 'Bar', 'domain' => 'd5' ],
102 false,
104 'Username + password + domain, change' => [
105 [ AuthManager::ACTION_CHANGE ],
106 [ 'username' => 'User', 'password' => 'Bar', 'domain' => 'd1' ],
107 false,
109 'Username + password + domain + retype' => [
110 [ AuthManager::ACTION_CHANGE ],
111 [ 'username' => 'User', 'password' => 'Bar', 'retype' => 'baz', 'domain' => 'd1' ],
112 [ 'password' => 'Bar', 'retype' => 'baz', 'action' => AuthManager::ACTION_CHANGE ] +
113 $domainList,
115 'Username empty, login' => [
116 [ AuthManager::ACTION_LOGIN ],
117 [ 'username' => '', 'password' => 'Bar', 'domain' => 'd1' ],
118 false,
120 'Username empty, change' => [
121 [ AuthManager::ACTION_CHANGE ],
122 [ 'username' => '', 'password' => 'Bar', 'retype' => 'baz', 'domain' => 'd1' ],
123 [ 'password' => 'Bar', 'retype' => 'baz', 'action' => AuthManager::ACTION_CHANGE ] +
124 $domainList,
126 'Password empty, login' => [
127 [ AuthManager::ACTION_LOGIN ],
128 [ 'username' => 'User', 'password' => '', 'domain' => 'd1' ],
129 false,
131 'Password empty, login, with retype' => [
132 [ AuthManager::ACTION_LOGIN ],
133 [ 'username' => 'User', 'password' => '', 'retype' => 'baz', 'domain' => 'd1' ],
134 false,
136 'Retype empty' => [
137 [ AuthManager::ACTION_CHANGE ],
138 [ 'username' => 'User', 'password' => 'Bar', 'retype' => '', 'domain' => 'd1' ],
139 false,
144 public function testDescribeCredentials() {
145 $req = new PasswordDomainAuthenticationRequest( [ 'd1', 'd2' ] );
146 $req->action = AuthManager::ACTION_LOGIN;
147 $req->username = 'UTSysop';
148 $req->domain = 'd2';
149 $ret = $req->describeCredentials();
150 $this->assertInternalType( 'array', $ret );
151 $this->assertArrayHasKey( 'provider', $ret );
152 $this->assertInstanceOf( 'Message', $ret['provider'] );
153 $this->assertSame( 'authmanager-provider-password-domain', $ret['provider']->getKey() );
154 $this->assertArrayHasKey( 'account', $ret );
155 $this->assertInstanceOf( 'Message', $ret['account'] );
156 $this->assertSame( 'authmanager-account-password-domain', $ret['account']->getKey() );
157 $this->assertSame( [ 'UTSysop', 'd2' ], $ret['account']->getParams() );