* @group Database
*/
class TitlePermissionTest extends MediaWikiLangTestCase {
+
+ /**
+ * @var string
+ */
+ protected $userName, $altUserName;
+
+ /**
+ * @var Title
+ */
protected $title;
- protected $user;
- protected $anonUser;
- protected $userUser;
- protected $altUser;
- protected $userName;
- protected $altUserName;
-
- function setUp() {
- global $wgLocaltimezone, $wgLocalTZoffset, $wgMemc, $wgContLang, $wgLang;
- parent::setUp();
- if(!$wgMemc) {
- $wgMemc = new EmptyBagOStuff;
- }
- $wgContLang = $wgLang = Language::factory( 'en' );
+ /**
+ * @var User
+ */
+ protected $user, $anonUser, $userUser, $altUser;
+
+ protected function setUp() {
+ parent::setUp();
- $this->userName = "Useruser";
- $this->altUserName = "Altuseruser";
- date_default_timezone_set( $wgLocaltimezone );
- $wgLocalTZoffset = date( "Z" ) / 60;
+ $langObj = Language::factory( 'en' );
+ $localZone = 'UTC';
+ $localOffset = date( 'Z' ) / 60;
+
+ $this->setMwGlobals( array(
+ 'wgMemc' => new EmptyBagOStuff,
+ 'wgContLang' => $langObj,
+ 'wgLang' => $langObj,
+ 'wgLocaltimezone' => $localZone,
+ 'wgLocalTZoffset' => $localOffset,
+ 'wgNamespaceProtection' => array(
+ NS_MEDIAWIKI => 'editinterface',
+ ),
+ 'wgUser' => null,
+ ) );
+
+ $this->userName = 'Useruser';
+ $this->altUserName = 'Altuseruser';
+ date_default_timezone_set( $localZone );
$this->title = Title::makeTitle( NS_MAIN, "Main Page" );
if ( !isset( $this->userUser ) || !( $this->userUser instanceOf User ) ) {
$this->user = $this->userUser;
}
- }
- function tearDown() {
- parent::tearDown();
}
function setUserPerm( $perm ) {
+ // Setting member variables is evil!!!
+
if ( is_array( $perm ) ) {
$this->user->mRights = $perm;
} else {
}
function setUser( $userName = null ) {
+ global $wgUser;
+
if ( $userName === 'anon' ) {
$this->user = $this->anonUser;
} elseif ( $userName === null || $userName === $this->userName ) {
$this->user = $this->altUser;
}
- global $wgUser;
$wgUser = $this->user;
}
$this->runGroupPermissions( 'move', array( array( 'movenotallowedfile' ), array( 'movenotallowed' ) ),
array( array( 'movenotallowedfile' ), array( 'movenologintext' ) ) );
- $this->setTitle( NS_MAIN );
- $this->setUser( 'anon' );
- $this->setUserPerm( "move" );
- $this->runGroupPermissions( 'move', array( ) );
+ if ( $this->isWikitextNS( NS_MAIN ) ) {
+ //NOTE: some content models don't allow moving
+ //@todo: find a Wikitext namespace for testing
- $this->setUserPerm( "" );
- $this->runGroupPermissions( 'move', array( array( 'movenotallowed' ) ),
- array( array( 'movenologintext' ) ) );
+ $this->setTitle( NS_MAIN );
+ $this->setUser( 'anon' );
+ $this->setUserPerm( "move" );
+ $this->runGroupPermissions( 'move', array( ) );
- $this->setUser( $this->userName );
- $this->setUserPerm( "" );
- $this->runGroupPermissions( 'move', array( array( 'movenotallowed' ) ) );
+ $this->setUserPerm( "" );
+ $this->runGroupPermissions( 'move', array( array( 'movenotallowed' ) ),
+ array( array( 'movenologintext' ) ) );
- $this->setUserPerm( "move" );
- $this->runGroupPermissions( 'move', array( ) );
+ $this->setUser( $this->userName );
+ $this->setUserPerm( "" );
+ $this->runGroupPermissions( 'move', array( array( 'movenotallowed' ) ) );
- $this->setUser( 'anon' );
- $this->setUserPerm( 'move' );
- $res = $this->title->getUserPermissionsErrors( 'move-target', $this->user );
- $this->assertEquals( array( ), $res );
+ $this->setUserPerm( "move" );
+ $this->runGroupPermissions( 'move', array( ) );
- $this->setUserPerm( '' );
- $res = $this->title->getUserPermissionsErrors( 'move-target', $this->user );
- $this->assertEquals( array( array( 'movenotallowed' ) ), $res );
+ $this->setUser( 'anon' );
+ $this->setUserPerm( 'move' );
+ $res = $this->title->getUserPermissionsErrors( 'move-target', $this->user );
+ $this->assertEquals( array( ), $res );
+
+ $this->setUserPerm( '' );
+ $res = $this->title->getUserPermissionsErrors( 'move-target', $this->user );
+ $this->assertEquals( array( array( 'movenotallowed' ) ), $res );
+ }
$this->setTitle( NS_USER );
$this->setUser( $this->userName );
$this->assertEquals( $check[$action][3],
$this->title->userCan( $action, true ) );
$this->assertEquals( $check[$action][3],
- $this->title->quickUserCan( $action, false ) );
+ $this->title->quickUserCan( $action ) );
# count( User::getGroupsWithPermissions( $action ) ) < 1
}
}
function testSpecialsAndNSPermissions() {
+ global $wgNamespaceProtection;
$this->setUser( $this->userName );
- global $wgUser;
- $wgUser = $this->user;
$this->setTitle( NS_SPECIAL );
$this->assertEquals( array( array( 'badaccess-group0' ) ),
$this->title->getUserPermissionsErrors( 'bogus', $this->user ) );
- global $wgNamespaceProtection;
- $wgNamespaceProtection[NS_USER] = array ( 'bogus' );
+ $wgNamespaceProtection[NS_USER] = array( 'bogus' );
+
$this->setTitle( NS_USER );
$this->setUserPerm( '' );
$this->assertEquals( array( array( 'badaccess-group0' ), array( 'namespaceprotected', 'User' ) ),
$this->title->getUserPermissionsErrors( 'bogus', $this->user ) );
$wgNamespaceProtection = null;
+
$this->setUserPerm( 'bogus' );
$this->assertEquals( array( ),
$this->title->getUserPermissionsErrors( 'bogus', $this->user ) );
$this->title->userCan( 'bogus' ) );
}
- function testCSSandJSPermissions() {
+ function testCssAndJavascriptPermissions() {
$this->setUser( $this->userName );
- global $wgUser;
- $wgUser = $this->user;
$this->setTitle( NS_USER, $this->altUserName . '/test.js' );
$this->runCSSandJSPermissions(
$this->user ) );
$this->assertEquals( true,
- $this->title->quickUserCan( 'edit', false ) );
+ $this->title->quickUserCan( 'edit' ) );
$this->title->mRestrictions = array( "edit" => array( 'bogus', "sysop", "protect", "" ),
"bogus" => array( 'bogus', "sysop", "protect", "" ) );
$this->user ) );
$this->title->mCascadeRestriction = true;
$this->assertEquals( false,
- $this->title->quickUserCan( 'bogus', false ) );
+ $this->title->quickUserCan( 'bogus' ) );
$this->assertEquals( false,
- $this->title->quickUserCan( 'edit', false ) );
+ $this->title->quickUserCan( 'edit' ) );
$this->assertEquals( array( array( 'badaccess-group0' ),
array( 'protectedpagetext', 'bogus' ),
array( 'protectedpagetext', 'protect' ),
$this->setTitle( NS_MAIN, "test page" );
$this->title->mTitleProtection['pt_create_perm'] = '';
$this->title->mTitleProtection['pt_user'] = $this->user->getID();
- $this->title->mTitleProtection['pt_expiry'] = Block::infinity();
+ $this->title->mTitleProtection['pt_expiry'] = wfGetDB( DB_SLAVE )->getInfinity();
$this->title->mTitleProtection['pt_reason'] = 'test';
$this->title->mCascadeRestriction = false;
$this->assertEquals( array( array( 'immobile-source-namespace', 'Media' ) ),
$this->title->getUserPermissionsErrors( 'move', $this->user ) );
- $this->setTitle( NS_MAIN, "test page" );
+ $this->setTitle( NS_HELP, "test page" );
$this->assertEquals( array( ),
$this->title->getUserPermissionsErrors( 'move', $this->user ) );
$this->assertEquals( true,
$this->title->userCan( 'move' ) );
$this->title->mInterwiki = "no";
- $this->assertEquals( array( array( 'immobile-page' ) ),
+ $this->assertEquals( array( array( 'immobile-source-page' ) ),
$this->title->getUserPermissionsErrors( 'move', $this->user ) );
$this->assertEquals( false,
$this->title->userCan( 'move' ) );
$this->assertEquals( array( array( 'immobile-target-namespace', 'Media' ) ),
$this->title->getUserPermissionsErrors( 'move-target', $this->user ) );
- $this->setTitle( NS_MAIN, "test page" );
+ $this->setTitle( NS_HELP, "test page" );
$this->assertEquals( array( ),
$this->title->getUserPermissionsErrors( 'move-target', $this->user ) );
$this->assertEquals( true,
$wgUser = $this->user;
$this->setUserPerm( array( "createpage", "move" ) );
- $this->setTitle( NS_MAIN, "test page" );
+ $this->setTitle( NS_HELP, "test page" );
# $short
$this->assertEquals( array( array( 'confirmedittext' ) ),
$prev = time();
$now = time() + 120;
$this->user->mBlockedby = $this->user->getId();
- $this->user->mBlock = new Block( '127.0.8.1', $this->user->getId(), $this->user->getId(),
+ $this->user->mBlock = new Block( '127.0.8.1', 0, $this->user->getId(),
'no reason given', $prev + 3600, 1, 0 );
$this->user->mBlock->mTimestamp = 0;
$this->assertEquals( array( array( 'autoblockedtext',
global $wgLocalTZoffset;
$wgLocalTZoffset = -60;
$this->user->mBlockedby = $this->user->getName();
- $this->user->mBlock = new Block( '127.0.8.1', 2, 1, 'no reason given', $now, 0, 10 );
+ $this->user->mBlock = new Block( '127.0.8.1', 0, 1, 'no reason given', $now, 0, 10 );
$this->assertEquals( array( array( 'blockedtext',
'[[User:Useruser|Useruser]]', 'no reason given', '127.0.0.1',
'Useruser', null, '23:00, 31 December 1969', '127.0.8.1',