MediaWiki  1.28.1
UserDataAuthenticationRequestTest.php
Go to the documentation of this file.
1 <?php
2 
3 namespace MediaWiki\Auth;
4 
10 
11  protected function getInstance( array $args = [] ) {
13  }
14 
15  protected function setUp() {
16  parent::setUp();
17  $this->setMwGlobals( 'wgHiddenPrefs', [] );
18  }
19 
26  public function testPopulateUser( $email, $realname, $expect ) {
27  $user = new \User();
28  $user->setEmail( 'default@example.com' );
29  $user->setRealName( 'Fake Name' );
30 
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() );
38  }
39 
40  }
41 
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' ) ],
50  ];
51  }
52 
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 );
63  }
64 
65  public function provideLoadFromSubmission() {
66  $unhidden = [];
67  $hidden = [ 'realname' ];
68 
69  return [
70  'Empty request, unhidden, email enabled' => [
71  [],
72  [],
73  false,
74  $unhidden,
75  true
76  ],
77  'email + realname, unhidden, email enabled' => [
78  [],
79  $data = [ 'email' => 'Email', 'realname' => 'Name' ],
80  $data,
81  $unhidden,
82  true
83  ],
84  'email empty, unhidden, email enabled' => [
85  [],
86  $data = [ 'email' => '', 'realname' => 'Name' ],
87  $data,
88  $unhidden,
89  true
90  ],
91  'email omitted, unhidden, email enabled' => [
92  [],
93  [ 'realname' => 'Name' ],
94  false,
95  $unhidden,
96  true
97  ],
98  'realname empty, unhidden, email enabled' => [
99  [],
100  $data = [ 'email' => 'Email', 'realname' => '' ],
101  $data,
102  $unhidden,
103  true
104  ],
105  'realname omitted, unhidden, email enabled' => [
106  [],
107  [ 'email' => 'Email' ],
108  false,
109  $unhidden,
110  true
111  ],
112  'Empty request, hidden, email enabled' => [
113  [],
114  [],
115  false,
116  $hidden,
117  true
118  ],
119  'email + realname, hidden, email enabled' => [
120  [],
121  [ 'email' => 'Email', 'realname' => 'Name' ],
122  [ 'email' => 'Email' ],
123  $hidden,
124  true
125  ],
126  'email empty, hidden, email enabled' => [
127  [],
128  $data = [ 'email' => '', 'realname' => 'Name' ],
129  [ 'email' => '' ],
130  $hidden,
131  true
132  ],
133  'email omitted, hidden, email enabled' => [
134  [],
135  [ 'realname' => 'Name' ],
136  false,
137  $hidden,
138  true
139  ],
140  'realname empty, hidden, email enabled' => [
141  [],
142  $data = [ 'email' => 'Email', 'realname' => '' ],
143  [ 'email' => 'Email' ],
144  $hidden,
145  true
146  ],
147  'realname omitted, hidden, email enabled' => [
148  [],
149  [ 'email' => 'Email' ],
150  [ 'email' => 'Email' ],
151  $hidden,
152  true
153  ],
154  'email + realname, unhidden, email disabled' => [
155  [],
156  [ 'email' => 'Email', 'realname' => 'Name' ],
157  [ 'realname' => 'Name' ],
158  $unhidden,
159  false
160  ],
161  'email omitted, unhidden, email disabled' => [
162  [],
163  [ 'realname' => 'Name' ],
164  [ 'realname' => 'Name' ],
165  $unhidden,
166  false
167  ],
168  'email empty, unhidden, email disabled' => [
169  [],
170  [ 'email' => '', 'realname' => 'Name' ],
171  [ 'realname' => 'Name' ],
172  $unhidden,
173  false
174  ],
175  ];
176  }
177 }
AuthManager MediaWiki\Auth\UserDataAuthenticationRequest.
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
Definition: deferred.txt:11
the array() calling protocol came about after MediaWiki 1.4rc1.
processing should stop and the error should be shown to the user * false
Definition: hooks.txt:189
static newFatal($message)
Factory function for fatal errors.
Definition: StatusValue.php:63
if($line===false) $args
Definition: cdb.php:64
testPopulateUser($email, $realname, $expect)
providePopulateUser
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return true
Definition: hooks.txt:1936
This represents additional user data requested on the account creation form.
static newGood($value=null)
Factory function for good results.
Definition: StatusValue.php:76
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a local account $user
Definition: hooks.txt:242
testLoadFromSubmission(array $args, array $data, $expectState)
provideLoadFromSubmission
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
this hook is for auditing only $req
Definition: hooks.txt:1007
setMwGlobals($pairs, $value=null)