50 $localOffset = date(
'Z' ) / 60;
53 'wgLocaltimezone' => $localZone,
54 'wgLocalTZoffset' => $localOffset,
55 'wgNamespaceProtection' => [
63 $this->userName =
'Useruser';
64 $this->altUserName =
'Altuseruser';
65 date_default_timezone_set( $localZone );
68 if ( !isset( $this->userUser ) || !( $this->userUser instanceof
User ) ) {
71 if ( !$this->userUser->getId() ) {
73 "email" =>
"test@example.com",
74 "real_name" =>
"Test User" ] );
75 $this->userUser->load();
79 if ( !$this->altUser->getId() ) {
81 "email" =>
"alttest@example.com",
82 "real_name" =>
"Test User Alt" ] );
83 $this->altUser->load();
99 if ( is_array( $perm ) ) {
100 $this->
user->mRights = $perm;
102 $this->
user->mRights = [ $perm ];
136 $res = $this->permissionManager
137 ->getPermissionErrors(
'create', $this->
user, $this->
title );
138 $this->assertEquals( [],
$res );
142 $res = $this->permissionManager
143 ->getPermissionErrors(
'create', $this->
user, $this->
title );
144 $this->assertEquals( [ [
"nocreatetext" ] ],
$res );
148 $res = $this->permissionManager
149 ->getPermissionErrors(
'create', $this->
user, $this->
title );
150 $this->assertEquals( [ [
'nocreatetext' ] ],
$res );
154 $res = $this->permissionManager
155 ->getPermissionErrors(
'create', $this->
user, $this->
title );
156 $this->assertEquals( [],
$res );
160 $res = $this->permissionManager
161 ->getPermissionErrors(
'create', $this->
user, $this->
title );
162 $this->assertEquals( [ [
'nocreatetext' ] ],
$res );
164 $this->
setUser( $this->userName );
167 $res = $this->permissionManager
168 ->getPermissionErrors(
'create', $this->
user, $this->
title );
169 $this->assertEquals( [],
$res );
173 $res = $this->permissionManager
174 ->getPermissionErrors(
'create', $this->
user, $this->
title );
175 $this->assertEquals( [ [
'nocreate-loggedin' ] ],
$res );
179 $res = $this->permissionManager
180 ->getPermissionErrors(
'create', $this->
user, $this->
title );
181 $this->assertEquals( [ [
'nocreate-loggedin' ] ],
$res );
185 $res = $this->permissionManager
186 ->getPermissionErrors(
'create', $this->
user, $this->
title );
187 $this->assertEquals( [],
$res );
191 $res = $this->permissionManager
192 ->getPermissionErrors(
'create', $this->
user, $this->
title );
193 $this->assertEquals( [ [
'nocreate-loggedin' ] ],
$res );
197 $res = $this->permissionManager
198 ->getPermissionErrors(
'create', $this->
user, $this->
title );
199 $this->assertEquals( [ [
'nocreate-loggedin' ] ],
$res );
204 $res = $this->permissionManager
205 ->getPermissionErrors(
'move', $this->
user, $this->
title );
206 $this->assertEquals( [ [
'cant-move-user-page' ], [
'movenologintext' ] ],
$res );
210 $res = $this->permissionManager
211 ->getPermissionErrors(
'move', $this->
user, $this->
title );
212 $this->assertEquals( [ [
'movenologintext' ] ],
$res );
216 $res = $this->permissionManager
217 ->getPermissionErrors(
'move', $this->
user, $this->
title );
218 $this->assertEquals( [ [
'movenologintext' ] ],
$res );
222 $res = $this->permissionManager
223 ->getPermissionErrors(
'move', $this->
user, $this->
title );
224 $this->assertEquals( [ [
'movenologintext' ] ],
$res );
228 $res = $this->permissionManager
229 ->getPermissionErrors(
'move', $this->
user, $this->
title );
230 $this->assertEquals( [ [
'cant-move-user-page' ], [
'movenologintext' ] ],
$res );
234 $res = $this->permissionManager
235 ->getPermissionErrors(
'move', $this->
user, $this->
title );
236 $this->assertEquals( [ [
'movenologintext' ] ],
$res );
240 $res = $this->permissionManager
241 ->getPermissionErrors(
'move', $this->
user, $this->
title );
242 $this->assertEquals( [ [
'movenologintext' ] ],
$res );
246 $res = $this->permissionManager
247 ->getPermissionErrors(
'move', $this->
user, $this->
title );
248 $this->assertEquals( [ [
'movenologintext' ] ],
$res );
250 $this->
setUser( $this->userName );
253 $res = $this->permissionManager
254 ->getPermissionErrors(
'move', $this->
user, $this->
title );
255 $this->assertEquals( [ [
'movenotallowedfile' ], [
'movenotallowed' ] ],
$res );
259 $res = $this->permissionManager
260 ->getPermissionErrors(
'move', $this->
user, $this->
title );
261 $this->assertEquals( [ [
'movenotallowed' ] ],
$res );
266 $res = $this->permissionManager
267 ->getPermissionErrors(
'move', $this->
user, $this->
title );
268 $this->assertEquals( [ [
'movenotallowedfile' ], [
'movenologintext' ] ],
$res );
272 $res = $this->permissionManager
273 ->getPermissionErrors(
'move', $this->
user, $this->
title );
274 $this->assertEquals( [ [
'movenologintext' ] ],
$res );
276 $this->
setUser( $this->userName );
283 [ [
'movenotallowedfile' ], [
'movenotallowed' ] ]
293 [ [
'movenotallowedfile' ], [
'movenotallowed' ] ],
294 [ [
'movenotallowedfile' ], [
'movenologintext' ] ]
308 [ [
'movenologintext' ] ] );
310 $this->
setUser( $this->userName );
319 $res = $this->permissionManager
320 ->getPermissionErrors(
'move-target', $this->
user, $this->
title );
321 $this->assertEquals( [],
$res );
324 $res = $this->permissionManager
325 ->getPermissionErrors(
'move-target', $this->
user, $this->
title );
326 $this->assertEquals( [ [
'movenotallowed' ] ],
$res );
330 $this->
setUser( $this->userName );
331 $this->
setUserPerm( [
"move",
"move-rootuserpages" ] );
332 $res = $this->permissionManager
333 ->getPermissionErrors(
'move-target', $this->
user, $this->
title );
334 $this->assertEquals( [],
$res );
337 $res = $this->permissionManager
338 ->getPermissionErrors(
'move-target', $this->
user, $this->
title );
339 $this->assertEquals( [ [
'cant-move-to-user-page' ] ],
$res );
342 $this->
setUserPerm( [
"move",
"move-rootuserpages" ] );
343 $res = $this->permissionManager
344 ->getPermissionErrors(
'move-target', $this->
user, $this->
title );
345 $this->assertEquals( [],
$res );
348 $this->
setUserPerm( [
"move",
"move-rootuserpages" ] );
349 $res = $this->permissionManager
350 ->getPermissionErrors(
'move-target', $this->
user, $this->
title );
351 $this->assertEquals( [],
$res );
354 $res = $this->permissionManager
355 ->getPermissionErrors(
'move-target', $this->
user, $this->
title );
356 $this->assertEquals( [],
$res );
361 [ [
'badaccess-groups',
"*, [[$prefix:Users|Users]]", 2 ] ],
362 [ [
'badaccess-group0' ] ],
369 "[[$prefix:Administrators|Administrators]]", 1 ],
372 [ [
'badaccess-group0' ], [
'protect-cantedit' ] ],
373 [ [
'protect-cantedit' ] ],
376 '' => [ [], [], [],
true ]
379 foreach ( [
"edit",
"protect",
"" ]
as $action ) {
381 $this->assertEquals( $check[
$action][0],
382 $this->permissionManager
384 $this->assertEquals( $check[
$action][0],
385 $this->permissionManager
387 $this->assertEquals( $check[
$action][0],
388 $this->permissionManager
395 $this->assertEquals( $check[
$action][1],
396 $this->permissionManager
398 $this->assertEquals( $check[
$action][1],
399 $this->permissionManager
401 $this->assertEquals( $check[
$action][1],
402 $this->permissionManager
404 $wgGroupPermissions = $old;
407 $this->assertEquals( $check[
$action][2],
408 $this->permissionManager
410 $this->assertEquals( $check[
$action][2],
411 $this->permissionManager
413 $this->assertEquals( $check[
$action][2],
414 $this->permissionManager
418 $this->assertEquals( $check[
$action][3],
419 $this->permissionManager->userCan(
$action, $this->user, $this->title,
true ) );
420 $this->assertEquals( $check[
$action][3],
421 $this->permissionManager->userCan(
$action, $this->user, $this->title,
422 PermissionManager::RIGOR_QUICK ) );
423 # count( User::getGroupsWithPermissions( $action ) ) < 1
430 if ( $result2 ===
null ) {
436 $res = $this->permissionManager
442 $res = $this->permissionManager
444 $this->assertEquals( $result2,
$res );
448 $res = $this->permissionManager
450 $this->assertEquals( $result2,
$res );
454 $res = $this->permissionManager
456 $this->assertEquals( $result2,
$res );
466 $this->
setUser( $this->userName );
470 $this->assertEquals( [ [
'badaccess-group0' ], [
'ns-specialprotected' ] ],
471 $this->permissionManager
472 ->getPermissionErrors(
'bogus', $this->
user, $this->
title ) );
476 $this->assertEquals( [],
477 $this->permissionManager
478 ->getPermissionErrors(
'bogus', $this->
user, $this->
title ) );
482 $this->assertEquals( [ [
'badaccess-group0' ] ],
483 $this->permissionManager
484 ->getPermissionErrors(
'bogus', $this->
user, $this->
title ) );
486 $wgNamespaceProtection[
NS_USER] = [
'bogus' ];
490 $this->assertEquals( [ [
'badaccess-group0' ],
491 [
'namespaceprotected',
'User',
'bogus' ] ],
492 $this->permissionManager
493 ->getPermissionErrors(
'bogus', $this->
user, $this->
title ) );
497 $this->assertEquals( [ [
'protectedinterface',
'bogus' ] ],
498 $this->permissionManager
499 ->getPermissionErrors(
'bogus', $this->
user, $this->
title ) );
503 $this->assertEquals( [ [
'protectedinterface',
'bogus' ] ],
504 $this->permissionManager
505 ->getPermissionErrors(
'bogus', $this->
user, $this->
title ) );
507 $wgNamespaceProtection =
null;
510 $this->assertEquals( [],
511 $this->permissionManager
512 ->getPermissionErrors(
'bogus', $this->
user, $this->
title ) );
513 $this->assertEquals(
true,
514 $this->permissionManager->userCan(
'bogus', $this->user, $this->title ) );
517 $this->assertEquals( [ [
'badaccess-group0' ] ],
518 $this->permissionManager
519 ->getPermissionErrors(
'bogus', $this->
user, $this->
title ) );
520 $this->assertEquals(
false,
521 $this->permissionManager->userCan(
'bogus', $this->user, $this->title ) );
530 $this->
setUser( $this->userName );
534 [ [
'badaccess-group0' ], [
'mycustomjsprotected',
'bogus' ] ],
536 [ [
'badaccess-group0' ], [
'mycustomjsprotected',
'bogus' ] ],
537 [ [
'badaccess-group0' ], [
'mycustomjsprotected',
'bogus' ] ],
538 [ [
'badaccess-group0' ] ],
540 [ [
'badaccess-group0' ], [
'mycustomjsprotected',
'bogus' ] ],
541 [ [
'badaccess-group0' ], [
'mycustomjsprotected',
'bogus' ] ],
542 [ [
'badaccess-group0' ] ],
543 [ [
'badaccess-groups' ] ]
555 $this->
setUser( $this->userName );
559 [ [
'badaccess-group0' ], [
'mycustomjsonprotected',
'bogus' ] ],
561 [ [
'badaccess-group0' ], [
'mycustomjsonprotected',
'bogus' ] ],
562 [ [
'badaccess-group0' ] ],
563 [ [
'badaccess-group0' ], [
'mycustomjsonprotected',
'bogus' ] ],
565 [ [
'badaccess-group0' ], [
'mycustomjsonprotected',
'bogus' ] ],
566 [ [
'badaccess-group0' ] ],
567 [ [
'badaccess-group0' ], [
'mycustomjsonprotected',
'bogus' ] ],
568 [ [
'badaccess-groups' ] ]
578 $this->
setUser( $this->userName );
582 [ [
'badaccess-group0' ], [
'mycustomcssprotected',
'bogus' ] ],
584 [ [
'badaccess-group0' ] ],
585 [ [
'badaccess-group0' ], [
'mycustomcssprotected',
'bogus' ] ],
586 [ [
'badaccess-group0' ], [
'mycustomcssprotected',
'bogus' ] ],
588 [ [
'badaccess-group0' ] ],
589 [ [
'badaccess-group0' ], [
'mycustomcssprotected',
'bogus' ] ],
590 [ [
'badaccess-group0' ], [
'mycustomcssprotected',
'bogus' ] ],
591 [ [
'badaccess-groups' ] ]
601 $this->
setUser( $this->userName );
605 [ [
'badaccess-group0' ], [
'customjsprotected',
'bogus' ] ],
607 [ [
'badaccess-group0' ], [
'customjsprotected',
'bogus' ] ],
608 [ [
'badaccess-group0' ], [
'customjsprotected',
'bogus' ] ],
609 [ [
'badaccess-group0' ], [
'customjsprotected',
'bogus' ] ],
611 [ [
'badaccess-group0' ], [
'customjsprotected',
'bogus' ] ],
612 [ [
'badaccess-group0' ], [
'customjsprotected',
'bogus' ] ],
613 [ [
'badaccess-group0' ] ],
614 [ [
'badaccess-groups' ] ]
624 $this->
setUser( $this->userName );
628 [ [
'badaccess-group0' ], [
'customjsonprotected',
'bogus' ] ],
630 [ [
'badaccess-group0' ], [
'customjsonprotected',
'bogus' ] ],
631 [ [
'badaccess-group0' ], [
'customjsonprotected',
'bogus' ] ],
632 [ [
'badaccess-group0' ], [
'customjsonprotected',
'bogus' ] ],
634 [ [
'badaccess-group0' ], [
'customjsonprotected',
'bogus' ] ],
635 [ [
'badaccess-group0' ] ],
636 [ [
'badaccess-group0' ], [
'customjsonprotected',
'bogus' ] ],
637 [ [
'badaccess-groups' ] ]
647 $this->
setUser( $this->userName );
651 [ [
'badaccess-group0' ], [
'customcssprotected',
'bogus' ] ],
653 [ [
'badaccess-group0' ], [
'customcssprotected',
'bogus' ] ],
654 [ [
'badaccess-group0' ], [
'customcssprotected',
'bogus' ] ],
655 [ [
'badaccess-group0' ], [
'customcssprotected',
'bogus' ] ],
657 [ [
'badaccess-group0' ] ],
658 [ [
'badaccess-group0' ], [
'customcssprotected',
'bogus' ] ],
659 [ [
'badaccess-group0' ], [
'customcssprotected',
'bogus' ] ],
660 [ [
'badaccess-groups' ] ]
670 $this->
setUser( $this->userName );
674 [ [
'badaccess-group0' ] ],
676 [ [
'badaccess-group0' ] ],
677 [ [
'badaccess-group0' ] ],
678 [ [
'badaccess-group0' ] ],
680 [ [
'badaccess-group0' ] ],
681 [ [
'badaccess-group0' ] ],
682 [ [
'badaccess-group0' ] ],
683 [ [
'badaccess-groups' ] ]
695 [ [
'badaccess-group0' ] ],
697 [ [
'badaccess-group0' ] ],
698 [ [
'badaccess-group0' ] ],
699 [ [
'badaccess-group0' ] ],
701 [ [
'badaccess-group0' ] ],
702 [ [
'badaccess-group0' ] ],
703 [ [
'badaccess-group0' ] ],
704 [ [
'badaccess-groups' ] ]
719 $result = $this->permissionManager
720 ->getPermissionErrors(
'bogus', $this->
user, $this->
title );
721 $this->assertEquals( $resultNone,
$result );
724 $result = $this->permissionManager
725 ->getPermissionErrors(
'bogus', $this->
user, $this->
title );
726 $this->assertEquals( $resultMyCss,
$result );
729 $result = $this->permissionManager
730 ->getPermissionErrors(
'bogus', $this->
user, $this->
title );
731 $this->assertEquals( $resultMyJson,
$result );
734 $result = $this->permissionManager
735 ->getPermissionErrors(
'bogus', $this->
user, $this->
title );
736 $this->assertEquals( $resultMyJs,
$result );
739 $result = $this->permissionManager
740 ->getPermissionErrors(
'bogus', $this->
user, $this->
title );
741 $this->assertEquals( $resultUserCss,
$result );
744 $result = $this->permissionManager
745 ->getPermissionErrors(
'bogus', $this->
user, $this->
title );
746 $this->assertEquals( $resultUserJson,
$result );
749 $result = $this->permissionManager
750 ->getPermissionErrors(
'bogus', $this->
user, $this->
title );
751 $this->assertEquals( $resultUserJs,
$result );
754 $result = $this->permissionManager
755 ->getPermissionErrors(
'patrol', $this->
user, $this->
title );
756 $this->assertEquals( reset( $resultPatrol[0] ), reset(
$result[0] ) );
758 $this->
setUserPerm( [
'edituserjs',
'edituserjson',
'editusercss' ] );
759 $result = $this->permissionManager
760 ->getPermissionErrors(
'bogus', $this->
user, $this->
title );
761 $this->assertEquals( [ [
'badaccess-group0' ] ],
$result );
778 $this->
title->mRestrictionsLoaded =
true;
780 $this->
title->mRestrictions = [
"bogus" => [
'bogus',
"sysop",
"protect",
"" ] ];
782 $this->assertEquals( [],
783 $this->permissionManager->getPermissionErrors(
'edit',
784 $this->user, $this->title ) );
786 $this->assertEquals(
true,
787 $this->permissionManager->userCan(
'edit', $this->user, $this->title,
788 PermissionManager::RIGOR_QUICK ) );
790 $this->
title->mRestrictions = [
"edit" => [
'bogus',
"sysop",
"protect",
"" ],
791 "bogus" => [
'bogus',
"sysop",
"protect",
"" ] ];
793 $this->assertEquals( [ [
'badaccess-group0' ],
794 [
'protectedpagetext',
'bogus',
'bogus' ],
795 [
'protectedpagetext',
'editprotected',
'bogus' ],
796 [
'protectedpagetext',
'protect',
'bogus' ] ],
797 $this->permissionManager->getPermissionErrors(
'bogus',
798 $this->user, $this->title ) );
799 $this->assertEquals( [ [
'protectedpagetext',
'bogus',
'edit' ],
800 [
'protectedpagetext',
'editprotected',
'edit' ],
801 [
'protectedpagetext',
'protect',
'edit' ] ],
802 $this->permissionManager->getPermissionErrors(
'edit',
803 $this->user, $this->title ) );
805 $this->assertEquals( [ [
'badaccess-group0' ],
806 [
'protectedpagetext',
'bogus',
'bogus' ],
807 [
'protectedpagetext',
'editprotected',
'bogus' ],
808 [
'protectedpagetext',
'protect',
'bogus' ] ],
809 $this->permissionManager->getPermissionErrors(
'bogus',
810 $this->user, $this->title ) );
811 $this->assertEquals( [ [
'badaccess-groups',
"*, [[$prefix:Users|Users]]", 2 ],
812 [
'protectedpagetext',
'bogus',
'edit' ],
813 [
'protectedpagetext',
'editprotected',
'edit' ],
814 [
'protectedpagetext',
'protect',
'edit' ] ],
815 $this->permissionManager->getPermissionErrors(
'edit',
816 $this->user, $this->title ) );
818 $this->assertEquals( [ [
'badaccess-group0' ],
819 [
'protectedpagetext',
'bogus',
'bogus' ],
820 [
'protectedpagetext',
'protect',
'bogus' ] ],
821 $this->permissionManager->getPermissionErrors(
'bogus',
822 $this->user, $this->title ) );
823 $this->assertEquals( [
824 [
'protectedpagetext',
'bogus',
'edit' ],
825 [
'protectedpagetext',
'protect',
'edit' ] ],
826 $this->permissionManager->getPermissionErrors(
'edit',
827 $this->user, $this->title ) );
829 $this->
title->mCascadeRestriction =
true;
832 $this->assertEquals(
false,
833 $this->permissionManager->userCan(
'bogus', $this->user, $this->title,
834 PermissionManager::RIGOR_QUICK ) );
836 $this->assertEquals(
false,
837 $this->permissionManager->userCan(
'edit', $this->user, $this->title,
838 PermissionManager::RIGOR_QUICK ) );
840 $this->assertEquals( [ [
'badaccess-group0' ],
841 [
'protectedpagetext',
'bogus',
'bogus' ],
842 [
'protectedpagetext',
'editprotected',
'bogus' ],
843 [
'protectedpagetext',
'protect',
'bogus' ] ],
844 $this->permissionManager->getPermissionErrors(
'bogus',
845 $this->user, $this->title ) );
846 $this->assertEquals( [ [
'protectedpagetext',
'bogus',
'edit' ],
847 [
'protectedpagetext',
'editprotected',
'edit' ],
848 [
'protectedpagetext',
'protect',
'edit' ] ],
849 $this->permissionManager->getPermissionErrors(
'edit',
850 $this->user, $this->title ) );
853 $this->assertEquals(
false,
854 $this->permissionManager->userCan(
'bogus', $this->user, $this->title,
855 PermissionManager::RIGOR_QUICK ) );
857 $this->assertEquals(
false,
858 $this->permissionManager->userCan(
'edit', $this->user, $this->title,
859 PermissionManager::RIGOR_QUICK ) );
861 $this->assertEquals( [ [
'badaccess-group0' ],
862 [
'protectedpagetext',
'bogus',
'bogus' ],
863 [
'protectedpagetext',
'protect',
'bogus' ],
864 [
'protectedpagetext',
'protect',
'bogus' ] ],
865 $this->permissionManager->getPermissionErrors(
'bogus',
866 $this->user, $this->title ) );
867 $this->assertEquals( [ [
'protectedpagetext',
'bogus',
'edit' ],
868 [
'protectedpagetext',
'protect',
'edit' ],
869 [
'protectedpagetext',
'protect',
'edit' ] ],
870 $this->permissionManager->getPermissionErrors(
'edit',
871 $this->user, $this->title ) );
881 $this->
title->mCascadeSources = [
885 $this->
title->mCascadingRestrictions = [
886 "bogus" => [
'bogus',
"sysop",
"protect",
"" ]
889 $this->assertEquals(
false,
890 $this->permissionManager->userCan(
'bogus', $this->user, $this->title ) );
891 $this->assertEquals( [
892 [
"cascadeprotected", 2,
"* [[:Bogus]]\n* [[:UnBogus]]\n",
'bogus' ],
893 [
"cascadeprotected", 2,
"* [[:Bogus]]\n* [[:UnBogus]]\n",
'bogus' ],
894 [
"cascadeprotected", 2,
"* [[:Bogus]]\n* [[:UnBogus]]\n",
'bogus' ] ],
895 $this->permissionManager->getPermissionErrors(
'bogus', $this->user, $this->title ) );
897 $this->assertEquals(
true,
898 $this->permissionManager->userCan(
'edit', $this->user, $this->title ) );
899 $this->assertEquals( [],
900 $this->permissionManager->getPermissionErrors(
'edit', $this->user, $this->title ) );
911 $this->
title->mTitleProtection[
'permission'] =
'';
912 $this->
title->mTitleProtection[
'user'] = $this->
user->getId();
913 $this->
title->mTitleProtection[
'expiry'] =
'infinity';
914 $this->
title->mTitleProtection[
'reason'] =
'test';
915 $this->
title->mCascadeRestriction =
false;
917 $this->assertEquals( [ [
'titleprotected',
'Useruser',
'test' ] ],
918 $this->permissionManager
919 ->getPermissionErrors(
'create', $this->
user, $this->
title ) );
920 $this->assertEquals(
false,
921 $this->permissionManager->userCan(
'create', $this->user, $this->title ) );
923 $this->
title->mTitleProtection[
'permission'] =
'editprotected';
925 $this->assertEquals( [ [
'titleprotected',
'Useruser',
'test' ] ],
926 $this->permissionManager
927 ->getPermissionErrors(
'create', $this->
user, $this->
title ) );
928 $this->assertEquals(
false,
929 $this->permissionManager->userCan(
'create', $this->user, $this->title ) );
931 $this->
setUserPerm( [
'createpage',
'editprotected' ] );
932 $this->assertEquals( [],
933 $this->permissionManager
934 ->getPermissionErrors(
'create', $this->
user, $this->
title ) );
935 $this->assertEquals(
true,
936 $this->permissionManager->userCan(
'create', $this->user, $this->title ) );
939 $this->assertEquals( [ [
'titleprotected',
'Useruser',
'test' ] ],
940 $this->permissionManager
941 ->getPermissionErrors(
'create', $this->
user, $this->
title ) );
942 $this->assertEquals(
false,
943 $this->permissionManager->userCan(
'create', $this->user, $this->title ) );
947 $this->assertEquals(
false,
948 $this->permissionManager->userCan(
'move', $this->user, $this->title ) );
949 $this->assertEquals( [ [
'immobile-source-namespace',
'Media' ] ],
950 $this->permissionManager
951 ->getPermissionErrors(
'move', $this->
user, $this->
title ) );
954 $this->assertEquals( [],
955 $this->permissionManager
956 ->getPermissionErrors(
'move', $this->
user, $this->
title ) );
957 $this->assertEquals(
true,
958 $this->permissionManager->userCan(
'move', $this->user, $this->title ) );
960 $this->
title->mInterwiki =
"no";
961 $this->assertEquals( [ [
'immobile-source-page' ] ],
962 $this->permissionManager
963 ->getPermissionErrors(
'move', $this->
user, $this->
title ) );
964 $this->assertEquals(
false,
965 $this->permissionManager->userCan(
'move', $this->user, $this->title ) );
968 $this->assertEquals(
false,
969 $this->permissionManager->userCan(
'move-target', $this->user, $this->title ) );
970 $this->assertEquals( [ [
'immobile-target-namespace',
'Media' ] ],
971 $this->permissionManager
972 ->getPermissionErrors(
'move-target', $this->
user, $this->
title ) );
975 $this->assertEquals( [],
976 $this->permissionManager
977 ->getPermissionErrors(
'move-target', $this->
user, $this->
title ) );
978 $this->assertEquals(
true,
979 $this->permissionManager->userCan(
'move-target', $this->user, $this->title ) );
981 $this->
title->mInterwiki =
"no";
982 $this->assertEquals( [ [
'immobile-target-page' ] ],
983 $this->permissionManager
984 ->getPermissionErrors(
'move-target', $this->
user, $this->
title ) );
985 $this->assertEquals(
false,
986 $this->permissionManager->userCan(
'move-target', $this->user, $this->title ) );
994 'wgEmailConfirmToEdit' =>
true,
995 'wgEmailAuthentication' =>
true,
1012 # $wgEmailConfirmToEdit only applies to 'edit' action
1013 $this->assertEquals( [],
1014 $this->permissionManager->getPermissionErrors(
'move-target',
1015 $this->user, $this->title ) );
1016 $this->assertContains( [
'confirmedittext' ],
1017 $this->permissionManager
1018 ->getPermissionErrors(
'edit', $this->
user, $this->
title ) );
1024 $this->assertNotContains( [
'confirmedittext' ],
1025 $this->permissionManager
1026 ->getPermissionErrors(
'edit', $this->
user, $this->
title ) );
1028 # $wgEmailConfirmToEdit && !$user->isEmailConfirmed() && $action != 'createaccount'
1029 $this->assertEquals( [],
1030 $this->permissionManager->getPermissionErrors(
'move-target',
1031 $this->user, $this->title ) );
1035 $now = time() + 120;
1036 $this->
user->mBlockedby = $this->
user->getId();
1038 'address' =>
'127.0.8.1',
1039 'by' => $this->
user->getId(),
1040 'reason' =>
'no reason given',
1041 'timestamp' => $prev + 3600,
1045 $this->
user->mBlock->mTimestamp = 0;
1046 $this->assertEquals( [ [
'autoblockedtext',
1047 '[[User:Useruser|Useruser]]',
'no reason given',
'127.0.0.1',
1048 'Useruser',
null,
'infinite',
'127.0.8.1',
1050 $this->permissionManager->getPermissionErrors(
'move-target',
1053 $this->assertEquals(
false, $this->permissionManager
1054 ->userCan(
'move-target', $this->
user, $this->
title ) );
1056 $this->assertEquals(
true, $this->permissionManager
1057 ->userCan(
'move-target', $this->
user, $this->
title,
1058 PermissionManager::RIGOR_QUICK ) );
1062 $this->
user->mBlockedby = $this->
user->getName();
1064 'address' =>
'127.0.8.1',
1065 'by' => $this->
user->getId(),
1066 'reason' =>
'no reason given',
1067 'timestamp' => $now,
1071 $this->assertEquals( [ [
'blockedtext',
1072 '[[User:Useruser|Useruser]]',
'no reason given',
'127.0.0.1',
1073 'Useruser',
null,
'23:00, 31 December 1969',
'127.0.8.1',
1075 $this->permissionManager
1076 ->getPermissionErrors(
'move-target', $this->
user, $this->
title ) );
1077 # $action != 'read' && $action != 'createaccount' && $user->isBlockedFrom( $this )
1078 # $user->blockedFor() == ''
1079 # $user->mBlock->mExpiry == 'infinity'
1081 $this->
user->mBlockedby = $this->
user->getName();
1083 'address' =>
'127.0.8.1',
1084 'by' => $this->
user->getId(),
1085 'reason' =>
'no reason given',
1086 'timestamp' => $now,
1089 'systemBlock' =>
'test',
1092 $errors = [ [
'systemblockedtext',
1093 '[[User:Useruser|Useruser]]',
'no reason given',
'127.0.0.1',
1094 'Useruser',
'test',
'23:00, 31 December 1969',
'127.0.8.1',
1097 $this->assertEquals( $errors,
1098 $this->permissionManager
1099 ->getPermissionErrors(
'edit', $this->
user, $this->
title ) );
1100 $this->assertEquals( $errors,
1101 $this->permissionManager
1102 ->getPermissionErrors(
'move-target', $this->
user, $this->
title ) );
1103 $this->assertEquals( $errors,
1104 $this->permissionManager
1105 ->getPermissionErrors(
'rollback', $this->
user, $this->
title ) );
1106 $this->assertEquals( $errors,
1107 $this->permissionManager
1108 ->getPermissionErrors(
'patrol', $this->
user, $this->
title ) );
1109 $this->assertEquals( $errors,
1110 $this->permissionManager
1111 ->getPermissionErrors(
'upload', $this->
user, $this->
title ) );
1112 $this->assertEquals( [],
1113 $this->permissionManager
1114 ->getPermissionErrors(
'purge', $this->
user, $this->
title ) );
1117 $this->
user->mBlockedby = $this->
user->getName();
1119 'address' =>
'127.0.8.1',
1120 'by' => $this->
user->getId(),
1121 'reason' =>
'no reason given',
1122 'timestamp' => $now,
1123 'sitewide' =>
false,
1127 $this->assertEquals( [],
1128 $this->permissionManager
1129 ->getPermissionErrors(
'edit', $this->
user, $this->
title ) );
1130 $this->assertEquals( [],
1131 $this->permissionManager
1132 ->getPermissionErrors(
'move-target', $this->
user, $this->
title ) );
1133 $this->assertEquals( [],
1134 $this->permissionManager
1135 ->getPermissionErrors(
'rollback', $this->
user, $this->
title ) );
1136 $this->assertEquals( [],
1137 $this->permissionManager
1138 ->getPermissionErrors(
'patrol', $this->
user, $this->
title ) );
1139 $this->assertEquals( [],
1140 $this->permissionManager
1141 ->getPermissionErrors(
'upload', $this->
user, $this->
title ) );
1142 $this->assertEquals( [],
1143 $this->permissionManager
1144 ->getPermissionErrors(
'purge', $this->
user, $this->
title ) );
1146 $this->
user->mBlock->setRestrictions( [
1150 $errors = [ [
'blockedtext-partial',
1151 '[[User:Useruser|Useruser]]',
'no reason given',
'127.0.0.1',
1152 'Useruser',
null,
'23:00, 31 December 1969',
'127.0.8.1',
1155 $this->assertEquals( $errors,
1156 $this->permissionManager
1157 ->getPermissionErrors(
'edit', $this->
user, $this->
title ) );
1158 $this->assertEquals( $errors,
1159 $this->permissionManager
1160 ->getPermissionErrors(
'move-target', $this->
user, $this->
title ) );
1161 $this->assertEquals( $errors,
1162 $this->permissionManager
1163 ->getPermissionErrors(
'rollback', $this->
user, $this->
title ) );
1164 $this->assertEquals( $errors,
1165 $this->permissionManager
1166 ->getPermissionErrors(
'patrol', $this->
user, $this->
title ) );
1167 $this->assertEquals( [],
1168 $this->permissionManager
1169 ->getPermissionErrors(
'upload', $this->
user, $this->
title ) );
1170 $this->assertEquals( [],
1171 $this->permissionManager
1172 ->getPermissionErrors(
'purge', $this->
user, $this->
title ) );
1175 $this->
user->mBlockedby =
null;
1176 $this->
user->mBlock =
null;
1178 $this->assertEquals( [],
1179 $this->permissionManager
1180 ->getPermissionErrors(
'edit', $this->
user, $this->
title ) );
1193 ->disableOriginalConstructor()
1195 $tester->method(
'getName' )
1196 ->willReturn(
'tester' );
1197 $tester->method(
'getRestriction' )
1198 ->willReturn(
'test' );
1199 $tester->method(
'requiresUnblock' )
1200 ->willReturn(
false );
1204 'tester' => $tester,
1206 'wgGroupPermissions' => [
1214 $this->
user->mBlockedby = $this->
user->getName();
1216 'address' =>
'127.0.8.1',
1217 'by' => $this->
user->getId(),
1218 'reason' =>
'no reason given',
1219 'timestamp' => $now,
1221 'expiry' =>
'infinity',
1224 $errors = [ [
'blockedtext',
1225 '[[User:Useruser|Useruser]]',
'no reason given',
'127.0.0.1',
1226 'Useruser',
null,
'infinite',
'127.0.8.1',
1229 $this->assertEquals( $errors,
1230 $this->permissionManager
1231 ->getPermissionErrors(
'tester', $this->
user, $this->
title ) );
1241 $this->assertNull(
$user->
getBlock(
false ),
'sanity check' );
1245 $this->assertFalse( $this->permissionManager
1246 ->isBlockedFrom(
$user, $ut ),
'sanity check' );
1250 $block =
new Block( [
1252 'allowUsertalk' =>
false,
1253 'reason' =>
'Because',
1255 $block->setTarget(
$user );
1256 $block->setBlocker( $blocker );
1257 $res = $block->insert();
1258 $this->assertTrue( (
bool)
$res[
'id'],
'sanity check: Failed to insert block' );
1266 $this->assertTrue( $this->permissionManager->isBlockedFrom(
$user, $ut ) );
1277 $this->assertFalse( $this->permissionManager->isBlockedFrom(
$user, $ut ) );
1292 'wgBlockAllowsUTEdit' =>
$options[
'blockAllowsUTEdit'] ??
true,
1297 if (
$title === self::USER_TALK_PAGE ) {
1304 foreach (
$options[
'pageRestrictions'] ?? []
as $pagestr ) {
1310 foreach (
$options[
'namespaceRestrictions'] ?? []
as $ns ) {
1314 $block =
new Block( [
1316 'allowUsertalk' =>
$options[
'allowUsertalk'] ??
false,
1317 'sitewide' => !$restrictions,
1319 $block->setTarget(
$user );
1320 $block->setBlocker( $this->
getTestSysop()->getUser() );
1321 if ( $restrictions ) {
1322 $block->setRestrictions( $restrictions );
1327 $this->assertSame( $expect, $this->permissionManager->isBlockedFrom(
$user,
$title ) );
1335 'Sitewide block, basic operation' => [
'Test page',
true ],
1336 'Sitewide block, not allowing user talk' => [
1338 'allowUsertalk' =>
false,
1341 'Sitewide block, allowing user talk' => [
1343 'allowUsertalk' =>
true,
1346 'Sitewide block, allowing user talk but $wgBlockAllowsUTEdit is false' => [
1348 'allowUsertalk' =>
true,
1349 'blockAllowsUTEdit' =>
false,
1352 'Partial block, blocking the page' => [
1353 'Test page',
true, [
1354 'pageRestrictions' => [
'Test page' ],
1357 'Partial block, not blocking the page' => [
1358 'Test page 2',
false, [
1359 'pageRestrictions' => [
'Test page' ],
1362 'Partial block, not allowing user talk but user talk page is not blocked' => [
1364 'allowUsertalk' =>
false,
1365 'pageRestrictions' => [
'Test page' ],
1368 'Partial block, allowing user talk but user talk page is blocked' => [
1370 'allowUsertalk' =>
true,
1374 'Partial block, user talk page is not blocked but $wgBlockAllowsUTEdit is false' => [
1376 'allowUsertalk' =>
false,
1377 'pageRestrictions' => [
'Test page' ],
1378 'blockAllowsUTEdit' =>
false,
1381 'Partial block, user talk page is blocked and $wgBlockAllowsUTEdit is false' => [
1383 'allowUsertalk' =>
true,
1385 'blockAllowsUTEdit' =>
false,
1388 'Partial user talk namespace block, not allowing user talk' => [
1390 'allowUsertalk' =>
false,
1394 'Partial user talk namespace block, allowing user talk' => [
1396 'allowUsertalk' =>
true,
1400 'Partial user talk namespace block, where $wgBlockAllowsUTEdit is false' => [
1402 'allowUsertalk' =>
true,
1404 'blockAllowsUTEdit' =>
false,