Merge "(Bug 41352) Provide tests for edit conflicts."
[lhc/web/wiklou.git] / tests / phpunit / includes / TitleTest.php
index c74daae..8647954 100644 (file)
@@ -1,7 +1,25 @@
 <?php
 
+/**
+ *
+ * @group Database
+ *        ^--- needed for language cache stuff
+ */
 class TitleTest extends MediaWikiTestCase {
 
+       protected function setUp() {
+               parent::setUp();
+
+               $this->setMwGlobals( array(
+                       'wgLanguageCode' => 'en',
+                       'wgContLang' => Language::factory( 'en' ),
+                       // User language
+                       'wgLang' => Language::factory( 'en' ),
+                       'wgAllowUserJs' => false,
+                       'wgDefaultLanguageVariant' => false,
+               ) );
+       }
+
        function testLegalChars() {
                $titlechars = Title::legalChars();
 
@@ -16,7 +34,7 @@ class TitleTest extends MediaWikiTestCase {
        }
 
        /**
-        * @dataProvider dataBug31100
+        * @dataProvider provideBug31100
         */
        function testBug31100FixSpecialName( $text, $expectedParam ) {
                $title = Title::newFromText( $text );
@@ -30,7 +48,7 @@ class TitleTest extends MediaWikiTestCase {
                $this->assertEquals( $expectedParam, $par, "Bug 31100 regression check: Title->fixSpecialName() should preserve parameter" );
        }
 
-       function dataBug31100() {
+       public static function provideBug31100() {
                return array(
                        array( 'Special:Version', null ),
                        array( 'Special:Version/', '' ),
@@ -45,7 +63,7 @@ class TitleTest extends MediaWikiTestCase {
         * @param string $source
         * @param string $target
         * @param array|string|true $expected Required error
-        * @dataProvider dataTestIsValidMoveOperation
+        * @dataProvider provideTestIsValidMoveOperation
         */
        function testIsValidMoveOperation( $source, $target, $expected ) {
                $title = Title::newFromText( $source );
@@ -69,7 +87,7 @@ class TitleTest extends MediaWikiTestCase {
                return $result;
        }
        
-       function dataTestIsValidMoveOperation() {
+       public static function provideTestIsValidMoveOperation() {
                return array( 
                        array( 'Test', 'Test', 'selfmove' ),
                        array( 'File:Test.jpg', 'Page', 'imagenocrossnamespace' )
@@ -79,22 +97,15 @@ class TitleTest extends MediaWikiTestCase {
        /**
         * @dataProvider provideCasesForGetpageviewlanguage
         */
-       function testGetpageviewlanguage( $expected, $titleText, $contLang, $lang, $variant, $msg='' ) {
-               // Save globals
-               global $wgContLang, $wgLang, $wgAllowUserJs, $wgLanguageCode, $wgDefaultLanguageVariant;
-               $save['wgContLang']               = $wgContLang;
-               $save['wgLang']                   = $wgLang;
-               $save['wgAllowUserJs']            = $wgAllowUserJs;
-               $save['wgLanguageCode']           = $wgLanguageCode;
-               $save['wgDefaultLanguageVariant'] = $wgDefaultLanguageVariant;
-
-               // Setup test environnement:
-               $wgContLang = Language::factory( $contLang );
-               $wgLang     = Language::factory( $lang );
-               # To test out .js titles:
-               $wgAllowUserJs = true;
+       function testGetpageviewlanguage( $expected, $titleText, $contLang, $lang, $variant, $msg = '' ) {
+               global $wgLanguageCode, $wgContLang, $wgLang, $wgDefaultLanguageVariant, $wgAllowUserJs;
+
+               // Setup environnement for this test
                $wgLanguageCode = $contLang;
+               $wgContLang = Language::factory( $contLang );
+               $wgLang = Language::factory( $lang );
                $wgDefaultLanguageVariant = $variant;
+               $wgAllowUserJs = true;
 
                $title = Title::newFromText( $titleText );
                $this->assertInstanceOf( 'Title', $title,
@@ -104,13 +115,6 @@ class TitleTest extends MediaWikiTestCase {
                        $title->getPageViewLanguage()->getCode(),
                        $msg
                );
-
-               // Restore globals
-               $wgContLang               = $save['wgContLang'];
-               $wgLang                   = $save['wgLang'];
-               $wgAllowUserJs            = $save['wgAllowUserJs'];
-               $wgLanguageCode           = $save['wgLanguageCode'];
-               $wgDefaultLanguageVariant = $save['wgDefaultLanguageVariant'];
        }
 
        function provideCasesForGetpageviewlanguage() {
@@ -122,11 +126,11 @@ class TitleTest extends MediaWikiTestCase {
                # - wgDefaultLanguageVariant
                # - Optional message
                return array(
-                       array( 'fr', 'Main_page', 'fr', 'fr', false ),
-                       array( 'es', 'Main_page', 'es', 'zh-tw', false ),
-                       array( 'zh', 'Main_page', 'zh', 'zh-tw', false ),
+                       array( 'fr', 'Help:I_need_somebody', 'fr', 'fr', false ),
+                       array( 'es', 'Help:I_need_somebody', 'es', 'zh-tw', false ),
+                       array( 'zh', 'Help:I_need_somebody', 'zh', 'zh-tw', false ),
 
-                       array( 'es',    'Main_page',                 'es', 'zh-tw', 'zh-cn' ),
+                       array( 'es',    'Help:I_need_somebody',      'es', 'zh-tw', 'zh-cn' ),
                        array( 'es',    'MediaWiki:About',           'es', 'zh-tw', 'zh-cn' ),
                        array( 'es',    'MediaWiki:About/',          'es', 'zh-tw', 'zh-cn' ),
                        array( 'de',    'MediaWiki:About/de',        'es', 'zh-tw', 'zh-cn' ),
@@ -135,7 +139,7 @@ class TitleTest extends MediaWikiTestCase {
                        array( 'en',    'User:JohnDoe/Common.js',    'es', 'zh-tw', 'zh-cn' ),
                        array( 'en',    'User:JohnDoe/Monobook.css', 'es', 'zh-tw', 'zh-cn' ),
 
-                       array( 'zh-cn', 'Main_page',                 'zh', 'zh-tw', 'zh-cn' ),
+                       array( 'zh-cn', 'Help:I_need_somebody',      'zh', 'zh-tw', 'zh-cn' ),
                        array( 'zh',    'MediaWiki:About',           'zh', 'zh-tw', 'zh-cn' ),
                        array( 'zh',    'MediaWiki:About/',          'zh', 'zh-tw', 'zh-cn' ),
                        array( 'de',    'MediaWiki:About/de',        'zh', 'zh-tw', 'zh-cn' ),
@@ -182,7 +186,7 @@ class TitleTest extends MediaWikiTestCase {
                );
        }
 
-       function provideRootTitleCases() {
+       public static function provideRootTitleCases() {
                return array(
                        # Title, expected base, optional message
                        array('User:John_Doe/subOne/subTwo', 'John Doe' ),