Merge "define RC_EXTERNAL type for recent changes"
[lhc/web/wiklou.git] / tests / phpunit / includes / TitlePermissionTest.php
index 4c6ad92..f7387e1 100644 (file)
@@ -4,31 +4,44 @@
  * @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 ) ) {
@@ -53,10 +66,7 @@ class TitlePermissionTest extends MediaWikiLangTestCase {
 
                        $this->user = $this->userUser;
                }
-       }
 
-       function tearDown() {
-               parent::tearDown();
        }
 
        function setUserPerm( $perm ) {
@@ -74,6 +84,8 @@ class TitlePermissionTest extends MediaWikiLangTestCase {
        }
 
        function setUser( $userName = null ) {
+               global $wgUser;
+
                if ( $userName === 'anon' ) {
                        $this->user = $this->anonUser;
                } elseif ( $userName === null || $userName === $this->userName ) {
@@ -82,7 +94,6 @@ class TitlePermissionTest extends MediaWikiLangTestCase {
                        $this->user = $this->altUser;
                }
 
-               global $wgUser;
                $wgUser = $this->user;
        }
 
@@ -225,30 +236,35 @@ class TitlePermissionTest extends MediaWikiLangTestCase {
                $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 );
@@ -338,9 +354,8 @@ class TitlePermissionTest extends MediaWikiLangTestCase {
        }
 
        function testSpecialsAndNSPermissions() {
+               global $wgNamespaceProtection;
                $this->setUser( $this->userName );
-               global $wgUser;
-               $wgUser = $this->user;
 
                $this->setTitle( NS_SPECIAL );
 
@@ -359,8 +374,8 @@ class TitlePermissionTest extends MediaWikiLangTestCase {
                $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' ) ),
@@ -377,6 +392,7 @@ class TitlePermissionTest extends MediaWikiLangTestCase {
                                                         $this->title->getUserPermissionsErrors( 'bogus', $this->user ) );
 
                $wgNamespaceProtection = null;
+
                $this->setUserPerm( 'bogus' );
                $this->assertEquals( array( ),
                                                         $this->title->getUserPermissionsErrors( 'bogus', $this->user ) );
@@ -392,8 +408,6 @@ class TitlePermissionTest extends MediaWikiLangTestCase {
 
        function testCssAndJavascriptPermissions() {
                $this->setUser( $this->userName );
-               global $wgUser;
-               $wgUser = $this->user;
 
                $this->setTitle( NS_USER, $this->altUserName . '/test.js' );
                $this->runCSSandJSPermissions(
@@ -573,7 +587,7 @@ class TitlePermissionTest extends MediaWikiLangTestCase {
                $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,
@@ -591,7 +605,7 @@ class TitlePermissionTest extends MediaWikiLangTestCase {
                $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,
@@ -612,7 +626,7 @@ class TitlePermissionTest extends MediaWikiLangTestCase {
                $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' ) ),
@@ -629,7 +643,7 @@ class TitlePermissionTest extends MediaWikiLangTestCase {
                $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',
@@ -646,7 +660,7 @@ class TitlePermissionTest extends MediaWikiLangTestCase {
                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',