26 protected function setUp() {
31 $localOffset = date(
'Z' ) / 60;
35 'wgContLang' => $langObj,
36 'wgLanguageCode' =>
'en',
38 'wgLocaltimezone' => $localZone,
39 'wgLocalTZoffset' => $localOffset,
40 'wgNamespaceProtection' =>
array(
45 $this->userName =
'Useruser';
46 $this->altUserName =
'Altuseruser';
47 date_default_timezone_set( $localZone );
50 if ( !isset( $this->userUser ) || !( $this->userUser instanceof
User ) ) {
53 if ( !$this->userUser->getID() ) {
55 "email" =>
"test@example.com",
56 "real_name" =>
"Test User" ) );
57 $this->userUser->load();
61 if ( !$this->altUser->getID() ) {
63 "email" =>
"alttest@example.com",
64 "real_name" =>
"Test User Alt" ) );
65 $this->altUser->load();
77 if ( is_array( $perm ) ) {
78 $this->
user->mRights = $perm;
109 $res = $this->
title->getUserPermissionsErrors(
'create', $this->
user );
114 $res = $this->
title->getUserPermissionsErrors(
'create', $this->
user );
119 $res = $this->
title->getUserPermissionsErrors(
'create', $this->
user );
124 $res = $this->
title->getUserPermissionsErrors(
'create', $this->
user );
129 $res = $this->
title->getUserPermissionsErrors(
'create', $this->
user );
132 $this->
setUser( $this->userName );
135 $res = $this->
title->getUserPermissionsErrors(
'create', $this->
user );
140 $res = $this->
title->getUserPermissionsErrors(
'create', $this->
user );
141 $this->assertEquals(
array(
array(
'nocreate-loggedin' ) ),
$res );
145 $res = $this->
title->getUserPermissionsErrors(
'create', $this->
user );
146 $this->assertEquals(
array(
array(
'nocreate-loggedin' ) ),
$res );
150 $res = $this->
title->getUserPermissionsErrors(
'create', $this->
user );
155 $res = $this->
title->getUserPermissionsErrors(
'create', $this->
user );
156 $this->assertEquals(
array(
array(
'nocreate-loggedin' ) ),
$res );
160 $res = $this->
title->getUserPermissionsErrors(
'create', $this->
user );
161 $this->assertEquals(
array(
array(
'nocreate-loggedin' ) ),
$res );
166 $res = $this->
title->getUserPermissionsErrors(
'move', $this->
user );
167 $this->assertEquals(
array(
array(
'cant-move-user-page' ),
array(
'movenologintext' ) ),
$res );
171 $res = $this->
title->getUserPermissionsErrors(
'move', $this->
user );
176 $res = $this->
title->getUserPermissionsErrors(
'move', $this->
user );
181 $res = $this->
title->getUserPermissionsErrors(
'move', $this->
user );
186 $res = $this->
title->getUserPermissionsErrors(
'move', $this->
user );
187 $this->assertEquals(
array(
array(
'cant-move-user-page' ),
array(
'movenologintext' ) ),
$res );
191 $res = $this->
title->getUserPermissionsErrors(
'move', $this->
user );
196 $res = $this->
title->getUserPermissionsErrors(
'move', $this->
user );
201 $res = $this->
title->getUserPermissionsErrors(
'move', $this->
user );
204 $this->
setUser( $this->userName );
207 $res = $this->
title->getUserPermissionsErrors(
'move', $this->
user );
208 $this->assertEquals(
array(
array(
'movenotallowedfile' ),
array(
'movenotallowed' ) ),
$res );
212 $res = $this->
title->getUserPermissionsErrors(
'move', $this->
user );
218 $res = $this->
title->getUserPermissionsErrors(
'move', $this->
user );
219 $this->assertEquals(
array(
array(
'movenotallowedfile' ),
array(
'movenologintext' ) ),
$res );
223 $res = $this->
title->getUserPermissionsErrors(
'move', $this->
user );
226 $this->
setUser( $this->userName );
254 $this->
setUser( $this->userName );
263 $res = $this->
title->getUserPermissionsErrors(
'move-target', $this->
user );
267 $res = $this->
title->getUserPermissionsErrors(
'move-target', $this->
user );
272 $this->
setUser( $this->userName );
274 $res = $this->
title->getUserPermissionsErrors(
'move-target', $this->
user );
278 $res = $this->
title->getUserPermissionsErrors(
'move-target', $this->
user );
279 $this->assertEquals(
array(
array(
'cant-move-to-user-page' ) ),
$res );
283 $res = $this->
title->getUserPermissionsErrors(
'move-target', $this->
user );
288 $res = $this->
title->getUserPermissionsErrors(
'move-target', $this->
user );
292 $res = $this->
title->getUserPermissionsErrors(
'move-target', $this->
user );
296 $check =
array(
'edit' =>
array(
array(
array(
'badaccess-groups',
"*, [[$prefix:Users|Users]]", 2 ) ),
299 'protect' =>
array(
array(
array(
'badaccess-groups',
"[[$prefix:Administrators|Administrators]]", 1 ),
array(
'protect-cantedit' ) ),
301 array(
array(
'protect-cantedit' ) ),
false ),
304 foreach (
array(
"edit",
"protect",
"" )
as $action ) {
306 $this->assertEquals( $check[$action][0],
307 $this->
title->getUserPermissionsErrors( $action, $this->user,
true ) );
309 global $wgGroupPermissions;
310 $old = $wgGroupPermissions;
311 $wgGroupPermissions =
array();
313 $this->assertEquals( $check[$action][1],
314 $this->
title->getUserPermissionsErrors( $action, $this->user,
true ) );
315 $wgGroupPermissions = $old;
318 $this->assertEquals( $check[$action][2],
319 $this->
title->getUserPermissionsErrors( $action, $this->user,
true ) );
322 $this->assertEquals( $check[$action][3],
323 $this->
title->userCan( $action, $this->user,
true ) );
324 $this->assertEquals( $check[$action][3],
325 $this->
title->quickUserCan( $action, $this->user ) );
326 # count( User::getGroupsWithPermissions( $action ) ) < 1
331 global $wgGroupPermissions;
333 if ( $result2 ===
null ) {
337 $wgGroupPermissions[
'autoconfirmed'][
'move'] =
false;
338 $wgGroupPermissions[
'user'][
'move'] =
false;
339 $res = $this->
title->getUserPermissionsErrors( $action, $this->
user );
342 $wgGroupPermissions[
'autoconfirmed'][
'move'] =
true;
343 $wgGroupPermissions[
'user'][
'move'] =
false;
344 $res = $this->
title->getUserPermissionsErrors( $action, $this->
user );
345 $this->assertEquals( $result2,
$res );
347 $wgGroupPermissions[
'autoconfirmed'][
'move'] =
true;
348 $wgGroupPermissions[
'user'][
'move'] =
true;
349 $res = $this->
title->getUserPermissionsErrors( $action, $this->
user );
350 $this->assertEquals( $result2,
$res );
352 $wgGroupPermissions[
'autoconfirmed'][
'move'] =
false;
353 $wgGroupPermissions[
'user'][
'move'] =
true;
354 $res = $this->
title->getUserPermissionsErrors( $action, $this->
user );
355 $this->assertEquals( $result2,
$res );
364 $this->
setUser( $this->userName );
368 $this->assertEquals(
array(
array(
'badaccess-group0' ),
array(
'ns-specialprotected' ) ),
369 $this->
title->getUserPermissionsErrors(
'bogus', $this->user ) );
373 $this->assertEquals(
array(),
374 $this->
title->getUserPermissionsErrors(
'bogus', $this->user ) );
378 $this->assertEquals(
array(
array(
'badaccess-group0' ) ),
379 $this->
title->getUserPermissionsErrors(
'bogus', $this->user ) );
385 $this->assertEquals(
array(
array(
'badaccess-group0' ),
array(
'namespaceprotected',
'User' ) ),
386 $this->
title->getUserPermissionsErrors(
'bogus', $this->user ) );
390 $this->assertEquals(
array(
array(
'protectedinterface' ) ),
391 $this->
title->getUserPermissionsErrors(
'bogus', $this->user ) );
395 $this->assertEquals(
array(
array(
'protectedinterface' ) ),
396 $this->
title->getUserPermissionsErrors(
'bogus', $this->user ) );
401 $this->assertEquals(
array(),
402 $this->
title->getUserPermissionsErrors(
'bogus', $this->user ) );
403 $this->assertEquals(
true,
404 $this->
title->userCan(
'bogus', $this->user ) );
407 $this->assertEquals(
array(
array(
'badaccess-group0' ) ),
408 $this->
title->getUserPermissionsErrors(
'bogus', $this->user ) );
409 $this->assertEquals(
false,
410 $this->
title->userCan(
'bogus', $this->user ) );
418 $this->
setUser( $this->userName );
468 $this->assertEquals( $result0,
469 $this->
title->getUserPermissionsErrors(
'bogus',
473 $this->assertEquals( $result1,
474 $this->
title->getUserPermissionsErrors(
'bogus',
478 $this->assertEquals( $result2,
479 $this->
title->getUserPermissionsErrors(
'bogus',
483 $this->assertEquals( $result3,
484 $this->
title->getUserPermissionsErrors(
'bogus',
488 $this->assertEquals( $result4,
489 $this->
title->getUserPermissionsErrors(
'bogus',
493 $this->assertEquals(
array(
array(
'badaccess-group0' ) ),
494 $this->
title->getUserPermissionsErrors(
'bogus',
498 $this->assertEquals(
array(
array(
'badaccess-group0' ) ),
499 $this->
title->getUserPermissionsErrors(
'bogus',
513 $this->
title->mRestrictionsLoaded =
true;
515 $this->
title->mRestrictions =
array(
"bogus" =>
array(
'bogus',
"sysop",
"protect",
"" ) );
517 $this->assertEquals(
array(),
518 $this->
title->getUserPermissionsErrors(
'edit',
521 $this->assertEquals(
true,
522 $this->
title->quickUserCan(
'edit', $this->user ) );
523 $this->
title->mRestrictions =
array(
"edit" =>
array(
'bogus',
"sysop",
"protect",
"" ),
524 "bogus" =>
array(
'bogus',
"sysop",
"protect",
"" ) );
526 $this->assertEquals(
array(
array(
'badaccess-group0' ),
527 array(
'protectedpagetext',
'bogus' ),
528 array(
'protectedpagetext',
'editprotected' ),
529 array(
'protectedpagetext',
'protect' ) ),
530 $this->
title->getUserPermissionsErrors(
'bogus',
532 $this->assertEquals(
array(
array(
'protectedpagetext',
'bogus' ),
533 array(
'protectedpagetext',
'editprotected' ),
534 array(
'protectedpagetext',
'protect' ) ),
535 $this->
title->getUserPermissionsErrors(
'edit',
538 $this->assertEquals(
array(
array(
'badaccess-group0' ),
539 array(
'protectedpagetext',
'bogus' ),
540 array(
'protectedpagetext',
'editprotected' ),
541 array(
'protectedpagetext',
'protect' ) ),
542 $this->
title->getUserPermissionsErrors(
'bogus',
544 $this->assertEquals(
array(
array(
'badaccess-groups',
"*, [[$prefix:Users|Users]]", 2 ),
545 array(
'protectedpagetext',
'bogus' ),
546 array(
'protectedpagetext',
'editprotected' ),
547 array(
'protectedpagetext',
'protect' ) ),
548 $this->
title->getUserPermissionsErrors(
'edit',
551 $this->assertEquals(
array(
array(
'badaccess-group0' ),
552 array(
'protectedpagetext',
'bogus' ),
553 array(
'protectedpagetext',
'protect' ) ),
554 $this->
title->getUserPermissionsErrors(
'bogus',
556 $this->assertEquals(
array(
557 array(
'protectedpagetext',
'bogus' ),
558 array(
'protectedpagetext',
'protect' ) ),
559 $this->
title->getUserPermissionsErrors(
'edit',
562 $this->
title->mCascadeRestriction =
true;
564 $this->assertEquals(
false,
565 $this->
title->quickUserCan(
'bogus', $this->user ) );
566 $this->assertEquals(
false,
567 $this->
title->quickUserCan(
'edit', $this->user ) );
568 $this->assertEquals(
array(
array(
'badaccess-group0' ),
569 array(
'protectedpagetext',
'bogus' ),
570 array(
'protectedpagetext',
'editprotected' ),
571 array(
'protectedpagetext',
'protect' ) ),
572 $this->
title->getUserPermissionsErrors(
'bogus',
574 $this->assertEquals(
array(
array(
'protectedpagetext',
'bogus' ),
575 array(
'protectedpagetext',
'editprotected' ),
576 array(
'protectedpagetext',
'protect' ) ),
577 $this->
title->getUserPermissionsErrors(
'edit',
581 $this->assertEquals(
false,
582 $this->
title->quickUserCan(
'bogus', $this->user ) );
583 $this->assertEquals(
false,
584 $this->
title->quickUserCan(
'edit', $this->user ) );
585 $this->assertEquals(
array(
array(
'badaccess-group0' ),
586 array(
'protectedpagetext',
'bogus' ),
587 array(
'protectedpagetext',
'protect' ),
588 array(
'protectedpagetext',
'protect' ) ),
589 $this->
title->getUserPermissionsErrors(
'bogus',
591 $this->assertEquals(
array(
array(
'protectedpagetext',
'bogus' ),
592 array(
'protectedpagetext',
'protect' ),
593 array(
'protectedpagetext',
'protect' ) ),
594 $this->
title->getUserPermissionsErrors(
'edit',
603 $this->
title->mCascadingRestrictions =
array(
"bogus" =>
array(
'bogus',
"sysop",
"protect",
"" ) );
605 $this->assertEquals(
false,
606 $this->
title->userCan(
'bogus', $this->user ) );
607 $this->assertEquals(
array(
array(
"cascadeprotected", 2,
"* [[:Bogus]]\n* [[:UnBogus]]\n" ),
608 array(
"cascadeprotected", 2,
"* [[:Bogus]]\n* [[:UnBogus]]\n" ),
609 array(
"cascadeprotected", 2,
"* [[:Bogus]]\n* [[:UnBogus]]\n" ) ),
610 $this->
title->getUserPermissionsErrors(
'bogus', $this->user ) );
612 $this->assertEquals(
true,
613 $this->
title->userCan(
'edit', $this->user ) );
614 $this->assertEquals(
array(),
615 $this->
title->getUserPermissionsErrors(
'edit', $this->user ) );
625 $this->
title->mTitleProtection[
'pt_create_perm'] =
'';
626 $this->
title->mTitleProtection[
'pt_user'] = $this->
user->getID();
628 $this->
title->mTitleProtection[
'pt_reason'] =
'test';
629 $this->
title->mCascadeRestriction =
false;
631 $this->assertEquals(
array(
array(
'titleprotected',
'Useruser',
'test' ) ),
632 $this->
title->getUserPermissionsErrors(
'create', $this->user ) );
633 $this->assertEquals(
false,
634 $this->
title->userCan(
'create', $this->user ) );
636 $this->
title->mTitleProtection[
'pt_create_perm'] =
'sysop';
638 $this->assertEquals(
array(
array(
'titleprotected',
'Useruser',
'test' ) ),
639 $this->
title->getUserPermissionsErrors(
'create', $this->user ) );
640 $this->assertEquals(
false,
641 $this->
title->userCan(
'create', $this->user ) );
644 $this->assertEquals(
array(),
645 $this->
title->getUserPermissionsErrors(
'create', $this->user ) );
646 $this->assertEquals(
true,
647 $this->
title->userCan(
'create', $this->user ) );
650 $this->assertEquals(
array(
array(
'titleprotected',
'Useruser',
'test' ) ),
651 $this->
title->getUserPermissionsErrors(
'create', $this->user ) );
652 $this->assertEquals(
false,
653 $this->
title->userCan(
'create', $this->user ) );
657 $this->assertEquals(
false,
658 $this->
title->userCan(
'move', $this->user ) );
659 $this->assertEquals(
array(
array(
'immobile-source-namespace',
'Media' ) ),
660 $this->
title->getUserPermissionsErrors(
'move', $this->user ) );
663 $this->assertEquals(
array(),
664 $this->
title->getUserPermissionsErrors(
'move', $this->user ) );
665 $this->assertEquals(
true,
666 $this->
title->userCan(
'move', $this->user ) );
668 $this->
title->mInterwiki =
"no";
669 $this->assertEquals(
array(
array(
'immobile-source-page' ) ),
670 $this->
title->getUserPermissionsErrors(
'move', $this->user ) );
671 $this->assertEquals(
false,
672 $this->
title->userCan(
'move', $this->user ) );
675 $this->assertEquals(
false,
676 $this->
title->userCan(
'move-target', $this->user ) );
677 $this->assertEquals(
array(
array(
'immobile-target-namespace',
'Media' ) ),
678 $this->
title->getUserPermissionsErrors(
'move-target', $this->user ) );
681 $this->assertEquals(
array(),
682 $this->
title->getUserPermissionsErrors(
'move-target', $this->user ) );
683 $this->assertEquals(
true,
684 $this->
title->userCan(
'move-target', $this->user ) );
686 $this->
title->mInterwiki =
"no";
687 $this->assertEquals(
array(
array(
'immobile-target-page' ) ),
688 $this->
title->getUserPermissionsErrors(
'move-target', $this->user ) );
689 $this->assertEquals(
false,
690 $this->
title->userCan(
'move-target', $this->user ) );
694 global $wgEmailConfirmToEdit, $wgEmailAuthentication;
695 $wgEmailConfirmToEdit =
true;
696 $wgEmailAuthentication =
true;
702 $this->assertEquals(
array(
array(
'confirmedittext' ) ),
703 $this->
title->getUserPermissionsErrors(
'move-target', $this->user ) );
704 $wgEmailConfirmToEdit =
false;
705 $this->assertEquals(
true, $this->
title->userCan(
'move-target', $this->user ) );
707 # $wgEmailConfirmToEdit && !$user->isEmailConfirmed() && $action != 'createaccount'
708 $this->assertEquals(
array(),
709 $this->
title->getUserPermissionsErrors(
'move-target',
715 $this->
user->mBlockedby = $this->
user->getId();
716 $this->
user->mBlock =
new Block(
'127.0.8.1', 0, $this->
user->getId(),
717 'no reason given', $prev + 3600, 1, 0 );
718 $this->
user->mBlock->mTimestamp = 0;
719 $this->assertEquals(
array(
array(
'autoblockedtext',
720 '[[User:Useruser|Useruser]]',
'no reason given',
'127.0.0.1',
721 'Useruser',
null,
'infinite',
'127.0.8.1',
723 $this->
title->getUserPermissionsErrors(
'move-target',
726 $this->assertEquals(
false, $this->
title->userCan(
'move-target', $this->user ) );
728 $this->assertEquals(
true, $this->
title->quickUserCan(
'move-target', $this->user ) );
731 $wgLocalTZoffset = -60;
732 $this->
user->mBlockedby = $this->
user->getName();
733 $this->
user->mBlock =
new Block(
'127.0.8.1', 0, $this->
user->getId(),
734 'no reason given', $now, 0, 10 );
735 $this->assertEquals(
array(
array(
'blockedtext',
736 '[[User:Useruser|Useruser]]',
'no reason given',
'127.0.0.1',
737 'Useruser',
null,
'23:00, 31 December 1969',
'127.0.8.1',
739 $this->
title->getUserPermissionsErrors(
'move-target', $this->
user ) );
740 # $action != 'read' && $action != 'createaccount' && $user->isBlockedFrom( $this )
741 # $user->blockedFor() == ''
742 # $user->mBlock->mExpiry == 'infinity'