3 namespace MediaWiki\Tests\Auth
;
5 use MediaWiki\Auth\UserDataAuthenticationRequest
;
6 use MediaWiki\MainConfigNames
;
7 use MediaWiki\User\User
;
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
{
22 $this->overrideConfigValue( MainConfigNames
::HiddenPrefs
, [] );
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 ) {
34 'UserSetEmailAuthenticationTimestamp',
35 'InvalidateEmailComplete',
40 $user->setEmail( 'default@example.com' );
41 $user->setRealName( 'Fake Name' );
43 $req = new UserDataAuthenticationRequest
;
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();
56 [ 'email@example.com', 'Real Name', $good ],
57 [ 'email@example.com', '', $good ],
58 [ '', 'Real Name', $good ],
60 [ 'invalid-email', 'Real Name', StatusValue
::newFatal( 'invalidemailaddress' ) ],
65 * @dataProvider provideLoadFromSubmission
67 public function testLoadFromSubmission(
68 array $args, array $data, $expectState, $hiddenPref = null, $enableEmail = null
70 $this->overrideConfigValues( [
71 MainConfigNames
::HiddenPrefs
=> $hiddenPref,
72 MainConfigNames
::EnableEmail
=> $enableEmail,
74 parent
::testLoadFromSubmission( $args, $data, $expectState );
77 public static function provideLoadFromSubmission() {
79 $hidden = [ 'realname' ];
82 'Empty request, unhidden, email enabled' => [
89 'email + realname, unhidden, email enabled' => [
91 $data = [ 'email' => 'Email', 'realname' => 'Name' ],
96 'email empty, unhidden, email enabled' => [
98 $data = [ 'email' => '', 'realname' => 'Name' ],
103 'email omitted, unhidden, email enabled' => [
105 [ 'realname' => 'Name' ],
110 'realname empty, unhidden, email enabled' => [
112 $data = [ 'email' => 'Email', 'realname' => '' ],
117 'realname omitted, unhidden, email enabled' => [
119 [ 'email' => 'Email' ],
124 'Empty request, hidden, email enabled' => [
131 'email + realname, hidden, email enabled' => [
133 [ 'email' => 'Email', 'realname' => 'Name' ],
134 [ 'email' => 'Email' ],
138 'email empty, hidden, email enabled' => [
140 $data = [ 'email' => '', 'realname' => 'Name' ],
145 'email omitted, hidden, email enabled' => [
147 [ 'realname' => 'Name' ],
152 'realname empty, hidden, email enabled' => [
154 $data = [ 'email' => 'Email', 'realname' => '' ],
155 [ 'email' => 'Email' ],
159 'realname omitted, hidden, email enabled' => [
161 [ 'email' => 'Email' ],
162 [ 'email' => 'Email' ],
166 'email + realname, unhidden, email disabled' => [
168 [ 'email' => 'Email', 'realname' => 'Name' ],
169 [ 'realname' => 'Name' ],
173 'email omitted, unhidden, email disabled' => [
175 [ 'realname' => 'Name' ],
176 [ 'realname' => 'Name' ],
180 'email empty, unhidden, email disabled' => [
182 [ 'email' => '', 'realname' => 'Name' ],
183 [ 'realname' => 'Name' ],