30 $localOffset = date(
'Z' ) / 60;
33 'wgLocaltimezone' => $localZone,
34 'wgLocalTZoffset' => $localOffset,
35 'wgNamespaceProtection' => [
36 NS_MEDIAWIKI =>
'editinterface',
43 $this->userName =
'Useruser';
44 $this->altUserName =
'Altuseruser';
45 date_default_timezone_set( $localZone );
47 $this->title = Title::makeTitle(
NS_MAIN,
"Main Page" );
48 if ( !isset( $this->userUser ) || !( $this->userUser instanceof
User ) ) {
49 $this->userUser = User::newFromName( $this->userName );
51 if ( !$this->userUser->getId() ) {
52 $this->userUser = User::createNew( $this->userName, [
53 "email" =>
"test@example.com",
54 "real_name" =>
"Test User" ] );
55 $this->userUser->load();
58 $this->altUser = User::newFromName( $this->altUserName );
59 if ( !$this->altUser->getId() ) {
60 $this->altUser = User::createNew( $this->altUserName, [
61 "email" =>
"alttest@example.com",
62 "real_name" =>
"Test User Alt" ] );
63 $this->altUser->load();
66 $this->anonUser = User::newFromId( 0 );
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 );
162 $this->
setTitle( NS_USER, $this->userName .
'' );
164 $res = $this->title->getUserPermissionsErrors(
'move', $this->user );
165 $this->assertEquals( [ [
'cant-move-user-page' ], [
'movenologintext' ] ],
$res );
167 $this->
setTitle( NS_USER, $this->userName .
'/subpage' );
169 $res = $this->title->getUserPermissionsErrors(
'move', $this->user );
170 $this->assertEquals( [ [
'movenologintext' ] ],
$res );
172 $this->
setTitle( NS_USER, $this->userName .
'' );
174 $res = $this->title->getUserPermissionsErrors(
'move', $this->user );
175 $this->assertEquals( [ [
'movenologintext' ] ],
$res );
177 $this->
setTitle( NS_USER, $this->userName .
'/subpage' );
179 $res = $this->title->getUserPermissionsErrors(
'move', $this->user );
180 $this->assertEquals( [ [
'movenologintext' ] ],
$res );
182 $this->
setTitle( NS_USER, $this->userName .
'' );
184 $res = $this->title->getUserPermissionsErrors(
'move', $this->user );
185 $this->assertEquals( [ [
'cant-move-user-page' ], [
'movenologintext' ] ],
$res );
187 $this->
setTitle( NS_USER, $this->userName .
'/subpage' );
189 $res = $this->title->getUserPermissionsErrors(
'move', $this->user );
190 $this->assertEquals( [ [
'movenologintext' ] ],
$res );
192 $this->
setTitle( NS_USER, $this->userName .
'' );
194 $res = $this->title->getUserPermissionsErrors(
'move', $this->user );
195 $this->assertEquals( [ [
'movenologintext' ] ],
$res );
197 $this->
setTitle( NS_USER, $this->userName .
'/subpage' );
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 );
290 $this->
setTitle( NS_USER,
"User/subpage" );
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
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',
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 ) );
725 'wgEmailConfirmToEdit' =>
true,
726 'wgEmailAuthentication' =>
true,
732 # $wgEmailConfirmToEdit only applies to 'edit' action
733 $this->assertEquals( [],
734 $this->title->getUserPermissionsErrors(
'move-target', $this->user ) );
735 $this->assertContains( [
'confirmedittext' ],
736 $this->title->getUserPermissionsErrors(
'edit', $this->user ) );
739 $this->assertNotContains( [
'confirmedittext' ],
740 $this->title->getUserPermissionsErrors(
'edit', $this->user ) );
742 # $wgEmailConfirmToEdit && !$user->isEmailConfirmed() && $action != 'createaccount'
743 $this->assertEquals( [],
744 $this->title->getUserPermissionsErrors(
'move-target',
750 $this->user->mBlockedby = $this->user->getId();
751 $this->user->mBlock =
new Block( [
752 'address' =>
'127.0.8.1',
753 'by' => $this->user->getId(),
754 'reason' =>
'no reason given',
755 'timestamp' => $prev + 3600,
759 $this->user->mBlock->mTimestamp = 0;
760 $this->assertEquals( [ [
'autoblockedtext',
761 '[[User:Useruser|Useruser]]',
'no reason given',
'127.0.0.1',
762 'Useruser',
null,
'infinite',
'127.0.8.1',
764 $this->title->getUserPermissionsErrors(
'move-target',
767 $this->assertEquals(
false, $this->title->userCan(
'move-target', $this->user ) );
769 $this->assertEquals(
true, $this->title->quickUserCan(
'move-target', $this->user ) );
773 $this->user->mBlockedby = $this->user->getName();
774 $this->user->mBlock =
new Block( [
775 'address' =>
'127.0.8.1',
776 'by' => $this->user->getId(),
777 'reason' =>
'no reason given',
782 $this->assertEquals( [ [
'blockedtext',
783 '[[User:Useruser|Useruser]]',
'no reason given',
'127.0.0.1',
784 'Useruser',
null,
'23:00, 31 December 1969',
'127.0.8.1',
786 $this->title->getUserPermissionsErrors(
'move-target', $this->user ) );
787 # $action != 'read' && $action != 'createaccount' && $user->isBlockedFrom( $this )
788 # $user->blockedFor() == ''
789 # $user->mBlock->mExpiry == 'infinity'
791 $this->user->mBlockedby = $this->user->getName();
792 $this->user->mBlock =
new Block( [
793 'address' =>
'127.0.8.1',
794 'by' => $this->user->getId(),
795 'reason' =>
'no reason given',
799 'systemBlock' =>
'test',
801 $this->assertEquals( [ [
'systemblockedtext',
802 '[[User:Useruser|Useruser]]',
'no reason given',
'127.0.0.1',
803 'Useruser',
'test',
'23:00, 31 December 1969',
'127.0.8.1',
805 $this->title->getUserPermissionsErrors(
'move-target', $this->user ) );