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