Localisation updates from https://translatewiki.net.
[mediawiki.git] / tests / phpunit / includes / auth / UserDataAuthenticationRequestTest.php
blob0cb03ff3e8eed335e217942b60189dbdd1184d55
1 <?php
3 namespace MediaWiki\Tests\Auth;
5 use MediaWiki\Auth\UserDataAuthenticationRequest;
6 use MediaWiki\MainConfigNames;
7 use MediaWiki\User\User;
8 use StatusValue;
10 /**
11 * @group AuthManager
12 * @covers \MediaWiki\Auth\UserDataAuthenticationRequest
14 class UserDataAuthenticationRequestTest extends AuthenticationRequestTestCase {
16 protected function getInstance( array $args = [] ) {
17 return new UserDataAuthenticationRequest;
20 protected function setUp(): void {
21 parent::setUp();
22 $this->overrideConfigValue( MainConfigNames::HiddenPrefs, [] );
25 /**
26 * @dataProvider providePopulateUser
27 * @param string $email Email to set
28 * @param string $realname Realname to set
29 * @param StatusValue $expect Expected return
31 public function testPopulateUser( $email, $realname, $expect ) {
32 $this->clearHooks( [
33 'UserGetEmail',
34 'UserSetEmailAuthenticationTimestamp',
35 'InvalidateEmailComplete',
36 'UserSetEmail',
37 ] );
39 $user = new User();
40 $user->setEmail( 'default@example.com' );
41 $user->setRealName( 'Fake Name' );
43 $req = new UserDataAuthenticationRequest;
44 $req->email = $email;
45 $req->realname = $realname;
46 $this->assertEquals( $expect, $req->populateUser( $user ) );
47 if ( $expect->isOK() ) {
48 $this->assertSame( $email ?: 'default@example.com', $user->getEmail() );
49 $this->assertSame( $realname ?: 'Fake Name', $user->getRealName() );
53 public static function providePopulateUser() {
54 $good = StatusValue::newGood();
55 return [
56 [ 'email@example.com', 'Real Name', $good ],
57 [ 'email@example.com', '', $good ],
58 [ '', 'Real Name', $good ],
59 [ '', '', $good ],
60 [ 'invalid-email', 'Real Name', StatusValue::newFatal( 'invalidemailaddress' ) ],
64 /**
65 * @dataProvider provideLoadFromSubmission
67 public function testLoadFromSubmission(
68 array $args, array $data, $expectState, $hiddenPref = null, $enableEmail = null
69 ) {
70 $this->overrideConfigValues( [
71 MainConfigNames::HiddenPrefs => $hiddenPref,
72 MainConfigNames::EnableEmail => $enableEmail,
73 ] );
74 parent::testLoadFromSubmission( $args, $data, $expectState );
77 public static function provideLoadFromSubmission() {
78 $unhidden = [];
79 $hidden = [ 'realname' ];
81 return [
82 'Empty request, unhidden, email enabled' => [
83 [],
84 [],
85 false,
86 $unhidden,
87 true
89 'email + realname, unhidden, email enabled' => [
90 [],
91 $data = [ 'email' => 'Email', 'realname' => 'Name' ],
92 $data,
93 $unhidden,
94 true
96 'email empty, unhidden, email enabled' => [
97 [],
98 $data = [ 'email' => '', 'realname' => 'Name' ],
99 $data,
100 $unhidden,
101 true
103 'email omitted, unhidden, email enabled' => [
105 [ 'realname' => 'Name' ],
106 false,
107 $unhidden,
108 true
110 'realname empty, unhidden, email enabled' => [
112 $data = [ 'email' => 'Email', 'realname' => '' ],
113 $data,
114 $unhidden,
115 true
117 'realname omitted, unhidden, email enabled' => [
119 [ 'email' => 'Email' ],
120 false,
121 $unhidden,
122 true
124 'Empty request, hidden, email enabled' => [
127 false,
128 $hidden,
129 true
131 'email + realname, hidden, email enabled' => [
133 [ 'email' => 'Email', 'realname' => 'Name' ],
134 [ 'email' => 'Email' ],
135 $hidden,
136 true
138 'email empty, hidden, email enabled' => [
140 $data = [ 'email' => '', 'realname' => 'Name' ],
141 [ 'email' => '' ],
142 $hidden,
143 true
145 'email omitted, hidden, email enabled' => [
147 [ 'realname' => 'Name' ],
148 false,
149 $hidden,
150 true
152 'realname empty, hidden, email enabled' => [
154 $data = [ 'email' => 'Email', 'realname' => '' ],
155 [ 'email' => 'Email' ],
156 $hidden,
157 true
159 'realname omitted, hidden, email enabled' => [
161 [ 'email' => 'Email' ],
162 [ 'email' => 'Email' ],
163 $hidden,
164 true
166 'email + realname, unhidden, email disabled' => [
168 [ 'email' => 'Email', 'realname' => 'Name' ],
169 [ 'realname' => 'Name' ],
170 $unhidden,
171 false
173 'email omitted, unhidden, email disabled' => [
175 [ 'realname' => 'Name' ],
176 [ 'realname' => 'Name' ],
177 $unhidden,
178 false
180 'email empty, unhidden, email disabled' => [
182 [ 'email' => '', 'realname' => 'Name' ],
183 [ 'realname' => 'Name' ],
184 $unhidden,
185 false