API: Fixes for AuthManager
[mediawiki.git] / tests / phpunit / includes / auth / UserDataAuthenticationRequestTest.php
blob7fe335117c2c27525ecf336a87aebebf756d1b47
1 <?php
3 namespace MediaWiki\Auth;
5 /**
6 * @group AuthManager
7 * @covers MediaWiki\Auth\UserDataAuthenticationRequest
8 */
9 class UserDataAuthenticationRequestTest extends AuthenticationRequestTestCase {
11 protected function getInstance( array $args = [] ) {
12 return new UserDataAuthenticationRequest;
15 protected function setUp() {
16 parent::setUp();
17 $this->setMwGlobals( 'wgHiddenPrefs', [] );
20 /**
21 * @dataProvider providePopulateUser
22 * @param string $email Email to set
23 * @param string $realname Realname to set
24 * @param StatusValue $expect Expected return
26 public function testPopulateUser( $email, $realname, $expect ) {
27 $user = new \User();
28 $user->setEmail( 'default@example.com' );
29 $user->setRealName( 'Fake Name' );
31 $req = new UserDataAuthenticationRequest;
32 $req->email = $email;
33 $req->realname = $realname;
34 $this->assertEquals( $expect, $req->populateUser( $user ) );
35 if ( $expect->isOk() ) {
36 $this->assertSame( $email ?: 'default@example.com', $user->getEmail() );
37 $this->assertSame( $realname ?: 'Fake Name', $user->getRealName() );
42 public static function providePopulateUser() {
43 $good = \StatusValue::newGood();
44 return [
45 [ 'email@example.com', 'Real Name', $good ],
46 [ 'email@example.com', '', $good ],
47 [ '', 'Real Name', $good ],
48 [ '', '', $good ],
49 [ 'invalid-email', 'Real Name', \StatusValue::newFatal( 'invalidemailaddress' ) ],
53 /**
54 * @dataProvider provideLoadFromSubmission
56 public function testLoadFromSubmission(
57 array $args, array $data, $expectState /* $hiddenPref, $enableEmail */
58 ) {
59 list( $args, $data, $expectState, $hiddenPref, $enableEmail ) = func_get_args();
60 $this->setMwGlobals( 'wgHiddenPrefs', $hiddenPref );
61 $this->setMwGlobals( 'wgEnableEmail', $enableEmail );
62 parent::testLoadFromSubmission( $args, $data, $expectState );
65 public function provideLoadFromSubmission() {
66 $unhidden = [];
67 $hidden = [ 'realname' ];
69 return [
70 'Empty request, unhidden, email enabled' => [
71 [],
72 [],
73 false,
74 $unhidden,
75 true
77 'email + realname, unhidden, email enabled' => [
78 [],
79 $data = [ 'email' => 'Email', 'realname' => 'Name' ],
80 $data,
81 $unhidden,
82 true
84 'email empty, unhidden, email enabled' => [
85 [],
86 $data = [ 'email' => '', 'realname' => 'Name' ],
87 $data,
88 $unhidden,
89 true
91 'email omitted, unhidden, email enabled' => [
92 [],
93 [ 'realname' => 'Name' ],
94 false,
95 $unhidden,
96 true
98 'realname empty, unhidden, email enabled' => [
99 [],
100 $data = [ 'email' => 'Email', 'realname' => '' ],
101 $data,
102 $unhidden,
103 true
105 'realname omitted, unhidden, email enabled' => [
107 [ 'email' => 'Email' ],
108 false,
109 $unhidden,
110 true
112 'Empty request, hidden, email enabled' => [
115 false,
116 $hidden,
117 true
119 'email + realname, hidden, email enabled' => [
121 [ 'email' => 'Email', 'realname' => 'Name' ],
122 [ 'email' => 'Email' ],
123 $hidden,
124 true
126 'email empty, hidden, email enabled' => [
128 $data = [ 'email' => '', 'realname' => 'Name' ],
129 [ 'email' => '' ],
130 $hidden,
131 true
133 'email omitted, hidden, email enabled' => [
135 [ 'realname' => 'Name' ],
136 false,
137 $hidden,
138 true
140 'realname empty, hidden, email enabled' => [
142 $data = [ 'email' => 'Email', 'realname' => '' ],
143 [ 'email' => 'Email' ],
144 $hidden,
145 true
147 'realname omitted, hidden, email enabled' => [
149 [ 'email' => 'Email' ],
150 [ 'email' => 'Email' ],
151 $hidden,
152 true
154 'email + realname, unhidden, email disabled' => [
156 [ 'email' => 'Email', 'realname' => 'Name' ],
157 [ 'realname' => 'Name' ],
158 $unhidden,
159 false
161 'email omitted, unhidden, email disabled' => [
163 [ 'realname' => 'Name' ],
164 [ 'realname' => 'Name' ],
165 $unhidden,
166 false
168 'email empty, unhidden, email disabled' => [
170 [ 'email' => '', 'realname' => 'Name' ],
171 [ 'realname' => 'Name' ],
172 $unhidden,
173 false