3 namespace MediaWiki\Auth
;
7 * @covers MediaWiki\Auth\UserDataAuthenticationRequest
9 class UserDataAuthenticationRequestTest
extends AuthenticationRequestTestCase
{
11 protected function getInstance( array $args = [] ) {
12 return new UserDataAuthenticationRequest
;
15 protected function setUp() {
17 $this->setMwGlobals( 'wgHiddenPrefs', [] );
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 ) {
28 $user->setEmail( 'default@example.com' );
29 $user->setRealName( 'Fake Name' );
31 $req = new UserDataAuthenticationRequest
;
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();
45 [ 'email@example.com', 'Real Name', $good ],
46 [ 'email@example.com', '', $good ],
47 [ '', 'Real Name', $good ],
49 [ 'invalid-email', 'Real Name', \StatusValue
::newFatal( 'invalidemailaddress' ) ],
54 * @dataProvider provideLoadFromSubmission
56 public function testLoadFromSubmission(
57 array $args, array $data, $expectState /* $hiddenPref, $enableEmail */
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() {
67 $hidden = [ 'realname' ];
70 'Empty request, unhidden, email enabled' => [
77 'email + realname, unhidden, email enabled' => [
79 $data = [ 'email' => 'Email', 'realname' => 'Name' ],
84 'email empty, unhidden, email enabled' => [
86 $data = [ 'email' => '', 'realname' => 'Name' ],
91 'email omitted, unhidden, email enabled' => [
93 [ 'realname' => 'Name' ],
98 'realname empty, unhidden, email enabled' => [
100 $data = [ 'email' => 'Email', 'realname' => '' ],
105 'realname omitted, unhidden, email enabled' => [
107 [ 'email' => 'Email' ],
112 'Empty request, hidden, email enabled' => [
119 'email + realname, hidden, email enabled' => [
121 [ 'email' => 'Email', 'realname' => 'Name' ],
122 [ 'email' => 'Email' ],
126 'email empty, hidden, email enabled' => [
128 $data = [ 'email' => '', 'realname' => 'Name' ],
133 'email omitted, hidden, email enabled' => [
135 [ 'realname' => 'Name' ],
140 'realname empty, hidden, email enabled' => [
142 $data = [ 'email' => 'Email', 'realname' => '' ],
143 [ 'email' => 'Email' ],
147 'realname omitted, hidden, email enabled' => [
149 [ 'email' => 'Email' ],
150 [ 'email' => 'Email' ],
154 'email + realname, unhidden, email disabled' => [
156 [ 'email' => 'Email', 'realname' => 'Name' ],
157 [ 'realname' => 'Name' ],
161 'email omitted, unhidden, email disabled' => [
163 [ 'realname' => 'Name' ],
164 [ 'realname' => 'Name' ],
168 'email empty, unhidden, email disabled' => [
170 [ 'email' => '', 'realname' => 'Name' ],
171 [ 'realname' => 'Name' ],