Merge "Move Title::isNamespaceProtected() to PermissionManager."
[lhc/web/wiklou.git] / tests / phpunit / includes / TitlePermissionTest.php
1 <?php
2
3 use MediaWiki\Block\DatabaseBlock;
4 use MediaWiki\Block\Restriction\PageRestriction;
5 use MediaWiki\Block\SystemBlock;
6 use MediaWiki\MediaWikiServices;
7
8 /**
9 * @group Database
10 *
11 * @covers \MediaWiki\Permissions\PermissionManager::getPermissionErrors
12 * @covers \MediaWiki\Permissions\PermissionManager::getPermissionErrorsInternal
13 */
14 class TitlePermissionTest extends MediaWikiLangTestCase {
15
16 /**
17 * @var string
18 */
19 protected $userName, $altUserName;
20
21 /**
22 * @var Title
23 */
24 protected $title;
25
26 /**
27 * @var User
28 */
29 protected $user, $anonUser, $userUser, $altUser;
30
31 protected function setUp() {
32 parent::setUp();
33
34 $localZone = 'UTC';
35 $localOffset = date( 'Z' ) / 60;
36
37 $this->setMwGlobals( [
38 'wgLocaltimezone' => $localZone,
39 'wgLocalTZoffset' => $localOffset,
40 'wgNamespaceProtection' => [
41 NS_MEDIAWIKI => 'editinterface',
42 ],
43 ] );
44 // Without this testUserBlock will use a non-English context on non-English MediaWiki
45 // installations (because of how Title::checkUserBlock is implemented) and fail.
46 RequestContext::resetMain();
47
48 $this->userName = 'Useruser';
49 $this->altUserName = 'Altuseruser';
50 date_default_timezone_set( $localZone );
51
52 $this->title = Title::makeTitle( NS_MAIN, "Main Page" );
53 if ( !isset( $this->userUser ) || !( $this->userUser instanceof User ) ) {
54 $this->userUser = User::newFromName( $this->userName );
55
56 if ( !$this->userUser->getId() ) {
57 $this->userUser = User::createNew( $this->userName, [
58 "email" => "test@example.com",
59 "real_name" => "Test User" ] );
60 $this->userUser->load();
61 }
62
63 $this->altUser = User::newFromName( $this->altUserName );
64 if ( !$this->altUser->getId() ) {
65 $this->altUser = User::createNew( $this->altUserName, [
66 "email" => "alttest@example.com",
67 "real_name" => "Test User Alt" ] );
68 $this->altUser->load();
69 }
70
71 $this->anonUser = User::newFromId( 0 );
72
73 $this->user = $this->userUser;
74 }
75 $this->resetServices();
76 }
77
78 protected function setTitle( $ns, $title = "Main_Page" ) {
79 $this->title = Title::makeTitle( $ns, $title );
80 }
81
82 protected function setUser( $userName = null ) {
83 if ( $userName === 'anon' ) {
84 $this->user = $this->anonUser;
85 } elseif ( $userName === null || $userName === $this->userName ) {
86 $this->user = $this->userUser;
87 } else {
88 $this->user = $this->altUser;
89 }
90 }
91
92 /**
93 * @todo This test method should be split up into separate test methods and
94 * data providers
95 *
96 * This test is failing per T201776.
97 *
98 * @group Broken
99 * @covers \MediaWiki\Permissions\PermissionManager::checkQuickPermissions
100 */
101 public function testQuickPermissions() {
102 $prefix = MediaWikiServices::getInstance()->getContentLanguage()->
103 getFormattedNsText( NS_PROJECT );
104
105 $this->setUser( 'anon' );
106 $this->setTitle( NS_TALK );
107 $this->overrideUserPermissions( $this->user, "createtalk" );
108 $res = $this->title->getUserPermissionsErrors( 'create', $this->user );
109 $this->assertEquals( [], $res );
110
111 $this->setTitle( NS_TALK );
112 $this->overrideUserPermissions( $this->user, "createpage" );
113 $res = $this->title->getUserPermissionsErrors( 'create', $this->user );
114 $this->assertEquals( [ [ "nocreatetext" ] ], $res );
115
116 $this->setTitle( NS_TALK );
117 $this->overrideUserPermissions( $this->user, "" );
118 $res = $this->title->getUserPermissionsErrors( 'create', $this->user );
119 $this->assertEquals( [ [ 'nocreatetext' ] ], $res );
120
121 $this->setTitle( NS_MAIN );
122 $this->overrideUserPermissions( $this->user, "createpage" );
123 $res = $this->title->getUserPermissionsErrors( 'create', $this->user );
124 $this->assertEquals( [], $res );
125
126 $this->setTitle( NS_MAIN );
127 $this->overrideUserPermissions( $this->user, "createtalk" );
128 $res = $this->title->getUserPermissionsErrors( 'create', $this->user );
129 $this->assertEquals( [ [ 'nocreatetext' ] ], $res );
130
131 $this->setUser( $this->userName );
132 $this->setTitle( NS_TALK );
133 $this->overrideUserPermissions( $this->user, "createtalk" );
134 $res = $this->title->getUserPermissionsErrors( 'create', $this->user );
135 $this->assertEquals( [], $res );
136
137 $this->setTitle( NS_TALK );
138 $this->overrideUserPermissions( $this->user, "createpage" );
139 $res = $this->title->getUserPermissionsErrors( 'create', $this->user );
140 $this->assertEquals( [ [ 'nocreate-loggedin' ] ], $res );
141
142 $this->setTitle( NS_TALK );
143 $this->overrideUserPermissions( $this->user );
144 $res = $this->title->getUserPermissionsErrors( 'create', $this->user );
145 $this->assertEquals( [ [ 'nocreate-loggedin' ] ], $res );
146
147 $this->setTitle( NS_MAIN );
148 $this->overrideUserPermissions( $this->user, "createpage" );
149 $res = $this->title->getUserPermissionsErrors( 'create', $this->user );
150 $this->assertEquals( [], $res );
151
152 $this->setTitle( NS_MAIN );
153 $this->overrideUserPermissions( $this->user, "createtalk" );
154 $res = $this->title->getUserPermissionsErrors( 'create', $this->user );
155 $this->assertEquals( [ [ 'nocreate-loggedin' ] ], $res );
156
157 $this->setTitle( NS_MAIN );
158 $this->overrideUserPermissions( $this->user );
159 $res = $this->title->getUserPermissionsErrors( 'create', $this->user );
160 $this->assertEquals( [ [ 'nocreate-loggedin' ] ], $res );
161
162 $this->setUser( 'anon' );
163 $this->setTitle( NS_USER, $this->userName . '' );
164 $this->overrideUserPermissions( $this->user );
165 $res = $this->title->getUserPermissionsErrors( 'move', $this->user );
166 $this->assertEquals( [ [ 'cant-move-user-page' ], [ 'movenologintext' ] ], $res );
167
168 $this->setTitle( NS_USER, $this->userName . '/subpage' );
169 $this->overrideUserPermissions( $this->user );
170 $res = $this->title->getUserPermissionsErrors( 'move', $this->user );
171 $this->assertEquals( [ [ 'movenologintext' ] ], $res );
172
173 $this->setTitle( NS_USER, $this->userName . '' );
174 $this->overrideUserPermissions( $this->user, "move-rootuserpages" );
175 $res = $this->title->getUserPermissionsErrors( 'move', $this->user );
176 $this->assertEquals( [ [ 'movenologintext' ] ], $res );
177
178 $this->setTitle( NS_USER, $this->userName . '/subpage' );
179 $this->overrideUserPermissions( $this->user, "move-rootuserpages" );
180 $res = $this->title->getUserPermissionsErrors( 'move', $this->user );
181 $this->assertEquals( [ [ 'movenologintext' ] ], $res );
182
183 $this->setTitle( NS_USER, $this->userName . '' );
184 $this->overrideUserPermissions( $this->user, "" );
185 $res = $this->title->getUserPermissionsErrors( 'move', $this->user );
186 $this->assertEquals( [ [ 'cant-move-user-page' ], [ 'movenologintext' ] ], $res );
187
188 $this->setTitle( NS_USER, $this->userName . '/subpage' );
189 $this->overrideUserPermissions( $this->user, "" );
190 $res = $this->title->getUserPermissionsErrors( 'move', $this->user );
191 $this->assertEquals( [ [ 'movenologintext' ] ], $res );
192
193 $this->setTitle( NS_USER, $this->userName . '' );
194 $this->overrideUserPermissions( $this->user, "move-rootuserpages" );
195 $res = $this->title->getUserPermissionsErrors( 'move', $this->user );
196 $this->assertEquals( [ [ 'movenologintext' ] ], $res );
197
198 $this->setTitle( NS_USER, $this->userName . '/subpage' );
199 $this->overrideUserPermissions( $this->user, "move-rootuserpages" );
200 $res = $this->title->getUserPermissionsErrors( 'move', $this->user );
201 $this->assertEquals( [ [ 'movenologintext' ] ], $res );
202
203 $this->setUser( $this->userName );
204 $this->setTitle( NS_FILE, "img.png" );
205 $this->overrideUserPermissions( $this->user );
206 $res = $this->title->getUserPermissionsErrors( 'move', $this->user );
207 $this->assertEquals( [ [ 'movenotallowedfile' ], [ 'movenotallowed' ] ], $res );
208
209 $this->setTitle( NS_FILE, "img.png" );
210 $this->overrideUserPermissions( $this->user, "movefile" );
211 $res = $this->title->getUserPermissionsErrors( 'move', $this->user );
212 $this->assertEquals( [ [ 'movenotallowed' ] ], $res );
213
214 $this->setUser( 'anon' );
215 $this->setTitle( NS_FILE, "img.png" );
216 $this->overrideUserPermissions( $this->user );
217 $res = $this->title->getUserPermissionsErrors( 'move', $this->user );
218 $this->assertEquals( [ [ 'movenotallowedfile' ], [ 'movenologintext' ] ], $res );
219
220 $this->setTitle( NS_FILE, "img.png" );
221 $this->overrideUserPermissions( $this->user, "movefile" );
222 $res = $this->title->getUserPermissionsErrors( 'move', $this->user );
223 $this->assertEquals( [ [ 'movenologintext' ] ], $res );
224
225 $this->setUser( $this->userName );
226 $this->overrideUserPermissions( $this->user, "move" );
227 $this->runGroupPermissions( 'move', [ [ 'movenotallowedfile' ] ] );
228
229 $this->overrideUserPermissions( $this->user );
230 $this->runGroupPermissions(
231 'move',
232 [ [ 'movenotallowedfile' ], [ 'movenotallowed' ] ]
233 );
234
235 $this->setUser( 'anon' );
236 $this->overrideUserPermissions( $this->user, "move" );
237 $this->runGroupPermissions( 'move', [ [ 'movenotallowedfile' ] ] );
238
239 $this->overrideUserPermissions( $this->user );
240 $this->runGroupPermissions(
241 'move',
242 [ [ 'movenotallowedfile' ], [ 'movenotallowed' ] ],
243 [ [ 'movenotallowedfile' ], [ 'movenologintext' ] ]
244 );
245
246 if ( $this->isWikitextNS( NS_MAIN ) ) {
247 // NOTE: some content models don't allow moving
248 // @todo find a Wikitext namespace for testing
249
250 $this->setTitle( NS_MAIN );
251 $this->setUser( 'anon' );
252 $this->overrideUserPermissions( $this->user, "move" );
253 $this->runGroupPermissions( 'move', [] );
254
255 $this->overrideUserPermissions( $this->user, "" );
256 $this->runGroupPermissions( 'move', [ [ 'movenotallowed' ] ],
257 [ [ 'movenologintext' ] ] );
258
259 $this->setUser( $this->userName );
260 $this->overrideUserPermissions( $this->user, "" );
261 $this->runGroupPermissions( 'move', [ [ 'movenotallowed' ] ] );
262
263 $this->overrideUserPermissions( $this->user, "move" );
264 $this->runGroupPermissions( 'move', [] );
265
266 $this->setUser( 'anon' );
267 $this->overrideUserPermissions( $this->user, 'move' );
268 $res = $this->title->getUserPermissionsErrors( 'move-target', $this->user );
269 $this->assertEquals( [], $res );
270
271 $this->overrideUserPermissions( $this->user );
272 $res = $this->title->getUserPermissionsErrors( 'move-target', $this->user );
273 $this->assertEquals( [ [ 'movenotallowed' ] ], $res );
274 }
275
276 $this->setTitle( NS_USER );
277 $this->setUser( $this->userName );
278 $this->overrideUserPermissions( $this->user, [ "move", "move-rootuserpages" ] );
279 $res = $this->title->getUserPermissionsErrors( 'move-target', $this->user );
280 $this->assertEquals( [], $res );
281
282 $this->overrideUserPermissions( $this->user, "move" );
283 $res = $this->title->getUserPermissionsErrors( 'move-target', $this->user );
284 $this->assertEquals( [ [ 'cant-move-to-user-page' ] ], $res );
285
286 $this->setUser( 'anon' );
287 $this->overrideUserPermissions( $this->user, [ "move", "move-rootuserpages" ] );
288 $res = $this->title->getUserPermissionsErrors( 'move-target', $this->user );
289 $this->assertEquals( [], $res );
290
291 $this->setTitle( NS_USER, "User/subpage" );
292 $this->overrideUserPermissions( $this->user, [ "move", "move-rootuserpages" ] );
293 $res = $this->title->getUserPermissionsErrors( 'move-target', $this->user );
294 $this->assertEquals( [], $res );
295
296 $this->overrideUserPermissions( $this->user, "move" );
297 $res = $this->title->getUserPermissionsErrors( 'move-target', $this->user );
298 $this->assertEquals( [], $res );
299
300 $this->setUser( 'anon' );
301 $check = [
302 'edit' => [
303 [ [ 'badaccess-groups', "*, [[$prefix:Users|Users]]", 2 ] ],
304 [ [ 'badaccess-group0' ] ],
305 [],
306 true
307 ],
308 'protect' => [
309 [ [
310 'badaccess-groups',
311 "[[$prefix:Administrators|Administrators]]", 1 ],
312 [ 'protect-cantedit'
313 ] ],
314 [ [ 'badaccess-group0' ], [ 'protect-cantedit' ] ],
315 [ [ 'protect-cantedit' ] ],
316 false
317 ],
318 '' => [ [], [], [], true ]
319 ];
320
321 foreach ( [ "edit", "protect", "" ] as $action ) {
322 $this->overrideUserPermissions( $this->user );
323 $this->assertEquals( $check[$action][0],
324 $this->title->getUserPermissionsErrors( $action, $this->user, true ) );
325 $this->assertEquals( $check[$action][0],
326 $this->title->getUserPermissionsErrors( $action, $this->user, 'full' ) );
327 $this->assertEquals( $check[$action][0],
328 $this->title->getUserPermissionsErrors( $action, $this->user, 'secure' ) );
329
330 global $wgGroupPermissions;
331 $old = $wgGroupPermissions;
332 $wgGroupPermissions = [];
333
334 $this->resetServices();
335
336 $this->assertEquals( $check[$action][1],
337 $this->title->getUserPermissionsErrors( $action, $this->user, true ) );
338 $this->assertEquals( $check[$action][1],
339 $this->title->getUserPermissionsErrors( $action, $this->user, 'full' ) );
340 $this->assertEquals( $check[$action][1],
341 $this->title->getUserPermissionsErrors( $action, $this->user, 'secure' ) );
342
343 $wgGroupPermissions = $old;
344 $this->resetServices();
345
346 $this->overrideUserPermissions( $this->user, $action );
347 $this->assertEquals( $check[$action][2],
348 $this->title->getUserPermissionsErrors( $action, $this->user, true ) );
349 $this->assertEquals( $check[$action][2],
350 $this->title->getUserPermissionsErrors( $action, $this->user, 'full' ) );
351 $this->assertEquals( $check[$action][2],
352 $this->title->getUserPermissionsErrors( $action, $this->user, 'secure' ) );
353
354 $this->overrideUserPermissions( $this->user, $action );
355 $this->assertEquals( $check[$action][3],
356 $this->title->userCan( $action, $this->user, true ) );
357 $this->assertEquals( $check[$action][3],
358 $this->title->quickUserCan( $action, $this->user ) );
359 # count( User::getGroupsWithPermissions( $action ) ) < 1
360 }
361 }
362
363 protected function runGroupPermissions( $action, $result, $result2 = null ) {
364 global $wgGroupPermissions;
365
366 if ( $result2 === null ) {
367 $result2 = $result;
368 }
369
370 // XXX: there could be a better way to handle this, but since we need to
371 // override PermissionManager service each time globals are changed
372 // and in the same time we need to keep user permissions overrides from the outside
373 // the best we can do inside this method is to save & restore faked user perms
374
375 $userPermsOverrides = MediaWikiServices::getInstance()->getPermissionManager()
376 ->getUserPermissions( $this->user );
377
378 $wgGroupPermissions['autoconfirmed']['move'] = false;
379 $wgGroupPermissions['user']['move'] = false;
380 $this->resetServices();
381 $this->overrideUserPermissions( $this->user, $userPermsOverrides );
382 $res = $this->title->getUserPermissionsErrors( $action, $this->user );
383 $this->assertEquals( $result, $res );
384
385 $wgGroupPermissions['autoconfirmed']['move'] = true;
386 $wgGroupPermissions['user']['move'] = false;
387 $this->resetServices();
388 $this->overrideUserPermissions( $this->user, $userPermsOverrides );
389 $res = $this->title->getUserPermissionsErrors( $action, $this->user );
390 $this->assertEquals( $result2, $res );
391
392 $wgGroupPermissions['autoconfirmed']['move'] = true;
393 $wgGroupPermissions['user']['move'] = true;
394 $this->resetServices();
395 $this->overrideUserPermissions( $this->user, $userPermsOverrides );
396 $res = $this->title->getUserPermissionsErrors( $action, $this->user );
397 $this->assertEquals( $result2, $res );
398
399 $wgGroupPermissions['autoconfirmed']['move'] = false;
400 $wgGroupPermissions['user']['move'] = true;
401 $this->resetServices();
402 $this->overrideUserPermissions( $this->user, $userPermsOverrides );
403 $res = $this->title->getUserPermissionsErrors( $action, $this->user );
404 $this->assertEquals( $result2, $res );
405 }
406
407 /**
408 * @todo This test method should be split up into separate test methods and
409 * data providers
410 * @covers \MediaWiki\Permissions\PermissionManager::checkSpecialsAndNSPermissions
411 */
412 public function testSpecialsAndNSPermissions() {
413 $this->setUser( $this->userName );
414
415 $this->setTitle( NS_SPECIAL );
416
417 $this->assertEquals( [ [ 'badaccess-group0' ], [ 'ns-specialprotected' ] ],
418 $this->title->getUserPermissionsErrors( 'bogus', $this->user ) );
419
420 $this->setTitle( NS_MAIN );
421 $this->overrideUserPermissions( $this->user, 'bogus' );
422 $this->assertEquals( [],
423 $this->title->getUserPermissionsErrors( 'bogus', $this->user ) );
424
425 $this->setTitle( NS_MAIN );
426 $this->overrideUserPermissions( $this->user );
427 $this->assertEquals( [ [ 'badaccess-group0' ] ],
428 $this->title->getUserPermissionsErrors( 'bogus', $this->user ) );
429
430 $this->mergeMwGlobalArrayValue( 'wgNamespaceProtection', [
431 NS_USER => [ 'bogus' ]
432 ] );
433 $this->resetServices();
434 $this->setTitle( NS_USER );
435 $this->overrideUserPermissions( $this->user );
436 $this->assertEquals( [ [ 'badaccess-group0' ],
437 [ 'namespaceprotected', 'User', 'bogus' ] ],
438 $this->title->getUserPermissionsErrors( 'bogus', $this->user ) );
439
440 $this->setTitle( NS_MEDIAWIKI );
441 $this->overrideUserPermissions( $this->user, 'bogus' );
442 $this->assertEquals( [ [ 'protectedinterface', 'bogus' ] ],
443 $this->title->getUserPermissionsErrors( 'bogus', $this->user ) );
444
445 $this->setTitle( NS_MEDIAWIKI );
446 $this->overrideUserPermissions( $this->user, 'bogus' );
447 $this->assertEquals( [ [ 'protectedinterface', 'bogus' ] ],
448 $this->title->getUserPermissionsErrors( 'bogus', $this->user ) );
449
450 $this->setMwGlobals( 'wgNamespaceProtection', null );
451 $this->resetServices();
452 $this->overrideUserPermissions( $this->user, 'bogus' );
453 $this->assertEquals( [],
454 $this->title->getUserPermissionsErrors( 'bogus', $this->user ) );
455 $this->assertEquals( true,
456 $this->title->userCan( 'bogus', $this->user ) );
457
458 $this->overrideUserPermissions( $this->user );
459 $this->assertEquals( [ [ 'badaccess-group0' ] ],
460 $this->title->getUserPermissionsErrors( 'bogus', $this->user ) );
461 $this->assertEquals( false,
462 $this->title->userCan( 'bogus', $this->user ) );
463 }
464
465 /**
466 * @todo This test method should be split up into separate test methods and
467 * data providers
468 * @covers \MediaWiki\Permissions\PermissionManager::checkUserConfigPermissions
469 */
470 public function testJsConfigEditPermissions() {
471 $this->setUser( $this->userName );
472
473 $this->setTitle( NS_USER, $this->userName . '/test.js' );
474 $this->runConfigEditPermissions(
475 [ [ 'badaccess-group0' ], [ 'mycustomjsprotected', 'bogus' ] ],
476
477 [ [ 'badaccess-group0' ], [ 'mycustomjsprotected', 'bogus' ] ],
478 [ [ 'badaccess-group0' ], [ 'mycustomjsprotected', 'bogus' ] ],
479 [ [ 'badaccess-group0' ] ],
480
481 [ [ 'badaccess-group0' ], [ 'mycustomjsprotected', 'bogus' ] ],
482 [ [ 'badaccess-group0' ], [ 'mycustomjsprotected', 'bogus' ] ],
483 [ [ 'badaccess-group0' ] ],
484 [ [ 'badaccess-groups' ] ]
485 );
486 }
487
488 /**
489 * @todo This test method should be split up into separate test methods and
490 * data providers
491 * @covers \MediaWiki\Permissions\PermissionManager::checkUserConfigPermissions
492 */
493 public function testJsonConfigEditPermissions() {
494 $prefix = MediaWikiServices::getInstance()->getContentLanguage()->
495 getFormattedNsText( NS_PROJECT );
496 $this->setUser( $this->userName );
497
498 $this->setTitle( NS_USER, $this->userName . '/test.json' );
499 $this->runConfigEditPermissions(
500 [ [ 'badaccess-group0' ], [ 'mycustomjsonprotected', 'bogus' ] ],
501
502 [ [ 'badaccess-group0' ], [ 'mycustomjsonprotected', 'bogus' ] ],
503 [ [ 'badaccess-group0' ] ],
504 [ [ 'badaccess-group0' ], [ 'mycustomjsonprotected', 'bogus' ] ],
505
506 [ [ 'badaccess-group0' ], [ 'mycustomjsonprotected', 'bogus' ] ],
507 [ [ 'badaccess-group0' ] ],
508 [ [ 'badaccess-group0' ], [ 'mycustomjsonprotected', 'bogus' ] ],
509 [ [ 'badaccess-groups' ] ]
510 );
511 }
512
513 /**
514 * @todo This test method should be split up into separate test methods and
515 * data providers
516 * @covers \MediaWiki\Permissions\PermissionManager::checkUserConfigPermissions
517 */
518 public function testCssConfigEditPermissions() {
519 $this->setUser( $this->userName );
520
521 $this->setTitle( NS_USER, $this->userName . '/test.css' );
522 $this->runConfigEditPermissions(
523 [ [ 'badaccess-group0' ], [ 'mycustomcssprotected', 'bogus' ] ],
524
525 [ [ 'badaccess-group0' ] ],
526 [ [ 'badaccess-group0' ], [ 'mycustomcssprotected', 'bogus' ] ],
527 [ [ 'badaccess-group0' ], [ 'mycustomcssprotected', 'bogus' ] ],
528
529 [ [ 'badaccess-group0' ] ],
530 [ [ 'badaccess-group0' ], [ 'mycustomcssprotected', 'bogus' ] ],
531 [ [ 'badaccess-group0' ], [ 'mycustomcssprotected', 'bogus' ] ],
532 [ [ 'badaccess-groups' ] ]
533 );
534 }
535
536 /**
537 * @todo This test method should be split up into separate test methods and
538 * data providers
539 * @covers \MediaWiki\Permissions\PermissionManager::checkUserConfigPermissions
540 */
541 public function testOtherJsConfigEditPermissions() {
542 $this->setUser( $this->userName );
543
544 $this->setTitle( NS_USER, $this->altUserName . '/test.js' );
545 $this->runConfigEditPermissions(
546 [ [ 'badaccess-group0' ], [ 'customjsprotected', 'bogus' ] ],
547
548 [ [ 'badaccess-group0' ], [ 'customjsprotected', 'bogus' ] ],
549 [ [ 'badaccess-group0' ], [ 'customjsprotected', 'bogus' ] ],
550 [ [ 'badaccess-group0' ], [ 'customjsprotected', 'bogus' ] ],
551
552 [ [ 'badaccess-group0' ], [ 'customjsprotected', 'bogus' ] ],
553 [ [ 'badaccess-group0' ], [ 'customjsprotected', 'bogus' ] ],
554 [ [ 'badaccess-group0' ] ],
555 [ [ 'badaccess-groups' ] ]
556 );
557 }
558
559 /**
560 * @todo This test method should be split up into separate test methods and
561 * data providers
562 * @covers \MediaWiki\Permissions\PermissionManager::checkUserConfigPermissions
563 */
564 public function testOtherJsonConfigEditPermissions() {
565 $this->setUser( $this->userName );
566
567 $this->setTitle( NS_USER, $this->altUserName . '/test.json' );
568 $this->runConfigEditPermissions(
569 [ [ 'badaccess-group0' ], [ 'customjsonprotected', 'bogus' ] ],
570
571 [ [ 'badaccess-group0' ], [ 'customjsonprotected', 'bogus' ] ],
572 [ [ 'badaccess-group0' ], [ 'customjsonprotected', 'bogus' ] ],
573 [ [ 'badaccess-group0' ], [ 'customjsonprotected', 'bogus' ] ],
574
575 [ [ 'badaccess-group0' ], [ 'customjsonprotected', 'bogus' ] ],
576 [ [ 'badaccess-group0' ] ],
577 [ [ 'badaccess-group0' ], [ 'customjsonprotected', 'bogus' ] ],
578 [ [ 'badaccess-groups' ] ]
579 );
580 }
581
582 /**
583 * @todo This test method should be split up into separate test methods and
584 * data providers
585 * @covers \MediaWiki\Permissions\PermissionManager::checkUserConfigPermissions
586 */
587 public function testOtherCssConfigEditPermissions() {
588 $this->setUser( $this->userName );
589
590 $this->setTitle( NS_USER, $this->altUserName . '/test.css' );
591 $this->runConfigEditPermissions(
592 [ [ 'badaccess-group0' ], [ 'customcssprotected', 'bogus' ] ],
593
594 [ [ 'badaccess-group0' ], [ 'customcssprotected', 'bogus' ] ],
595 [ [ 'badaccess-group0' ], [ 'customcssprotected', 'bogus' ] ],
596 [ [ 'badaccess-group0' ], [ 'customcssprotected', 'bogus' ] ],
597
598 [ [ 'badaccess-group0' ] ],
599 [ [ 'badaccess-group0' ], [ 'customcssprotected', 'bogus' ] ],
600 [ [ 'badaccess-group0' ], [ 'customcssprotected', 'bogus' ] ],
601 [ [ 'badaccess-groups' ] ]
602 );
603 }
604
605 /**
606 * @todo This test method should be split up into separate test methods and
607 * data providers
608 * @covers \MediaWiki\Permissions\PermissionManager::checkUserConfigPermissions
609 */
610 public function testOtherNonConfigEditPermissions() {
611 $this->setUser( $this->userName );
612
613 $this->setTitle( NS_USER, $this->altUserName . '/tempo' );
614 $this->runConfigEditPermissions(
615 [ [ 'badaccess-group0' ] ],
616
617 [ [ 'badaccess-group0' ] ],
618 [ [ 'badaccess-group0' ] ],
619 [ [ 'badaccess-group0' ] ],
620
621 [ [ 'badaccess-group0' ] ],
622 [ [ 'badaccess-group0' ] ],
623 [ [ 'badaccess-group0' ] ],
624 [ [ 'badaccess-groups' ] ]
625 );
626 }
627
628 /**
629 * @todo This should use data providers like the other methods here.
630 * @covers \MediaWiki\Permissions\PermissionManager::checkUserConfigPermissions
631 */
632 public function testPatrolActionConfigEditPermissions() {
633 $this->setUser( 'anon' );
634 $this->setTitle( NS_USER, 'ToPatrolOrNotToPatrol' );
635 $this->runConfigEditPermissions(
636 [ [ 'badaccess-group0' ] ],
637
638 [ [ 'badaccess-group0' ] ],
639 [ [ 'badaccess-group0' ] ],
640 [ [ 'badaccess-group0' ] ],
641
642 [ [ 'badaccess-group0' ] ],
643 [ [ 'badaccess-group0' ] ],
644 [ [ 'badaccess-group0' ] ],
645 [ [ 'badaccess-groups' ] ]
646 );
647 }
648
649 protected function runConfigEditPermissions(
650 $resultNone,
651 $resultMyCss,
652 $resultMyJson,
653 $resultMyJs,
654 $resultUserCss,
655 $resultUserJson,
656 $resultUserJs,
657 $resultPatrol
658 ) {
659 $this->overrideUserPermissions( $this->user );
660 $result = $this->title->getUserPermissionsErrors( 'bogus', $this->user );
661 $this->assertEquals( $resultNone, $result );
662
663 $this->overrideUserPermissions( $this->user, 'editmyusercss' );
664 $result = $this->title->getUserPermissionsErrors( 'bogus', $this->user );
665 $this->assertEquals( $resultMyCss, $result );
666
667 $this->overrideUserPermissions( $this->user, 'editmyuserjson' );
668 $result = $this->title->getUserPermissionsErrors( 'bogus', $this->user );
669 $this->assertEquals( $resultMyJson, $result );
670
671 $this->overrideUserPermissions( $this->user, 'editmyuserjs' );
672 $result = $this->title->getUserPermissionsErrors( 'bogus', $this->user );
673 $this->assertEquals( $resultMyJs, $result );
674
675 $this->overrideUserPermissions( $this->user, 'editusercss' );
676 $result = $this->title->getUserPermissionsErrors( 'bogus', $this->user );
677 $this->assertEquals( $resultUserCss, $result );
678
679 $this->overrideUserPermissions( $this->user, 'edituserjson' );
680 $result = $this->title->getUserPermissionsErrors( 'bogus', $this->user );
681 $this->assertEquals( $resultUserJson, $result );
682
683 $this->overrideUserPermissions( $this->user, 'edituserjs' );
684 $result = $this->title->getUserPermissionsErrors( 'bogus', $this->user );
685 $this->assertEquals( $resultUserJs, $result );
686
687 $this->overrideUserPermissions( $this->user );
688 $result = $this->title->getUserPermissionsErrors( 'patrol', $this->user );
689 $this->assertEquals( reset( $resultPatrol[0] ), reset( $result[0] ) );
690
691 $this->overrideUserPermissions( $this->user, [ 'edituserjs', 'edituserjson', 'editusercss' ] );
692 $result = $this->title->getUserPermissionsErrors( 'bogus', $this->user );
693 $this->assertEquals( [ [ 'badaccess-group0' ] ], $result );
694 }
695
696 /**
697 * @todo This test method should be split up into separate test methods and
698 * data providers
699 *
700 * This test is failing per T201776.
701 *
702 * @group Broken
703 * @covers \MediaWiki\Permissions\PermissionManager::checkPageRestrictions
704 */
705 public function testPageRestrictions() {
706 $prefix = MediaWikiServices::getInstance()->getContentLanguage()->
707 getFormattedNsText( NS_PROJECT );
708
709 $this->setTitle( NS_MAIN );
710 $this->title->mRestrictionsLoaded = true;
711 $this->overrideUserPermissions( $this->user, "edit" );
712 $this->title->mRestrictions = [ "bogus" => [ 'bogus', "sysop", "protect", "" ] ];
713
714 $this->assertEquals( [],
715 $this->title->getUserPermissionsErrors( 'edit',
716 $this->user ) );
717
718 $this->assertEquals( true,
719 $this->title->quickUserCan( 'edit', $this->user ) );
720 $this->title->mRestrictions = [ "edit" => [ 'bogus', "sysop", "protect", "" ],
721 "bogus" => [ 'bogus', "sysop", "protect", "" ] ];
722
723 $this->assertEquals( [ [ 'badaccess-group0' ],
724 [ 'protectedpagetext', 'bogus', 'bogus' ],
725 [ 'protectedpagetext', 'editprotected', 'bogus' ],
726 [ 'protectedpagetext', 'protect', 'bogus' ] ],
727 $this->title->getUserPermissionsErrors( 'bogus',
728 $this->user ) );
729 $this->assertEquals( [ [ 'protectedpagetext', 'bogus', 'edit' ],
730 [ 'protectedpagetext', 'editprotected', 'edit' ],
731 [ 'protectedpagetext', 'protect', 'edit' ] ],
732 $this->title->getUserPermissionsErrors( 'edit',
733 $this->user ) );
734 $this->overrideUserPermissions( $this->user );
735 $this->assertEquals( [ [ 'badaccess-group0' ],
736 [ 'protectedpagetext', 'bogus', 'bogus' ],
737 [ 'protectedpagetext', 'editprotected', 'bogus' ],
738 [ 'protectedpagetext', 'protect', 'bogus' ] ],
739 $this->title->getUserPermissionsErrors( 'bogus',
740 $this->user ) );
741 $this->assertEquals( [ [ 'badaccess-groups', "*, [[$prefix:Users|Users]]", 2 ],
742 [ 'protectedpagetext', 'bogus', 'edit' ],
743 [ 'protectedpagetext', 'editprotected', 'edit' ],
744 [ 'protectedpagetext', 'protect', 'edit' ] ],
745 $this->title->getUserPermissionsErrors( 'edit',
746 $this->user ) );
747 $this->overrideUserPermissions( $this->user, [ "edit", "editprotected" ] );
748 $this->assertEquals( [ [ 'badaccess-group0' ],
749 [ 'protectedpagetext', 'bogus', 'bogus' ],
750 [ 'protectedpagetext', 'protect', 'bogus' ] ],
751 $this->title->getUserPermissionsErrors( 'bogus',
752 $this->user ) );
753 $this->assertEquals( [
754 [ 'protectedpagetext', 'bogus', 'edit' ],
755 [ 'protectedpagetext', 'protect', 'edit' ] ],
756 $this->title->getUserPermissionsErrors( 'edit',
757 $this->user ) );
758
759 $this->title->mCascadeRestriction = true;
760 $this->overrideUserPermissions( $this->user, "edit" );
761 $this->assertEquals( false,
762 $this->title->quickUserCan( 'bogus', $this->user ) );
763 $this->assertEquals( false,
764 $this->title->quickUserCan( 'edit', $this->user ) );
765 $this->assertEquals( [ [ 'badaccess-group0' ],
766 [ 'protectedpagetext', 'bogus', 'bogus' ],
767 [ 'protectedpagetext', 'editprotected', 'bogus' ],
768 [ 'protectedpagetext', 'protect', 'bogus' ] ],
769 $this->title->getUserPermissionsErrors( 'bogus',
770 $this->user ) );
771 $this->assertEquals( [ [ 'protectedpagetext', 'bogus', 'edit' ],
772 [ 'protectedpagetext', 'editprotected', 'edit' ],
773 [ 'protectedpagetext', 'protect', 'edit' ] ],
774 $this->title->getUserPermissionsErrors( 'edit',
775 $this->user ) );
776
777 $this->overrideUserPermissions( $this->user, [ "edit", "editprotected" ] );
778 $this->assertEquals( false,
779 $this->title->quickUserCan( 'bogus', $this->user ) );
780 $this->assertEquals( false,
781 $this->title->quickUserCan( 'edit', $this->user ) );
782 $this->assertEquals( [ [ 'badaccess-group0' ],
783 [ 'protectedpagetext', 'bogus', 'bogus' ],
784 [ 'protectedpagetext', 'protect', 'bogus' ],
785 [ 'protectedpagetext', 'protect', 'bogus' ] ],
786 $this->title->getUserPermissionsErrors( 'bogus',
787 $this->user ) );
788 $this->assertEquals( [ [ 'protectedpagetext', 'bogus', 'edit' ],
789 [ 'protectedpagetext', 'protect', 'edit' ],
790 [ 'protectedpagetext', 'protect', 'edit' ] ],
791 $this->title->getUserPermissionsErrors( 'edit',
792 $this->user ) );
793 }
794
795 /**
796 * @covers \MediaWiki\Permissions\PermissionManager::checkCascadingSourcesRestrictions
797 */
798 public function testCascadingSourcesRestrictions() {
799 $this->setTitle( NS_MAIN, "test page" );
800 $this->overrideUserPermissions( $this->user, [ "edit", "bogus" ] );
801
802 $this->title->mCascadeSources = [
803 Title::makeTitle( NS_MAIN, "Bogus" ),
804 Title::makeTitle( NS_MAIN, "UnBogus" )
805 ];
806 $this->title->mCascadingRestrictions = [
807 "bogus" => [ 'bogus', "sysop", "protect", "" ]
808 ];
809
810 $this->assertEquals( false,
811 $this->title->userCan( 'bogus', $this->user ) );
812 $this->assertEquals( [
813 [ "cascadeprotected", 2, "* [[:Bogus]]\n* [[:UnBogus]]\n", 'bogus' ],
814 [ "cascadeprotected", 2, "* [[:Bogus]]\n* [[:UnBogus]]\n", 'bogus' ],
815 [ "cascadeprotected", 2, "* [[:Bogus]]\n* [[:UnBogus]]\n", 'bogus' ] ],
816 $this->title->getUserPermissionsErrors( 'bogus', $this->user ) );
817
818 $this->assertEquals( true,
819 $this->title->userCan( 'edit', $this->user ) );
820 $this->assertEquals( [],
821 $this->title->getUserPermissionsErrors( 'edit', $this->user ) );
822 }
823
824 /**
825 * @todo This test method should be split up into separate test methods and
826 * data providers
827 * @covers \MediaWiki\Permissions\PermissionManager::checkActionPermissions
828 */
829 public function testActionPermissions() {
830 $this->overrideUserPermissions( $this->user, [ "createpage" ] );
831 $this->setTitle( NS_MAIN, "test page" );
832 $this->title->mTitleProtection['permission'] = '';
833 $this->title->mTitleProtection['user'] = $this->user->getId();
834 $this->title->mTitleProtection['expiry'] = 'infinity';
835 $this->title->mTitleProtection['reason'] = 'test';
836 $this->title->mCascadeRestriction = false;
837
838 $this->assertEquals( [ [ 'titleprotected', 'Useruser', 'test' ] ],
839 $this->title->getUserPermissionsErrors( 'create', $this->user ) );
840 $this->assertEquals( false,
841 $this->title->userCan( 'create', $this->user ) );
842
843 $this->title->mTitleProtection['permission'] = 'editprotected';
844 $this->overrideUserPermissions( $this->user, [ 'createpage', 'protect' ] );
845 $this->assertEquals( [ [ 'titleprotected', 'Useruser', 'test' ] ],
846 $this->title->getUserPermissionsErrors( 'create', $this->user ) );
847 $this->assertEquals( false,
848 $this->title->userCan( 'create', $this->user ) );
849
850 $this->overrideUserPermissions( $this->user, [ 'createpage', 'editprotected' ] );
851 $this->assertEquals( [],
852 $this->title->getUserPermissionsErrors( 'create', $this->user ) );
853 $this->assertEquals( true,
854 $this->title->userCan( 'create', $this->user ) );
855
856 $this->overrideUserPermissions( $this->user, [ 'createpage' ] );
857 $this->assertEquals( [ [ 'titleprotected', 'Useruser', 'test' ] ],
858 $this->title->getUserPermissionsErrors( 'create', $this->user ) );
859 $this->assertEquals( false,
860 $this->title->userCan( 'create', $this->user ) );
861
862 $this->setTitle( NS_MEDIA, "test page" );
863 $this->overrideUserPermissions( $this->user, [ "move" ] );
864 $this->assertEquals( false,
865 $this->title->userCan( 'move', $this->user ) );
866 $this->assertEquals( [ [ 'immobile-source-namespace', 'Media' ] ],
867 $this->title->getUserPermissionsErrors( 'move', $this->user ) );
868
869 $this->setTitle( NS_HELP, "test page" );
870 $this->assertEquals( [],
871 $this->title->getUserPermissionsErrors( 'move', $this->user ) );
872 $this->assertEquals( true,
873 $this->title->userCan( 'move', $this->user ) );
874
875 $this->title->mInterwiki = "no";
876 $this->assertEquals( [ [ 'immobile-source-page' ] ],
877 $this->title->getUserPermissionsErrors( 'move', $this->user ) );
878 $this->assertEquals( false,
879 $this->title->userCan( 'move', $this->user ) );
880
881 $this->setTitle( NS_MEDIA, "test page" );
882 $this->assertEquals( false,
883 $this->title->userCan( 'move-target', $this->user ) );
884 $this->assertEquals( [ [ 'immobile-target-namespace', 'Media' ] ],
885 $this->title->getUserPermissionsErrors( 'move-target', $this->user ) );
886
887 $this->setTitle( NS_HELP, "test page" );
888 $this->assertEquals( [],
889 $this->title->getUserPermissionsErrors( 'move-target', $this->user ) );
890 $this->assertEquals( true,
891 $this->title->userCan( 'move-target', $this->user ) );
892
893 $this->title->mInterwiki = "no";
894 $this->assertEquals( [ [ 'immobile-target-page' ] ],
895 $this->title->getUserPermissionsErrors( 'move-target', $this->user ) );
896 $this->assertEquals( false,
897 $this->title->userCan( 'move-target', $this->user ) );
898 }
899
900 /**
901 * @covers \MediaWiki\Permissions\PermissionManager::checkUserBlock
902 */
903 public function testUserBlock() {
904 $this->setMwGlobals( [
905 'wgEmailConfirmToEdit' => true,
906 'wgEmailAuthentication' => true,
907 'wgBlockDisablesLogin' => false,
908 ] );
909 $this->resetServices();
910
911 $this->overrideUserPermissions(
912 $this->user,
913 [ 'createpage', 'edit', 'move', 'rollback', 'patrol', 'upload', 'purge' ]
914 );
915 $this->setTitle( NS_HELP, "test page" );
916
917 # $wgEmailConfirmToEdit only applies to 'edit' action
918 $this->assertEquals( [],
919 $this->title->getUserPermissionsErrors( 'move-target', $this->user ) );
920 $this->assertContains( [ 'confirmedittext' ],
921 $this->title->getUserPermissionsErrors( 'edit', $this->user ) );
922
923 $this->setMwGlobals( 'wgEmailConfirmToEdit', false );
924 $this->resetServices();
925 $this->overrideUserPermissions(
926 $this->user,
927 [ 'createpage', 'edit', 'move', 'rollback', 'patrol', 'upload', 'purge' ]
928 );
929
930 $this->assertNotContains( [ 'confirmedittext' ],
931 $this->title->getUserPermissionsErrors( 'edit', $this->user ) );
932
933 # $wgEmailConfirmToEdit && !$user->isEmailConfirmed() && $action != 'createaccount'
934 $this->assertEquals( [],
935 $this->title->getUserPermissionsErrors( 'move-target',
936 $this->user ) );
937
938 global $wgLang;
939 $prev = time();
940 $now = time() + 120;
941 $this->user->mBlockedby = $this->user->getId();
942 $this->user->mBlock = new DatabaseBlock( [
943 'address' => '127.0.8.1',
944 'by' => $this->user->getId(),
945 'reason' => 'no reason given',
946 'timestamp' => $prev,
947 'auto' => true,
948 'expiry' => 0
949 ] );
950 $this->assertEquals( [ [ 'autoblockedtext',
951 "[[User:Useruser|\u{202A}Useruser\u{202C}]]", 'no reason given', '127.0.0.1',
952 "\u{202A}Useruser\u{202C}", null, 'infinite', '127.0.8.1',
953 $wgLang->timeanddate( wfTimestamp( TS_MW, $prev ), true ) ] ],
954 $this->title->getUserPermissionsErrors( 'move-target',
955 $this->user ) );
956
957 $this->assertEquals( false, $this->title->userCan( 'move-target', $this->user ) );
958 // quickUserCan should ignore user blocks
959 $this->assertEquals( true, $this->title->quickUserCan( 'move-target', $this->user ) );
960
961 global $wgLocalTZoffset;
962 $wgLocalTZoffset = -60;
963 $this->user->mBlockedby = $this->user->getName();
964 $this->user->mBlock = new DatabaseBlock( [
965 'address' => '127.0.8.1',
966 'by' => $this->user->getId(),
967 'reason' => 'no reason given',
968 'timestamp' => $now,
969 'auto' => false,
970 'expiry' => 10,
971 ] );
972 $this->assertEquals( [ [ 'blockedtext',
973 "[[User:Useruser|\u{202A}Useruser\u{202C}]]", 'no reason given', '127.0.0.1',
974 "\u{202A}Useruser\u{202C}", null, '23:00, 31 December 1969', '127.0.8.1',
975 $wgLang->timeanddate( wfTimestamp( TS_MW, $now ), true ) ] ],
976 $this->title->getUserPermissionsErrors( 'move-target', $this->user ) );
977 # $action != 'read' && $action != 'createaccount' && $user->isBlockedFrom( $this )
978 # $user->blockedFor() == ''
979 # $user->mBlock->mExpiry == 'infinity'
980
981 $this->user->mBlockedby = $this->user->getName();
982 $this->user->mBlock = new SystemBlock( [
983 'address' => '127.0.8.1',
984 'by' => $this->user->getId(),
985 'reason' => 'no reason given',
986 'timestamp' => $now,
987 'systemBlock' => 'test',
988 ] );
989
990 $errors = [ [ 'systemblockedtext',
991 "[[User:Useruser|\u{202A}Useruser\u{202C}]]", 'no reason given', '127.0.0.1',
992 "\u{202A}Useruser\u{202C}", 'test', 'infinite', '127.0.8.1',
993 $wgLang->timeanddate( wfTimestamp( TS_MW, $now ), true ) ] ];
994
995 $this->assertEquals( $errors,
996 $this->title->getUserPermissionsErrors( 'edit', $this->user ) );
997 $this->assertEquals( $errors,
998 $this->title->getUserPermissionsErrors( 'move-target', $this->user ) );
999 $this->assertEquals( $errors,
1000 $this->title->getUserPermissionsErrors( 'rollback', $this->user ) );
1001 $this->assertEquals( $errors,
1002 $this->title->getUserPermissionsErrors( 'patrol', $this->user ) );
1003 $this->assertEquals( $errors,
1004 $this->title->getUserPermissionsErrors( 'upload', $this->user ) );
1005 $this->assertEquals( [],
1006 $this->title->getUserPermissionsErrors( 'purge', $this->user ) );
1007
1008 // partial block message test
1009 $this->user->mBlockedby = $this->user->getName();
1010 $this->user->mBlock = new DatabaseBlock( [
1011 'address' => '127.0.8.1',
1012 'by' => $this->user->getId(),
1013 'reason' => 'no reason given',
1014 'timestamp' => $now,
1015 'sitewide' => false,
1016 'expiry' => 10,
1017 ] );
1018
1019 $this->assertEquals( [],
1020 $this->title->getUserPermissionsErrors( 'edit', $this->user ) );
1021 $this->assertEquals( [],
1022 $this->title->getUserPermissionsErrors( 'move-target', $this->user ) );
1023 $this->assertEquals( [],
1024 $this->title->getUserPermissionsErrors( 'rollback', $this->user ) );
1025 $this->assertEquals( [],
1026 $this->title->getUserPermissionsErrors( 'patrol', $this->user ) );
1027 $this->assertEquals( [],
1028 $this->title->getUserPermissionsErrors( 'upload', $this->user ) );
1029 $this->assertEquals( [],
1030 $this->title->getUserPermissionsErrors( 'purge', $this->user ) );
1031
1032 $this->user->mBlock->setRestrictions( [
1033 ( new PageRestriction( 0, $this->title->getArticleID() ) )->setTitle( $this->title ),
1034 ] );
1035
1036 $errors = [ [ 'blockedtext-partial',
1037 "[[User:Useruser|\u{202A}Useruser\u{202C}]]", 'no reason given', '127.0.0.1',
1038 "\u{202A}Useruser\u{202C}", null, '23:00, 31 December 1969', '127.0.8.1',
1039 $wgLang->timeanddate( wfTimestamp( TS_MW, $now ), true ) ] ];
1040
1041 $this->assertEquals( $errors,
1042 $this->title->getUserPermissionsErrors( 'edit', $this->user ) );
1043 $this->assertEquals( $errors,
1044 $this->title->getUserPermissionsErrors( 'move-target', $this->user ) );
1045 $this->assertEquals( $errors,
1046 $this->title->getUserPermissionsErrors( 'rollback', $this->user ) );
1047 $this->assertEquals( $errors,
1048 $this->title->getUserPermissionsErrors( 'patrol', $this->user ) );
1049 $this->assertEquals( [],
1050 $this->title->getUserPermissionsErrors( 'upload', $this->user ) );
1051 $this->assertEquals( [],
1052 $this->title->getUserPermissionsErrors( 'purge', $this->user ) );
1053
1054 // Test no block.
1055 $this->user->mBlockedby = null;
1056 $this->user->mBlock = null;
1057
1058 $this->assertEquals( [],
1059 $this->title->getUserPermissionsErrors( 'edit', $this->user ) );
1060 }
1061
1062 /**
1063 * @covers \MediaWiki\Permissions\PermissionManager::checkUserBlock
1064 *
1065 * Tests to determine that the passed in permission does not get mixed up with
1066 * an action of the same name.
1067 */
1068 public function testUserBlockAction() {
1069 global $wgLang;
1070
1071 $tester = $this->getMockBuilder( Action::class )
1072 ->disableOriginalConstructor()
1073 ->getMock();
1074 $tester->method( 'getName' )
1075 ->willReturn( 'tester' );
1076 $tester->method( 'getRestriction' )
1077 ->willReturn( 'test' );
1078 $tester->method( 'requiresUnblock' )
1079 ->willReturn( false );
1080
1081 $this->setMwGlobals( [
1082 'wgActions' => [
1083 'tester' => $tester,
1084 ],
1085 'wgGroupPermissions' => [
1086 '*' => [
1087 'tester' => true,
1088 ],
1089 ],
1090 ] );
1091 $this->resetServices();
1092
1093 $now = time();
1094 $this->user->mBlockedby = $this->user->getName();
1095 $this->user->mBlock = new DatabaseBlock( [
1096 'address' => '127.0.8.1',
1097 'by' => $this->user->getId(),
1098 'reason' => 'no reason given',
1099 'timestamp' => $now,
1100 'auto' => false,
1101 'expiry' => 'infinity',
1102 ] );
1103
1104 $errors = [ [ 'blockedtext',
1105 "[[User:Useruser|\u{202A}Useruser\u{202C}]]", 'no reason given', '127.0.0.1',
1106 "\u{202A}Useruser\u{202C}", null, 'infinite', '127.0.8.1',
1107 $wgLang->timeanddate( wfTimestamp( TS_MW, $now ), true ) ] ];
1108
1109 $this->assertEquals( $errors,
1110 $this->title->getUserPermissionsErrors( 'tester', $this->user ) );
1111 }
1112 }