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 ) ) {
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 );
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
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',
522 $this->assertEquals( [ [
'badaccess-group0' ] ],
523 $this->
title->getUserPermissionsErrors(
'bogus',
526 $this->
setUserPerm( [
'edituserjs',
'editusercss' ] );
527 $this->assertEquals( [ [
'badaccess-group0' ] ],
528 $this->
title->getUserPermissionsErrors(
'bogus',
542 $this->
title->mRestrictionsLoaded =
true;
544 $this->
title->mRestrictions = [
"bogus" => [
'bogus',
"sysop",
"protect",
"" ] ];
546 $this->assertEquals( [],
547 $this->
title->getUserPermissionsErrors(
'edit',
550 $this->assertEquals(
true,
551 $this->
title->quickUserCan(
'edit', $this->user ) );
552 $this->
title->mRestrictions = [
"edit" => [
'bogus',
"sysop",
"protect",
"" ],
553 "bogus" => [
'bogus',
"sysop",
"protect",
"" ] ];
555 $this->assertEquals( [ [
'badaccess-group0' ],
556 [
'protectedpagetext',
'bogus',
'bogus' ],
557 [
'protectedpagetext',
'editprotected',
'bogus' ],
558 [
'protectedpagetext',
'protect',
'bogus' ] ],
559 $this->
title->getUserPermissionsErrors(
'bogus',
561 $this->assertEquals( [ [
'protectedpagetext',
'bogus',
'edit' ],
562 [
'protectedpagetext',
'editprotected',
'edit' ],
563 [
'protectedpagetext',
'protect',
'edit' ] ],
564 $this->
title->getUserPermissionsErrors(
'edit',
567 $this->assertEquals( [ [
'badaccess-group0' ],
568 [
'protectedpagetext',
'bogus',
'bogus' ],
569 [
'protectedpagetext',
'editprotected',
'bogus' ],
570 [
'protectedpagetext',
'protect',
'bogus' ] ],
571 $this->
title->getUserPermissionsErrors(
'bogus',
573 $this->assertEquals( [ [
'badaccess-groups',
"*, [[$prefix:Users|Users]]", 2 ],
574 [
'protectedpagetext',
'bogus',
'edit' ],
575 [
'protectedpagetext',
'editprotected',
'edit' ],
576 [
'protectedpagetext',
'protect',
'edit' ] ],
577 $this->
title->getUserPermissionsErrors(
'edit',
580 $this->assertEquals( [ [
'badaccess-group0' ],
581 [
'protectedpagetext',
'bogus',
'bogus' ],
582 [
'protectedpagetext',
'protect',
'bogus' ] ],
583 $this->
title->getUserPermissionsErrors(
'bogus',
585 $this->assertEquals( [
586 [
'protectedpagetext',
'bogus',
'edit' ],
587 [
'protectedpagetext',
'protect',
'edit' ] ],
588 $this->
title->getUserPermissionsErrors(
'edit',
591 $this->
title->mCascadeRestriction =
true;
593 $this->assertEquals(
false,
594 $this->
title->quickUserCan(
'bogus', $this->user ) );
595 $this->assertEquals(
false,
596 $this->
title->quickUserCan(
'edit', $this->user ) );
597 $this->assertEquals( [ [
'badaccess-group0' ],
598 [
'protectedpagetext',
'bogus',
'bogus' ],
599 [
'protectedpagetext',
'editprotected',
'bogus' ],
600 [
'protectedpagetext',
'protect',
'bogus' ] ],
601 $this->
title->getUserPermissionsErrors(
'bogus',
603 $this->assertEquals( [ [
'protectedpagetext',
'bogus',
'edit' ],
604 [
'protectedpagetext',
'editprotected',
'edit' ],
605 [
'protectedpagetext',
'protect',
'edit' ] ],
606 $this->
title->getUserPermissionsErrors(
'edit',
610 $this->assertEquals(
false,
611 $this->
title->quickUserCan(
'bogus', $this->user ) );
612 $this->assertEquals(
false,
613 $this->
title->quickUserCan(
'edit', $this->user ) );
614 $this->assertEquals( [ [
'badaccess-group0' ],
615 [
'protectedpagetext',
'bogus',
'bogus' ],
616 [
'protectedpagetext',
'protect',
'bogus' ],
617 [
'protectedpagetext',
'protect',
'bogus' ] ],
618 $this->
title->getUserPermissionsErrors(
'bogus',
620 $this->assertEquals( [ [
'protectedpagetext',
'bogus',
'edit' ],
621 [
'protectedpagetext',
'protect',
'edit' ],
622 [
'protectedpagetext',
'protect',
'edit' ] ],
623 $this->
title->getUserPermissionsErrors(
'edit',
660 $this->
title->mTitleProtection[
'permission'] =
'';
661 $this->
title->mTitleProtection[
'user'] = $this->
user->getId();
662 $this->
title->mTitleProtection[
'expiry'] =
'infinity';
663 $this->
title->mTitleProtection[
'reason'] =
'test';
664 $this->
title->mCascadeRestriction =
false;
666 $this->assertEquals( [ [
'titleprotected',
'Useruser',
'test' ] ],
667 $this->
title->getUserPermissionsErrors(
'create', $this->user ) );
668 $this->assertEquals(
false,
669 $this->
title->userCan(
'create', $this->user ) );
671 $this->
title->mTitleProtection[
'permission'] =
'editprotected';
673 $this->assertEquals( [ [
'titleprotected',
'Useruser',
'test' ] ],
674 $this->
title->getUserPermissionsErrors(
'create', $this->user ) );
675 $this->assertEquals(
false,
676 $this->
title->userCan(
'create', $this->user ) );
678 $this->
setUserPerm( [
'createpage',
'editprotected' ] );
679 $this->assertEquals( [],
680 $this->
title->getUserPermissionsErrors(
'create', $this->user ) );
681 $this->assertEquals(
true,
682 $this->
title->userCan(
'create', $this->user ) );
685 $this->assertEquals( [ [
'titleprotected',
'Useruser',
'test' ] ],
686 $this->
title->getUserPermissionsErrors(
'create', $this->user ) );
687 $this->assertEquals(
false,
688 $this->
title->userCan(
'create', $this->user ) );
692 $this->assertEquals(
false,
693 $this->
title->userCan(
'move', $this->user ) );
694 $this->assertEquals( [ [
'immobile-source-namespace',
'Media' ] ],
695 $this->
title->getUserPermissionsErrors(
'move', $this->user ) );
698 $this->assertEquals( [],
699 $this->
title->getUserPermissionsErrors(
'move', $this->user ) );
700 $this->assertEquals(
true,
701 $this->
title->userCan(
'move', $this->user ) );
703 $this->
title->mInterwiki =
"no";
704 $this->assertEquals( [ [
'immobile-source-page' ] ],
705 $this->
title->getUserPermissionsErrors(
'move', $this->user ) );
706 $this->assertEquals(
false,
707 $this->
title->userCan(
'move', $this->user ) );
710 $this->assertEquals(
false,
711 $this->
title->userCan(
'move-target', $this->user ) );
712 $this->assertEquals( [ [
'immobile-target-namespace',
'Media' ] ],
713 $this->
title->getUserPermissionsErrors(
'move-target', $this->user ) );
716 $this->assertEquals( [],
717 $this->
title->getUserPermissionsErrors(
'move-target', $this->user ) );
718 $this->assertEquals(
true,
719 $this->
title->userCan(
'move-target', $this->user ) );
721 $this->
title->mInterwiki =
"no";
722 $this->assertEquals( [ [
'immobile-target-page' ] ],
723 $this->
title->getUserPermissionsErrors(
'move-target', $this->user ) );
724 $this->assertEquals(
false,
725 $this->
title->userCan(
'move-target', $this->user ) );