* @group Database
*/
class TitlePermissionTest extends MediaWikiLangTestCase {
- protected $title;
/**
- * @var User
+ * @var string
*/
- protected $user, $anonUser, $userUser, $altUser;
+ protected $userName, $altUserName;
/**
- * @var string
+ * @var Title
*/
- protected $userName, $altUserName;
+ protected $title;
- function setUp() {
- global $wgLocaltimezone, $wgLocalTZoffset, $wgMemc, $wgContLang, $wgLang;
- parent::setUp();
+ /**
+ * @var User
+ */
+ protected $user, $anonUser, $userUser, $altUser;
- if(!$wgMemc) {
- $wgMemc = new EmptyBagOStuff;
- }
- $wgContLang = $wgLang = Language::factory( 'en' );
+ 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 ) {
}
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 );
}
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 ) );
function testCssAndJavascriptPermissions() {
$this->setUser( $this->userName );
- global $wgUser;
- $wgUser = $this->user;
$this->setTitle( NS_USER, $this->altUserName . '/test.js' );
$this->runCSSandJSPermissions(
$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->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',