30 $localOffset = date(
'Z' ) / 60;
33 'wgLocaltimezone' => $localZone,
34 'wgLocalTZoffset' => $localOffset,
35 'wgNamespaceProtection' => [
43 $this->userName =
'Useruser';
44 $this->altUserName =
'Altuseruser';
45 date_default_timezone_set( $localZone );
48 if ( !isset( $this->userUser ) || !( $this->userUser instanceof
User ) ) {
51 if ( !$this->userUser->getId() ) {
53 "email" =>
"test@example.com",
54 "real_name" =>
"Test User" ] );
55 $this->userUser->load();
59 if ( !$this->altUser->getId() ) {
61 "email" =>
"alttest@example.com",
62 "real_name" =>
"Test User Alt" ] );
63 $this->altUser->load();
75 if ( is_array( $perm ) ) {
76 $this->
user->mRights = $perm;
78 $this->
user->mRights = [ $perm ];
107 $res = $this->
title->getUserPermissionsErrors(
'create', $this->
user );
108 $this->assertEquals( [],
$res );
112 $res = $this->
title->getUserPermissionsErrors(
'create', $this->
user );
113 $this->assertEquals( [ [
"nocreatetext" ] ],
$res );
117 $res = $this->
title->getUserPermissionsErrors(
'create', $this->
user );
118 $this->assertEquals( [ [
'nocreatetext' ] ],
$res );
122 $res = $this->
title->getUserPermissionsErrors(
'create', $this->
user );
123 $this->assertEquals( [],
$res );
127 $res = $this->
title->getUserPermissionsErrors(
'create', $this->
user );
128 $this->assertEquals( [ [
'nocreatetext' ] ],
$res );
130 $this->
setUser( $this->userName );
133 $res = $this->
title->getUserPermissionsErrors(
'create', $this->
user );
134 $this->assertEquals( [],
$res );
138 $res = $this->
title->getUserPermissionsErrors(
'create', $this->
user );
139 $this->assertEquals( [ [
'nocreate-loggedin' ] ],
$res );
143 $res = $this->
title->getUserPermissionsErrors(
'create', $this->
user );
144 $this->assertEquals( [ [
'nocreate-loggedin' ] ],
$res );
148 $res = $this->
title->getUserPermissionsErrors(
'create', $this->
user );
149 $this->assertEquals( [],
$res );
153 $res = $this->
title->getUserPermissionsErrors(
'create', $this->
user );
154 $this->assertEquals( [ [
'nocreate-loggedin' ] ],
$res );
158 $res = $this->
title->getUserPermissionsErrors(
'create', $this->
user );
159 $this->assertEquals( [ [
'nocreate-loggedin' ] ],
$res );
164 $res = $this->
title->getUserPermissionsErrors(
'move', $this->
user );
165 $this->assertEquals( [ [
'cant-move-user-page' ], [
'movenologintext' ] ],
$res );
169 $res = $this->
title->getUserPermissionsErrors(
'move', $this->
user );
170 $this->assertEquals( [ [
'movenologintext' ] ],
$res );
174 $res = $this->
title->getUserPermissionsErrors(
'move', $this->
user );
175 $this->assertEquals( [ [
'movenologintext' ] ],
$res );
179 $res = $this->
title->getUserPermissionsErrors(
'move', $this->
user );
180 $this->assertEquals( [ [
'movenologintext' ] ],
$res );
184 $res = $this->
title->getUserPermissionsErrors(
'move', $this->
user );
185 $this->assertEquals( [ [
'cant-move-user-page' ], [
'movenologintext' ] ],
$res );
189 $res = $this->
title->getUserPermissionsErrors(
'move', $this->
user );
190 $this->assertEquals( [ [
'movenologintext' ] ],
$res );
194 $res = $this->
title->getUserPermissionsErrors(
'move', $this->
user );
195 $this->assertEquals( [ [
'movenologintext' ] ],
$res );
199 $res = $this->
title->getUserPermissionsErrors(
'move', $this->
user );
200 $this->assertEquals( [ [
'movenologintext' ] ],
$res );
202 $this->
setUser( $this->userName );
205 $res = $this->
title->getUserPermissionsErrors(
'move', $this->
user );
206 $this->assertEquals( [ [
'movenotallowedfile' ], [
'movenotallowed' ] ],
$res );
210 $res = $this->
title->getUserPermissionsErrors(
'move', $this->
user );
211 $this->assertEquals( [ [
'movenotallowed' ] ],
$res );
216 $res = $this->
title->getUserPermissionsErrors(
'move', $this->
user );
217 $this->assertEquals( [ [
'movenotallowedfile' ], [
'movenologintext' ] ],
$res );
221 $res = $this->
title->getUserPermissionsErrors(
'move', $this->
user );
222 $this->assertEquals( [ [
'movenologintext' ] ],
$res );
224 $this->
setUser( $this->userName );
231 [ [
'movenotallowedfile' ], [
'movenotallowed' ] ]
241 [ [
'movenotallowedfile' ], [
'movenotallowed' ] ],
242 [ [
'movenotallowedfile' ], [
'movenologintext' ] ]
256 [ [
'movenologintext' ] ] );
258 $this->
setUser( $this->userName );
267 $res = $this->
title->getUserPermissionsErrors(
'move-target', $this->
user );
268 $this->assertEquals( [],
$res );
271 $res = $this->
title->getUserPermissionsErrors(
'move-target', $this->
user );
272 $this->assertEquals( [ [
'movenotallowed' ] ],
$res );
276 $this->
setUser( $this->userName );
277 $this->
setUserPerm( [
"move",
"move-rootuserpages" ] );
278 $res = $this->
title->getUserPermissionsErrors(
'move-target', $this->
user );
279 $this->assertEquals( [],
$res );
282 $res = $this->
title->getUserPermissionsErrors(
'move-target', $this->
user );
283 $this->assertEquals( [ [
'cant-move-to-user-page' ] ],
$res );
286 $this->
setUserPerm( [
"move",
"move-rootuserpages" ] );
287 $res = $this->
title->getUserPermissionsErrors(
'move-target', $this->
user );
288 $this->assertEquals( [],
$res );
291 $this->
setUserPerm( [
"move",
"move-rootuserpages" ] );
292 $res = $this->
title->getUserPermissionsErrors(
'move-target', $this->
user );
293 $this->assertEquals( [],
$res );
296 $res = $this->
title->getUserPermissionsErrors(
'move-target', $this->
user );
297 $this->assertEquals( [],
$res );
302 [ [
'badaccess-groups',
"*, [[$prefix:Users|Users]]", 2 ] ],
303 [ [
'badaccess-group0' ] ],
310 "[[$prefix:Administrators|Administrators]]", 1 ],
313 [ [
'badaccess-group0' ], [
'protect-cantedit' ] ],
314 [ [
'protect-cantedit' ] ],
317 '' => [ [], [], [],
true ]
320 foreach ( [
"edit",
"protect",
"" ]
as $action ) {
322 $this->assertEquals( $check[$action][0],
323 $this->
title->getUserPermissionsErrors( $action, $this->user,
true ) );
324 $this->assertEquals( $check[$action][0],
325 $this->
title->getUserPermissionsErrors( $action, $this->user,
'full' ) );
326 $this->assertEquals( $check[$action][0],
327 $this->
title->getUserPermissionsErrors( $action, $this->user,
'secure' ) );
333 $this->assertEquals( $check[$action][1],
334 $this->
title->getUserPermissionsErrors( $action, $this->user,
true ) );
335 $this->assertEquals( $check[$action][1],
336 $this->
title->getUserPermissionsErrors( $action, $this->user,
'full' ) );
337 $this->assertEquals( $check[$action][1],
338 $this->
title->getUserPermissionsErrors( $action, $this->user,
'secure' ) );
342 $this->assertEquals( $check[$action][2],
343 $this->
title->getUserPermissionsErrors( $action, $this->user,
true ) );
344 $this->assertEquals( $check[$action][2],
345 $this->
title->getUserPermissionsErrors( $action, $this->user,
'full' ) );
346 $this->assertEquals( $check[$action][2],
347 $this->
title->getUserPermissionsErrors( $action, $this->user,
'secure' ) );
350 $this->assertEquals( $check[$action][3],
351 $this->
title->userCan( $action, $this->user,
true ) );
352 $this->assertEquals( $check[$action][3],
353 $this->
title->quickUserCan( $action, $this->user ) );
354 # count( User::getGroupsWithPermissions( $action ) ) < 1
361 if ( $result2 ===
null ) {
367 $res = $this->
title->getUserPermissionsErrors( $action, $this->
user );
372 $res = $this->
title->getUserPermissionsErrors( $action, $this->
user );
373 $this->assertEquals( $result2,
$res );
377 $res = $this->
title->getUserPermissionsErrors( $action, $this->
user );
378 $this->assertEquals( $result2,
$res );
382 $res = $this->
title->getUserPermissionsErrors( $action, $this->
user );
383 $this->assertEquals( $result2,
$res );
392 $this->
setUser( $this->userName );
396 $this->assertEquals( [ [
'badaccess-group0' ], [
'ns-specialprotected' ] ],
397 $this->
title->getUserPermissionsErrors(
'bogus', $this->user ) );
401 $this->assertEquals( [],
402 $this->
title->getUserPermissionsErrors(
'bogus', $this->user ) );
406 $this->assertEquals( [ [
'badaccess-group0' ] ],
407 $this->
title->getUserPermissionsErrors(
'bogus', $this->user ) );
413 $this->assertEquals( [ [
'badaccess-group0' ],
414 [
'namespaceprotected',
'User',
'bogus' ] ],
415 $this->
title->getUserPermissionsErrors(
'bogus', $this->user ) );
419 $this->assertEquals( [ [
'protectedinterface',
'bogus' ] ],
420 $this->
title->getUserPermissionsErrors(
'bogus', $this->user ) );
424 $this->assertEquals( [ [
'protectedinterface',
'bogus' ] ],
425 $this->
title->getUserPermissionsErrors(
'bogus', $this->user ) );
430 $this->assertEquals( [],
431 $this->
title->getUserPermissionsErrors(
'bogus', $this->user ) );
432 $this->assertEquals(
true,
433 $this->
title->userCan(
'bogus', $this->user ) );
436 $this->assertEquals( [ [
'badaccess-group0' ] ],
437 $this->
title->getUserPermissionsErrors(
'bogus', $this->user ) );
438 $this->assertEquals(
false,
439 $this->
title->userCan(
'bogus', $this->user ) );
447 $this->
setUser( $this->userName );
451 [ [
'badaccess-group0' ], [
'mycustomjsprotected',
'bogus' ] ],
452 [ [
'badaccess-group0' ], [
'mycustomjsprotected',
'bogus' ] ],
453 [ [
'badaccess-group0' ] ],
454 [ [
'badaccess-group0' ], [
'mycustomjsprotected',
'bogus' ] ],
455 [ [
'badaccess-group0' ] ]
460 [ [
'badaccess-group0' ], [
'mycustomcssprotected',
'bogus' ] ],
461 [ [
'badaccess-group0' ] ],
462 [ [
'badaccess-group0' ], [
'mycustomcssprotected',
'bogus' ] ],
463 [ [
'badaccess-group0' ] ],
464 [ [
'badaccess-group0' ], [
'mycustomcssprotected',
'bogus' ] ]
469 [ [
'badaccess-group0' ], [
'customjsprotected',
'bogus' ] ],
470 [ [
'badaccess-group0' ], [
'customjsprotected',
'bogus' ] ],
471 [ [
'badaccess-group0' ], [
'customjsprotected',
'bogus' ] ],
472 [ [
'badaccess-group0' ], [
'customjsprotected',
'bogus' ] ],
473 [ [
'badaccess-group0' ] ]
478 [ [
'badaccess-group0' ], [
'customcssprotected',
'bogus' ] ],
479 [ [
'badaccess-group0' ], [
'customcssprotected',
'bogus' ] ],
480 [ [
'badaccess-group0' ], [
'customcssprotected',
'bogus' ] ],
481 [ [
'badaccess-group0' ] ],
482 [ [
'badaccess-group0' ], [
'customcssprotected',
'bogus' ] ]
487 [ [
'badaccess-group0' ] ],
488 [ [
'badaccess-group0' ] ],
489 [ [
'badaccess-group0' ] ],
490 [ [
'badaccess-group0' ] ],
491 [ [
'badaccess-group0' ] ]
497 $this->assertEquals( $result0,
498 $this->
title->getUserPermissionsErrors(
'bogus',
502 $this->assertEquals( $result1,
503 $this->
title->getUserPermissionsErrors(
'bogus',
507 $this->assertEquals( $result2,
508 $this->
title->getUserPermissionsErrors(
'bogus',
512 $this->assertEquals( $result3,
513 $this->
title->getUserPermissionsErrors(
'bogus',
517 $this->assertEquals( $result4,
518 $this->
title->getUserPermissionsErrors(
'bogus',
521 $this->
setUserPerm( [
'edituserjs',
'editusercss' ] );
522 $this->assertEquals( [ [
'badaccess-group0' ] ],
523 $this->
title->getUserPermissionsErrors(
'bogus',
537 $this->
title->mRestrictionsLoaded =
true;
539 $this->
title->mRestrictions = [
"bogus" => [
'bogus',
"sysop",
"protect",
"" ] ];
541 $this->assertEquals( [],
542 $this->
title->getUserPermissionsErrors(
'edit',
545 $this->assertEquals(
true,
546 $this->
title->quickUserCan(
'edit', $this->user ) );
547 $this->
title->mRestrictions = [
"edit" => [
'bogus',
"sysop",
"protect",
"" ],
548 "bogus" => [
'bogus',
"sysop",
"protect",
"" ] ];
550 $this->assertEquals( [ [
'badaccess-group0' ],
551 [
'protectedpagetext',
'bogus',
'bogus' ],
552 [
'protectedpagetext',
'editprotected',
'bogus' ],
553 [
'protectedpagetext',
'protect',
'bogus' ] ],
554 $this->
title->getUserPermissionsErrors(
'bogus',
556 $this->assertEquals( [ [
'protectedpagetext',
'bogus',
'edit' ],
557 [
'protectedpagetext',
'editprotected',
'edit' ],
558 [
'protectedpagetext',
'protect',
'edit' ] ],
559 $this->
title->getUserPermissionsErrors(
'edit',
562 $this->assertEquals( [ [
'badaccess-group0' ],
563 [
'protectedpagetext',
'bogus',
'bogus' ],
564 [
'protectedpagetext',
'editprotected',
'bogus' ],
565 [
'protectedpagetext',
'protect',
'bogus' ] ],
566 $this->
title->getUserPermissionsErrors(
'bogus',
568 $this->assertEquals( [ [
'badaccess-groups',
"*, [[$prefix:Users|Users]]", 2 ],
569 [
'protectedpagetext',
'bogus',
'edit' ],
570 [
'protectedpagetext',
'editprotected',
'edit' ],
571 [
'protectedpagetext',
'protect',
'edit' ] ],
572 $this->
title->getUserPermissionsErrors(
'edit',
575 $this->assertEquals( [ [
'badaccess-group0' ],
576 [
'protectedpagetext',
'bogus',
'bogus' ],
577 [
'protectedpagetext',
'protect',
'bogus' ] ],
578 $this->
title->getUserPermissionsErrors(
'bogus',
580 $this->assertEquals( [
581 [
'protectedpagetext',
'bogus',
'edit' ],
582 [
'protectedpagetext',
'protect',
'edit' ] ],
583 $this->
title->getUserPermissionsErrors(
'edit',
586 $this->
title->mCascadeRestriction =
true;
588 $this->assertEquals(
false,
589 $this->
title->quickUserCan(
'bogus', $this->user ) );
590 $this->assertEquals(
false,
591 $this->
title->quickUserCan(
'edit', $this->user ) );
592 $this->assertEquals( [ [
'badaccess-group0' ],
593 [
'protectedpagetext',
'bogus',
'bogus' ],
594 [
'protectedpagetext',
'editprotected',
'bogus' ],
595 [
'protectedpagetext',
'protect',
'bogus' ] ],
596 $this->
title->getUserPermissionsErrors(
'bogus',
598 $this->assertEquals( [ [
'protectedpagetext',
'bogus',
'edit' ],
599 [
'protectedpagetext',
'editprotected',
'edit' ],
600 [
'protectedpagetext',
'protect',
'edit' ] ],
601 $this->
title->getUserPermissionsErrors(
'edit',
605 $this->assertEquals(
false,
606 $this->
title->quickUserCan(
'bogus', $this->user ) );
607 $this->assertEquals(
false,
608 $this->
title->quickUserCan(
'edit', $this->user ) );
609 $this->assertEquals( [ [
'badaccess-group0' ],
610 [
'protectedpagetext',
'bogus',
'bogus' ],
611 [
'protectedpagetext',
'protect',
'bogus' ],
612 [
'protectedpagetext',
'protect',
'bogus' ] ],
613 $this->
title->getUserPermissionsErrors(
'bogus',
615 $this->assertEquals( [ [
'protectedpagetext',
'bogus',
'edit' ],
616 [
'protectedpagetext',
'protect',
'edit' ],
617 [
'protectedpagetext',
'protect',
'edit' ] ],
618 $this->
title->getUserPermissionsErrors(
'edit',
626 $this->
title->mCascadeSources = [
630 $this->
title->mCascadingRestrictions = [
631 "bogus" => [
'bogus',
"sysop",
"protect",
"" ]
634 $this->assertEquals(
false,
635 $this->
title->userCan(
'bogus', $this->user ) );
636 $this->assertEquals( [
637 [
"cascadeprotected", 2,
"* [[:Bogus]]\n* [[:UnBogus]]\n",
'bogus' ],
638 [
"cascadeprotected", 2,
"* [[:Bogus]]\n* [[:UnBogus]]\n",
'bogus' ],
639 [
"cascadeprotected", 2,
"* [[:Bogus]]\n* [[:UnBogus]]\n",
'bogus' ] ],
640 $this->
title->getUserPermissionsErrors(
'bogus', $this->user ) );
642 $this->assertEquals(
true,
643 $this->
title->userCan(
'edit', $this->user ) );
644 $this->assertEquals( [],
645 $this->
title->getUserPermissionsErrors(
'edit', $this->user ) );
655 $this->
title->mTitleProtection[
'permission'] =
'';
656 $this->
title->mTitleProtection[
'user'] = $this->
user->getId();
657 $this->
title->mTitleProtection[
'expiry'] =
'infinity';
658 $this->
title->mTitleProtection[
'reason'] =
'test';
659 $this->
title->mCascadeRestriction =
false;
661 $this->assertEquals( [ [
'titleprotected',
'Useruser',
'test' ] ],
662 $this->
title->getUserPermissionsErrors(
'create', $this->user ) );
663 $this->assertEquals(
false,
664 $this->
title->userCan(
'create', $this->user ) );
666 $this->
title->mTitleProtection[
'permission'] =
'editprotected';
668 $this->assertEquals( [ [
'titleprotected',
'Useruser',
'test' ] ],
669 $this->
title->getUserPermissionsErrors(
'create', $this->user ) );
670 $this->assertEquals(
false,
671 $this->
title->userCan(
'create', $this->user ) );
673 $this->
setUserPerm( [
'createpage',
'editprotected' ] );
674 $this->assertEquals( [],
675 $this->
title->getUserPermissionsErrors(
'create', $this->user ) );
676 $this->assertEquals(
true,
677 $this->
title->userCan(
'create', $this->user ) );
680 $this->assertEquals( [ [
'titleprotected',
'Useruser',
'test' ] ],
681 $this->
title->getUserPermissionsErrors(
'create', $this->user ) );
682 $this->assertEquals(
false,
683 $this->
title->userCan(
'create', $this->user ) );
687 $this->assertEquals(
false,
688 $this->
title->userCan(
'move', $this->user ) );
689 $this->assertEquals( [ [
'immobile-source-namespace',
'Media' ] ],
690 $this->
title->getUserPermissionsErrors(
'move', $this->user ) );
693 $this->assertEquals( [],
694 $this->
title->getUserPermissionsErrors(
'move', $this->user ) );
695 $this->assertEquals(
true,
696 $this->
title->userCan(
'move', $this->user ) );
698 $this->
title->mInterwiki =
"no";
699 $this->assertEquals( [ [
'immobile-source-page' ] ],
700 $this->
title->getUserPermissionsErrors(
'move', $this->user ) );
701 $this->assertEquals(
false,
702 $this->
title->userCan(
'move', $this->user ) );
705 $this->assertEquals(
false,
706 $this->
title->userCan(
'move-target', $this->user ) );
707 $this->assertEquals( [ [
'immobile-target-namespace',
'Media' ] ],
708 $this->
title->getUserPermissionsErrors(
'move-target', $this->user ) );
711 $this->assertEquals( [],
712 $this->
title->getUserPermissionsErrors(
'move-target', $this->user ) );
713 $this->assertEquals(
true,
714 $this->
title->userCan(
'move-target', $this->user ) );
716 $this->
title->mInterwiki =
"no";
717 $this->assertEquals( [ [
'immobile-target-page' ] ],
718 $this->
title->getUserPermissionsErrors(
'move-target', $this->user ) );
719 $this->assertEquals(
false,
720 $this->
title->userCan(
'move-target', $this->user ) );
732 $this->assertEquals( [ [
'confirmedittext' ] ],
733 $this->
title->getUserPermissionsErrors(
'move-target', $this->user ) );
735 $this->assertEquals(
true, $this->
title->userCan(
'move-target', $this->user ) );
737 # $wgEmailConfirmToEdit && !$user->isEmailConfirmed() && $action != 'createaccount'
738 $this->assertEquals( [],
739 $this->
title->getUserPermissionsErrors(
'move-target',
745 $this->
user->mBlockedby = $this->
user->getId();
747 'address' =>
'127.0.8.1',
748 'by' => $this->
user->getId(),
749 'reason' =>
'no reason given',
750 'timestamp' => $prev + 3600,
754 $this->
user->mBlock->mTimestamp = 0;
755 $this->assertEquals( [ [
'autoblockedtext',
756 '[[User:Useruser|Useruser]]',
'no reason given',
'127.0.0.1',
757 'Useruser',
null,
'infinite',
'127.0.8.1',
759 $this->
title->getUserPermissionsErrors(
'move-target',
762 $this->assertEquals(
false, $this->
title->userCan(
'move-target', $this->user ) );
764 $this->assertEquals(
true, $this->
title->quickUserCan(
'move-target', $this->user ) );
768 $this->
user->mBlockedby = $this->
user->getName();
770 'address' =>
'127.0.8.1',
771 'by' => $this->
user->getId(),
772 'reason' =>
'no reason given',
777 $this->assertEquals( [ [
'blockedtext',
778 '[[User:Useruser|Useruser]]',
'no reason given',
'127.0.0.1',
779 'Useruser',
null,
'23:00, 31 December 1969',
'127.0.8.1',
781 $this->
title->getUserPermissionsErrors(
'move-target', $this->
user ) );
782 # $action != 'read' && $action != 'createaccount' && $user->isBlockedFrom( $this )
783 # $user->blockedFor() == ''
784 # $user->mBlock->mExpiry == 'infinity'
786 $this->
user->mBlockedby = $this->
user->getName();
788 'address' =>
'127.0.8.1',
789 'by' => $this->
user->getId(),
790 'reason' =>
'no reason given',
794 'systemBlock' =>
'test',
796 $this->assertEquals( [ [
'systemblockedtext',
797 '[[User:Useruser|Useruser]]',
'no reason given',
'127.0.0.1',
798 'Useruser',
'test',
'23:00, 31 December 1969',
'127.0.8.1',
800 $this->
title->getUserPermissionsErrors(
'move-target', $this->
user ) );