MediaWiki  REL1_21
TitlePermissionTest.php
Go to the documentation of this file.
00001 <?php
00002 
00006 class TitlePermissionTest extends MediaWikiLangTestCase {
00007 
00011         protected $userName, $altUserName;
00012 
00016         protected $title;
00017 
00021         protected $user, $anonUser, $userUser, $altUser;
00022 
00023         protected function setUp() {
00024                 parent::setUp();
00025 
00026                 $langObj = Language::factory( 'en' );
00027                 $localZone = 'UTC';
00028                 $localOffset = date( 'Z' ) / 60;
00029 
00030                 $this->setMwGlobals( array(
00031                         'wgMemc' => new EmptyBagOStuff,
00032                         'wgContLang' => $langObj,
00033                         'wgLanguageCode' => 'en',
00034                         'wgLang' => $langObj,
00035                         'wgLocaltimezone' => $localZone,
00036                         'wgLocalTZoffset' => $localOffset,
00037                         'wgNamespaceProtection' => array(
00038                                 NS_MEDIAWIKI => 'editinterface',
00039                         ),
00040                 ) );
00041 
00042                 $this->userName = 'Useruser';
00043                 $this->altUserName = 'Altuseruser';
00044                 date_default_timezone_set( $localZone );
00045 
00046                 $this->title = Title::makeTitle( NS_MAIN, "Main Page" );
00047                 if ( !isset( $this->userUser ) || !( $this->userUser instanceOf User ) ) {
00048                         $this->userUser = User::newFromName( $this->userName );
00049 
00050                         if ( !$this->userUser->getID() ) {
00051                                 $this->userUser = User::createNew( $this->userName, array(
00052                                         "email" => "[email protected]",
00053                                         "real_name" => "Test User" ) );
00054                                 $this->userUser->load();
00055                         }
00056 
00057                         $this->altUser = User::newFromName( $this->altUserName );
00058                         if ( !$this->altUser->getID() ) {
00059                                 $this->altUser = User::createNew( $this->altUserName, array(
00060                                         "email" => "[email protected]",
00061                                         "real_name" => "Test User Alt" ) );
00062                                 $this->altUser->load();
00063                         }
00064 
00065                         $this->anonUser = User::newFromId( 0 );
00066 
00067                         $this->user = $this->userUser;
00068                 }
00069 
00070         }
00071 
00072         function setUserPerm( $perm ) {
00073                 // Setting member variables is evil!!!
00074 
00075                 if ( is_array( $perm ) ) {
00076                         $this->user->mRights = $perm;
00077                 } else {
00078                         $this->user->mRights = array( $perm );
00079                 }
00080         }
00081 
00082         function setTitle( $ns, $title = "Main_Page" ) {
00083                 $this->title = Title::makeTitle( $ns, $title );
00084         }
00085 
00086         function setUser( $userName = null ) {
00087                 if ( $userName === 'anon' ) {
00088                         $this->user = $this->anonUser;
00089                 } elseif ( $userName === null || $userName === $this->userName ) {
00090                         $this->user = $this->userUser;
00091                 } else {
00092                         $this->user = $this->altUser;
00093                 }
00094         }
00095 
00096         function testQuickPermissions() {
00097                 global $wgContLang;
00098                 $prefix = $wgContLang->getFormattedNsText( NS_PROJECT );
00099 
00100                 $this->setUser( 'anon' );
00101                 $this->setTitle( NS_TALK );
00102                 $this->setUserPerm( "createtalk" );
00103                 $res = $this->title->getUserPermissionsErrors( 'create', $this->user );
00104                 $this->assertEquals( array(), $res );
00105 
00106                 $this->setTitle( NS_TALK );
00107                 $this->setUserPerm( "createpage" );
00108                 $res = $this->title->getUserPermissionsErrors( 'create', $this->user );
00109                 $this->assertEquals( array( array( "nocreatetext" ) ), $res );
00110 
00111                 $this->setTitle( NS_TALK );
00112                 $this->setUserPerm( "" );
00113                 $res = $this->title->getUserPermissionsErrors( 'create', $this->user );
00114                 $this->assertEquals( array( array( 'nocreatetext' ) ), $res );
00115 
00116                 $this->setTitle( NS_MAIN );
00117                 $this->setUserPerm( "createpage" );
00118                 $res = $this->title->getUserPermissionsErrors( 'create', $this->user );
00119                 $this->assertEquals( array(), $res );
00120 
00121                 $this->setTitle( NS_MAIN );
00122                 $this->setUserPerm( "createtalk" );
00123                 $res = $this->title->getUserPermissionsErrors( 'create', $this->user );
00124                 $this->assertEquals( array( array( 'nocreatetext' ) ), $res );
00125 
00126                 $this->setUser( $this->userName );
00127                 $this->setTitle( NS_TALK );
00128                 $this->setUserPerm( "createtalk" );
00129                 $res = $this->title->getUserPermissionsErrors( 'create', $this->user );
00130                 $this->assertEquals( array(), $res );
00131 
00132                 $this->setTitle( NS_TALK );
00133                 $this->setUserPerm( "createpage" );
00134                 $res = $this->title->getUserPermissionsErrors( 'create', $this->user );
00135                 $this->assertEquals( array( array( 'nocreate-loggedin' ) ), $res );
00136 
00137                 $this->setTitle( NS_TALK );
00138                 $this->setUserPerm( "" );
00139                 $res = $this->title->getUserPermissionsErrors( 'create', $this->user );
00140                 $this->assertEquals( array( array( 'nocreate-loggedin' ) ), $res );
00141 
00142                 $this->setTitle( NS_MAIN );
00143                 $this->setUserPerm( "createpage" );
00144                 $res = $this->title->getUserPermissionsErrors( 'create', $this->user );
00145                 $this->assertEquals( array(), $res );
00146 
00147                 $this->setTitle( NS_MAIN );
00148                 $this->setUserPerm( "createtalk" );
00149                 $res = $this->title->getUserPermissionsErrors( 'create', $this->user );
00150                 $this->assertEquals( array( array( 'nocreate-loggedin' ) ), $res );
00151 
00152                 $this->setTitle( NS_MAIN );
00153                 $this->setUserPerm( "" );
00154                 $res = $this->title->getUserPermissionsErrors( 'create', $this->user );
00155                 $this->assertEquals( array( array( 'nocreate-loggedin' ) ), $res );
00156 
00157                 $this->setUser( 'anon' );
00158                 $this->setTitle( NS_USER, $this->userName . '' );
00159                 $this->setUserPerm( "" );
00160                 $res = $this->title->getUserPermissionsErrors( 'move', $this->user );
00161                 $this->assertEquals( array( array( 'cant-move-user-page' ), array( 'movenologintext' ) ), $res );
00162 
00163                 $this->setTitle( NS_USER, $this->userName . '/subpage' );
00164                 $this->setUserPerm( "" );
00165                 $res = $this->title->getUserPermissionsErrors( 'move', $this->user );
00166                 $this->assertEquals( array( array( 'movenologintext' ) ), $res );
00167 
00168                 $this->setTitle( NS_USER, $this->userName . '' );
00169                 $this->setUserPerm( "move-rootuserpages" );
00170                 $res = $this->title->getUserPermissionsErrors( 'move', $this->user );
00171                 $this->assertEquals( array( array( 'movenologintext' ) ), $res );
00172 
00173                 $this->setTitle( NS_USER, $this->userName . '/subpage' );
00174                 $this->setUserPerm( "move-rootuserpages" );
00175                 $res = $this->title->getUserPermissionsErrors( 'move', $this->user );
00176                 $this->assertEquals( array( array( 'movenologintext' ) ), $res );
00177 
00178                 $this->setTitle( NS_USER, $this->userName . '' );
00179                 $this->setUserPerm( "" );
00180                 $res = $this->title->getUserPermissionsErrors( 'move', $this->user );
00181                 $this->assertEquals( array( array( 'cant-move-user-page' ), array( 'movenologintext' ) ), $res );
00182 
00183                 $this->setTitle( NS_USER, $this->userName . '/subpage' );
00184                 $this->setUserPerm( "" );
00185                 $res = $this->title->getUserPermissionsErrors( 'move', $this->user );
00186                 $this->assertEquals( array( array( 'movenologintext' ) ), $res );
00187 
00188                 $this->setTitle( NS_USER, $this->userName . '' );
00189                 $this->setUserPerm( "move-rootuserpages" );
00190                 $res = $this->title->getUserPermissionsErrors( 'move', $this->user );
00191                 $this->assertEquals( array( array( 'movenologintext' ) ), $res );
00192 
00193                 $this->setTitle( NS_USER, $this->userName . '/subpage' );
00194                 $this->setUserPerm( "move-rootuserpages" );
00195                 $res = $this->title->getUserPermissionsErrors( 'move', $this->user );
00196                 $this->assertEquals( array( array( 'movenologintext' ) ), $res );
00197 
00198                 $this->setUser( $this->userName );
00199                 $this->setTitle( NS_FILE, "img.png" );
00200                 $this->setUserPerm( "" );
00201                 $res = $this->title->getUserPermissionsErrors( 'move', $this->user );
00202                 $this->assertEquals( array( array( 'movenotallowedfile' ), array( 'movenotallowed' ) ), $res );
00203 
00204                 $this->setTitle( NS_FILE, "img.png" );
00205                 $this->setUserPerm( "movefile" );
00206                 $res = $this->title->getUserPermissionsErrors( 'move', $this->user );
00207                 $this->assertEquals( array( array( 'movenotallowed' ) ), $res );
00208 
00209                 $this->setUser( 'anon' );
00210                 $this->setTitle( NS_FILE, "img.png" );
00211                 $this->setUserPerm( "" );
00212                 $res = $this->title->getUserPermissionsErrors( 'move', $this->user );
00213                 $this->assertEquals( array( array( 'movenotallowedfile' ), array( 'movenologintext' ) ), $res );
00214 
00215                 $this->setTitle( NS_FILE, "img.png" );
00216                 $this->setUserPerm( "movefile" );
00217                 $res = $this->title->getUserPermissionsErrors( 'move', $this->user );
00218                 $this->assertEquals( array( array( 'movenologintext' ) ), $res );
00219 
00220                 $this->setUser( $this->userName );
00221                 $this->setUserPerm( "move" );
00222                 $this->runGroupPermissions( 'move', array( array( 'movenotallowedfile' ) ) );
00223 
00224                 $this->setUserPerm( "" );
00225                 $this->runGroupPermissions( 'move', array( array( 'movenotallowedfile' ), array( 'movenotallowed' ) ) );
00226 
00227                 $this->setUser( 'anon' );
00228                 $this->setUserPerm( "move" );
00229                 $this->runGroupPermissions( 'move', array( array( 'movenotallowedfile' ) ) );
00230 
00231                 $this->setUserPerm( "" );
00232                 $this->runGroupPermissions( 'move', array( array( 'movenotallowedfile' ), array( 'movenotallowed' ) ),
00233                         array( array( 'movenotallowedfile' ), array( 'movenologintext' ) ) );
00234 
00235                 if ( $this->isWikitextNS( NS_MAIN ) ) {
00236                         //NOTE: some content models don't allow moving
00237                         //@todo: find a Wikitext namespace for testing
00238 
00239                         $this->setTitle( NS_MAIN );
00240                         $this->setUser( 'anon' );
00241                         $this->setUserPerm( "move" );
00242                         $this->runGroupPermissions( 'move', array() );
00243 
00244                         $this->setUserPerm( "" );
00245                         $this->runGroupPermissions( 'move', array( array( 'movenotallowed' ) ),
00246                                 array( array( 'movenologintext' ) ) );
00247 
00248                         $this->setUser( $this->userName );
00249                         $this->setUserPerm( "" );
00250                         $this->runGroupPermissions( 'move', array( array( 'movenotallowed' ) ) );
00251 
00252                         $this->setUserPerm( "move" );
00253                         $this->runGroupPermissions( 'move', array() );
00254 
00255                         $this->setUser( 'anon' );
00256                         $this->setUserPerm( 'move' );
00257                         $res = $this->title->getUserPermissionsErrors( 'move-target', $this->user );
00258                         $this->assertEquals( array(), $res );
00259 
00260                         $this->setUserPerm( '' );
00261                         $res = $this->title->getUserPermissionsErrors( 'move-target', $this->user );
00262                         $this->assertEquals( array( array( 'movenotallowed' ) ), $res );
00263                 }
00264 
00265                 $this->setTitle( NS_USER );
00266                 $this->setUser( $this->userName );
00267                 $this->setUserPerm( array( "move", "move-rootuserpages" ) );
00268                 $res = $this->title->getUserPermissionsErrors( 'move-target', $this->user );
00269                 $this->assertEquals( array(), $res );
00270 
00271                 $this->setUserPerm( "move" );
00272                 $res = $this->title->getUserPermissionsErrors( 'move-target', $this->user );
00273                 $this->assertEquals( array( array( 'cant-move-to-user-page' ) ), $res );
00274 
00275                 $this->setUser( 'anon' );
00276                 $this->setUserPerm( array( "move", "move-rootuserpages" ) );
00277                 $res = $this->title->getUserPermissionsErrors( 'move-target', $this->user );
00278                 $this->assertEquals( array(), $res );
00279 
00280                 $this->setTitle( NS_USER, "User/subpage" );
00281                 $this->setUserPerm( array( "move", "move-rootuserpages" ) );
00282                 $res = $this->title->getUserPermissionsErrors( 'move-target', $this->user );
00283                 $this->assertEquals( array(), $res );
00284 
00285                 $this->setUserPerm( "move" );
00286                 $res = $this->title->getUserPermissionsErrors( 'move-target', $this->user );
00287                 $this->assertEquals( array(), $res );
00288 
00289                 $this->setUser( 'anon' );
00290                 $check = array( 'edit' => array( array( array( 'badaccess-groups', "*, [[$prefix:Users|Users]]", 2 ) ),
00291                         array( array( 'badaccess-group0' ) ),
00292                         array(), true ),
00293                         'protect' => array( array( array( 'badaccess-groups', "[[$prefix:Administrators|Administrators]]", 1 ), array( 'protect-cantedit' ) ),
00294                                 array( array( 'badaccess-group0' ), array( 'protect-cantedit' ) ),
00295                                 array( array( 'protect-cantedit' ) ), false ),
00296                         '' => array( array(), array(), array(), true ) );
00297 
00298                 foreach ( array( "edit", "protect", "" ) as $action ) {
00299                         $this->setUserPerm( null );
00300                         $this->assertEquals( $check[$action][0],
00301                                 $this->title->getUserPermissionsErrors( $action, $this->user, true ) );
00302 
00303                         global $wgGroupPermissions;
00304                         $old = $wgGroupPermissions;
00305                         $wgGroupPermissions = array();
00306 
00307                         $this->assertEquals( $check[$action][1],
00308                                 $this->title->getUserPermissionsErrors( $action, $this->user, true ) );
00309                         $wgGroupPermissions = $old;
00310 
00311                         $this->setUserPerm( $action );
00312                         $this->assertEquals( $check[$action][2],
00313                                 $this->title->getUserPermissionsErrors( $action, $this->user, true ) );
00314 
00315                         $this->setUserPerm( $action );
00316                         $this->assertEquals( $check[$action][3],
00317                                 $this->title->userCan( $action, $this->user, true ) );
00318                         $this->assertEquals( $check[$action][3],
00319                                 $this->title->quickUserCan( $action, $this->user ) );
00320 
00321                         # count( User::getGroupsWithPermissions( $action ) ) < 1
00322                 }
00323         }
00324 
00325         function runGroupPermissions( $action, $result, $result2 = null ) {
00326                 global $wgGroupPermissions;
00327 
00328                 if ( $result2 === null ) {
00329                         $result2 = $result;
00330                 }
00331 
00332                 $wgGroupPermissions['autoconfirmed']['move'] = false;
00333                 $wgGroupPermissions['user']['move'] = false;
00334                 $res = $this->title->getUserPermissionsErrors( $action, $this->user );
00335                 $this->assertEquals( $result, $res );
00336 
00337                 $wgGroupPermissions['autoconfirmed']['move'] = true;
00338                 $wgGroupPermissions['user']['move'] = false;
00339                 $res = $this->title->getUserPermissionsErrors( $action, $this->user );
00340                 $this->assertEquals( $result2, $res );
00341 
00342                 $wgGroupPermissions['autoconfirmed']['move'] = true;
00343                 $wgGroupPermissions['user']['move'] = true;
00344                 $res = $this->title->getUserPermissionsErrors( $action, $this->user );
00345                 $this->assertEquals( $result2, $res );
00346 
00347                 $wgGroupPermissions['autoconfirmed']['move'] = false;
00348                 $wgGroupPermissions['user']['move'] = true;
00349                 $res = $this->title->getUserPermissionsErrors( $action, $this->user );
00350                 $this->assertEquals( $result2, $res );
00351         }
00352 
00353         function testSpecialsAndNSPermissions() {
00354                 global $wgNamespaceProtection;
00355                 $this->setUser( $this->userName );
00356 
00357                 $this->setTitle( NS_SPECIAL );
00358 
00359                 $this->assertEquals( array( array( 'badaccess-group0' ), array( 'ns-specialprotected' ) ),
00360                         $this->title->getUserPermissionsErrors( 'bogus', $this->user ) );
00361 
00362                 $this->setTitle( NS_MAIN );
00363                 $this->setUserPerm( 'bogus' );
00364                 $this->assertEquals( array(),
00365                         $this->title->getUserPermissionsErrors( 'bogus', $this->user ) );
00366 
00367                 $this->setTitle( NS_MAIN );
00368                 $this->setUserPerm( '' );
00369                 $this->assertEquals( array( array( 'badaccess-group0' ) ),
00370                         $this->title->getUserPermissionsErrors( 'bogus', $this->user ) );
00371 
00372                 $wgNamespaceProtection[NS_USER] = array( 'bogus' );
00373 
00374                 $this->setTitle( NS_USER );
00375                 $this->setUserPerm( '' );
00376                 $this->assertEquals( array( array( 'badaccess-group0' ), array( 'namespaceprotected', 'User' ) ),
00377                         $this->title->getUserPermissionsErrors( 'bogus', $this->user ) );
00378 
00379                 $this->setTitle( NS_MEDIAWIKI );
00380                 $this->setUserPerm( 'bogus' );
00381                 $this->assertEquals( array( array( 'protectedinterface' ) ),
00382                         $this->title->getUserPermissionsErrors( 'bogus', $this->user ) );
00383 
00384                 $this->setTitle( NS_MEDIAWIKI );
00385                 $this->setUserPerm( 'bogus' );
00386                 $this->assertEquals( array( array( 'protectedinterface' ) ),
00387                         $this->title->getUserPermissionsErrors( 'bogus', $this->user ) );
00388 
00389                 $wgNamespaceProtection = null;
00390 
00391                 $this->setUserPerm( 'bogus' );
00392                 $this->assertEquals( array(),
00393                         $this->title->getUserPermissionsErrors( 'bogus', $this->user ) );
00394                 $this->assertEquals( true,
00395                         $this->title->userCan( 'bogus', $this->user ) );
00396 
00397                 $this->setUserPerm( '' );
00398                 $this->assertEquals( array( array( 'badaccess-group0' ) ),
00399                         $this->title->getUserPermissionsErrors( 'bogus', $this->user ) );
00400                 $this->assertEquals( false,
00401                         $this->title->userCan( 'bogus', $this->user ) );
00402         }
00403 
00404         function testCssAndJavascriptPermissions() {
00405                 $this->setUser( $this->userName );
00406 
00407                 $this->setTitle( NS_USER, $this->altUserName . '/test.js' );
00408                 $this->runCSSandJSPermissions(
00409                         array( array( 'badaccess-group0' ), array( 'customjsprotected' ) ),
00410                         array( array( 'badaccess-group0' ), array( 'customjsprotected' ) ),
00411                         array( array( 'badaccess-group0' ) ) );
00412 
00413                 $this->setTitle( NS_USER, $this->altUserName . '/test.css' );
00414                 $this->runCSSandJSPermissions(
00415                         array( array( 'badaccess-group0' ), array( 'customcssprotected' ) ),
00416                         array( array( 'badaccess-group0' ) ),
00417                         array( array( 'badaccess-group0' ), array( 'customcssprotected' ) ) );
00418 
00419                 $this->setTitle( NS_USER, $this->altUserName . '/tempo' );
00420                 $this->runCSSandJSPermissions(
00421                         array( array( 'badaccess-group0' ) ),
00422                         array( array( 'badaccess-group0' ) ),
00423                         array( array( 'badaccess-group0' ) ) );
00424         }
00425 
00426         function runCSSandJSPermissions( $result0, $result1, $result2 ) {
00427                 $this->setUserPerm( '' );
00428                 $this->assertEquals( $result0,
00429                         $this->title->getUserPermissionsErrors( 'bogus',
00430                                 $this->user ) );
00431 
00432                 $this->setUserPerm( 'editusercss' );
00433                 $this->assertEquals( $result1,
00434                         $this->title->getUserPermissionsErrors( 'bogus',
00435                                 $this->user ) );
00436 
00437                 $this->setUserPerm( 'edituserjs' );
00438                 $this->assertEquals( $result2,
00439                         $this->title->getUserPermissionsErrors( 'bogus',
00440                                 $this->user ) );
00441 
00442                 $this->setUserPerm( 'editusercssjs' );
00443                 $this->assertEquals( array( array( 'badaccess-group0' ) ),
00444                         $this->title->getUserPermissionsErrors( 'bogus',
00445                                 $this->user ) );
00446 
00447                 $this->setUserPerm( array( 'edituserjs', 'editusercss' ) );
00448                 $this->assertEquals( array( array( 'badaccess-group0' ) ),
00449                         $this->title->getUserPermissionsErrors( 'bogus',
00450                                 $this->user ) );
00451         }
00452 
00453         function testPageRestrictions() {
00454                 global $wgContLang;
00455 
00456                 $prefix = $wgContLang->getFormattedNsText( NS_PROJECT );
00457 
00458                 $this->setTitle( NS_MAIN );
00459                 $this->title->mRestrictionsLoaded = true;
00460                 $this->setUserPerm( "edit" );
00461                 $this->title->mRestrictions = array( "bogus" => array( 'bogus', "sysop", "protect", "" ) );
00462 
00463                 $this->assertEquals( array(),
00464                         $this->title->getUserPermissionsErrors( 'edit',
00465                                 $this->user ) );
00466 
00467                 $this->assertEquals( true,
00468                         $this->title->quickUserCan( 'edit', $this->user ) );
00469                 $this->title->mRestrictions = array( "edit" => array( 'bogus', "sysop", "protect", "" ),
00470                         "bogus" => array( 'bogus', "sysop", "protect", "" ) );
00471 
00472                 $this->assertEquals( array( array( 'badaccess-group0' ),
00473                                 array( 'protectedpagetext', 'bogus' ),
00474                                 array( 'protectedpagetext', 'protect' ),
00475                                 array( 'protectedpagetext', 'protect' ) ),
00476                         $this->title->getUserPermissionsErrors( 'bogus',
00477                                 $this->user ) );
00478                 $this->assertEquals( array( array( 'protectedpagetext', 'bogus' ),
00479                                 array( 'protectedpagetext', 'protect' ),
00480                                 array( 'protectedpagetext', 'protect' ) ),
00481                         $this->title->getUserPermissionsErrors( 'edit',
00482                                 $this->user ) );
00483                 $this->setUserPerm( "" );
00484                 $this->assertEquals( array( array( 'badaccess-group0' ),
00485                                 array( 'protectedpagetext', 'bogus' ),
00486                                 array( 'protectedpagetext', 'protect' ),
00487                                 array( 'protectedpagetext', 'protect' ) ),
00488                         $this->title->getUserPermissionsErrors( 'bogus',
00489                                 $this->user ) );
00490                 $this->assertEquals( array( array( 'badaccess-groups', "*, [[$prefix:Users|Users]]", 2 ),
00491                                 array( 'protectedpagetext', 'bogus' ),
00492                                 array( 'protectedpagetext', 'protect' ),
00493                                 array( 'protectedpagetext', 'protect' ) ),
00494                         $this->title->getUserPermissionsErrors( 'edit',
00495                                 $this->user ) );
00496                 $this->setUserPerm( array( "edit", "editprotected" ) );
00497                 $this->assertEquals( array( array( 'badaccess-group0' ),
00498                                 array( 'protectedpagetext', 'bogus' ),
00499                                 array( 'protectedpagetext', 'protect' ),
00500                                 array( 'protectedpagetext', 'protect' ) ),
00501                         $this->title->getUserPermissionsErrors( 'bogus',
00502                                 $this->user ) );
00503                 $this->assertEquals( array(),
00504                         $this->title->getUserPermissionsErrors( 'edit',
00505                                 $this->user ) );
00506                 $this->title->mCascadeRestriction = true;
00507                 $this->assertEquals( false,
00508                         $this->title->quickUserCan( 'bogus', $this->user ) );
00509                 $this->assertEquals( false,
00510                         $this->title->quickUserCan( 'edit', $this->user ) );
00511                 $this->assertEquals( array( array( 'badaccess-group0' ),
00512                                 array( 'protectedpagetext', 'bogus' ),
00513                                 array( 'protectedpagetext', 'protect' ),
00514                                 array( 'protectedpagetext', 'protect' ) ),
00515                         $this->title->getUserPermissionsErrors( 'bogus',
00516                                 $this->user ) );
00517                 $this->assertEquals( array( array( 'protectedpagetext', 'bogus' ),
00518                                 array( 'protectedpagetext', 'protect' ),
00519                                 array( 'protectedpagetext', 'protect' ) ),
00520                         $this->title->getUserPermissionsErrors( 'edit',
00521                                 $this->user ) );
00522         }
00523 
00524         function testCascadingSourcesRestrictions() {
00525                 $this->setTitle( NS_MAIN, "test page" );
00526                 $this->setUserPerm( array( "edit", "bogus" ) );
00527 
00528                 $this->title->mCascadeSources = array( Title::makeTitle( NS_MAIN, "Bogus" ), Title::makeTitle( NS_MAIN, "UnBogus" ) );
00529                 $this->title->mCascadingRestrictions = array( "bogus" => array( 'bogus', "sysop", "protect", "" ) );
00530 
00531                 $this->assertEquals( false,
00532                         $this->title->userCan( 'bogus', $this->user ) );
00533                 $this->assertEquals( array( array( "cascadeprotected", 2, "* [[:Bogus]]\n* [[:UnBogus]]\n" ),
00534                                 array( "cascadeprotected", 2, "* [[:Bogus]]\n* [[:UnBogus]]\n" ) ),
00535                         $this->title->getUserPermissionsErrors( 'bogus', $this->user ) );
00536 
00537                 $this->assertEquals( true,
00538                         $this->title->userCan( 'edit', $this->user ) );
00539                 $this->assertEquals( array(),
00540                         $this->title->getUserPermissionsErrors( 'edit', $this->user ) );
00541 
00542         }
00543 
00544         function testActionPermissions() {
00545                 $this->setUserPerm( array( "createpage" ) );
00546                 $this->setTitle( NS_MAIN, "test page" );
00547                 $this->title->mTitleProtection['pt_create_perm'] = '';
00548                 $this->title->mTitleProtection['pt_user'] = $this->user->getID();
00549                 $this->title->mTitleProtection['pt_expiry'] = wfGetDB( DB_SLAVE )->getInfinity();
00550                 $this->title->mTitleProtection['pt_reason'] = 'test';
00551                 $this->title->mCascadeRestriction = false;
00552 
00553                 $this->assertEquals( array( array( 'titleprotected', 'Useruser', 'test' ) ),
00554                         $this->title->getUserPermissionsErrors( 'create', $this->user ) );
00555                 $this->assertEquals( false,
00556                         $this->title->userCan( 'create', $this->user ) );
00557 
00558                 $this->title->mTitleProtection['pt_create_perm'] = 'sysop';
00559                 $this->setUserPerm( array( 'createpage', 'protect' ) );
00560                 $this->assertEquals( array(),
00561                         $this->title->getUserPermissionsErrors( 'create', $this->user ) );
00562                 $this->assertEquals( true,
00563                         $this->title->userCan( 'create', $this->user ) );
00564 
00565 
00566                 $this->setUserPerm( array( 'createpage' ) );
00567                 $this->assertEquals( array( array( 'titleprotected', 'Useruser', 'test' ) ),
00568                         $this->title->getUserPermissionsErrors( 'create', $this->user ) );
00569                 $this->assertEquals( false,
00570                         $this->title->userCan( 'create', $this->user ) );
00571 
00572                 $this->setTitle( NS_MEDIA, "test page" );
00573                 $this->setUserPerm( array( "move" ) );
00574                 $this->assertEquals( false,
00575                         $this->title->userCan( 'move', $this->user ) );
00576                 $this->assertEquals( array( array( 'immobile-source-namespace', 'Media' ) ),
00577                         $this->title->getUserPermissionsErrors( 'move', $this->user ) );
00578 
00579                 $this->setTitle( NS_HELP, "test page" );
00580                 $this->assertEquals( array(),
00581                         $this->title->getUserPermissionsErrors( 'move', $this->user ) );
00582                 $this->assertEquals( true,
00583                         $this->title->userCan( 'move', $this->user ) );
00584 
00585                 $this->title->mInterwiki = "no";
00586                 $this->assertEquals( array( array( 'immobile-source-page' ) ),
00587                         $this->title->getUserPermissionsErrors( 'move', $this->user ) );
00588                 $this->assertEquals( false,
00589                         $this->title->userCan( 'move', $this->user ) );
00590 
00591                 $this->setTitle( NS_MEDIA, "test page" );
00592                 $this->assertEquals( false,
00593                         $this->title->userCan( 'move-target', $this->user ) );
00594                 $this->assertEquals( array( array( 'immobile-target-namespace', 'Media' ) ),
00595                         $this->title->getUserPermissionsErrors( 'move-target', $this->user ) );
00596 
00597                 $this->setTitle( NS_HELP, "test page" );
00598                 $this->assertEquals( array(),
00599                         $this->title->getUserPermissionsErrors( 'move-target', $this->user ) );
00600                 $this->assertEquals( true,
00601                         $this->title->userCan( 'move-target', $this->user ) );
00602 
00603                 $this->title->mInterwiki = "no";
00604                 $this->assertEquals( array( array( 'immobile-target-page' ) ),
00605                         $this->title->getUserPermissionsErrors( 'move-target', $this->user ) );
00606                 $this->assertEquals( false,
00607                         $this->title->userCan( 'move-target', $this->user ) );
00608 
00609         }
00610 
00611         function testUserBlock() {
00612                 global $wgEmailConfirmToEdit, $wgEmailAuthentication;
00613                 $wgEmailConfirmToEdit = true;
00614                 $wgEmailAuthentication = true;
00615 
00616                 $this->setUserPerm( array( "createpage", "move" ) );
00617                 $this->setTitle( NS_HELP, "test page" );
00618 
00619                 # $short
00620                 $this->assertEquals( array( array( 'confirmedittext' ) ),
00621                         $this->title->getUserPermissionsErrors( 'move-target', $this->user ) );
00622                 $wgEmailConfirmToEdit = false;
00623                 $this->assertEquals( true, $this->title->userCan( 'move-target', $this->user ) );
00624 
00625                 # $wgEmailConfirmToEdit && !$user->isEmailConfirmed() && $action != 'createaccount'
00626                 $this->assertEquals( array(),
00627                         $this->title->getUserPermissionsErrors( 'move-target',
00628                                 $this->user ) );
00629 
00630                 global $wgLang;
00631                 $prev = time();
00632                 $now = time() + 120;
00633                 $this->user->mBlockedby = $this->user->getId();
00634                 $this->user->mBlock = new Block( '127.0.8.1', 0, $this->user->getId(),
00635                         'no reason given', $prev + 3600, 1, 0 );
00636                 $this->user->mBlock->mTimestamp = 0;
00637                 $this->assertEquals( array( array( 'autoblockedtext',
00638                                 '[[User:Useruser|Useruser]]', 'no reason given', '127.0.0.1',
00639                                 'Useruser', null, 'infinite', '127.0.8.1',
00640                                 $wgLang->timeanddate( wfTimestamp( TS_MW, $prev ), true ) ) ),
00641                         $this->title->getUserPermissionsErrors( 'move-target',
00642                                 $this->user ) );
00643 
00644                 $this->assertEquals( false, $this->title->userCan( 'move-target', $this->user ) );
00645                 // quickUserCan should ignore user blocks
00646                 $this->assertEquals( true, $this->title->quickUserCan( 'move-target', $this->user ) );
00647 
00648                 global $wgLocalTZoffset;
00649                 $wgLocalTZoffset = -60;
00650                 $this->user->mBlockedby = $this->user->getName();
00651                 $this->user->mBlock = new Block( '127.0.8.1', 0, 1, 'no reason given', $now, 0, 10 );
00652                 $this->assertEquals( array( array( 'blockedtext',
00653                                 '[[User:Useruser|Useruser]]', 'no reason given', '127.0.0.1',
00654                                 'Useruser', null, '23:00, 31 December 1969', '127.0.8.1',
00655                                 $wgLang->timeanddate( wfTimestamp( TS_MW, $now ), true ) ) ),
00656                         $this->title->getUserPermissionsErrors( 'move-target', $this->user ) );
00657 
00658                 # $action != 'read' && $action != 'createaccount' && $user->isBlockedFrom( $this )
00659                 #   $user->blockedFor() == ''
00660                 #   $user->mBlock->mExpiry == 'infinity'
00661         }
00662 }