Merge "Fixed dependencies for jquery.collapsibleTabs"
[lhc/web/wiklou.git] / tests / phpunit / includes / TitleMethodsTest.php
index badd040..44fd690 100644 (file)
@@ -1,8 +1,44 @@
 <?php
 
+/**
+ * @group ContentHandler
+ *
+ * @note: We don't make assumptions about the main namespace.
+ *        But we do expect the Help namespace to contain Wikitext.
+ *
+ */
 class TitleMethodsTest extends MediaWikiTestCase {
 
-       public function dataEquals() {
+       public function setup() {
+               global $wgExtraNamespaces, $wgNamespaceContentModels, $wgContLang;
+
+               $this->mergeMwGlobalArrayValue(
+                       'wgExtraNamespaces',
+                       array(
+                               12302 => 'TEST-JS',
+                               12303 => 'TEST-JS_TALK',
+                       )
+               );
+
+               $this->mergeMwGlobalArrayValue(
+                       'wgNamespaceContentModels',
+                       array(
+                               12302 => CONTENT_MODEL_JAVASCRIPT,
+                       )
+               );
+
+               MWNamespace::getCanonicalNamespaces( true ); # reset namespace cache
+               $wgContLang->resetNamespaces(); # reset namespace cache
+       }
+
+       public function teardown() {
+               global $wgContLang;
+
+               MWNamespace::getCanonicalNamespaces( true ); # reset namespace cache
+               $wgContLang->resetNamespaces(); # reset namespace cache
+       }
+
+       public static function provideEquals() {
                return array(
                        array( 'Main Page', 'Main Page', true ),
                        array( 'Main Page', 'Not The Main Page', false ),
@@ -15,7 +51,7 @@ class TitleMethodsTest extends MediaWikiTestCase {
        }
 
        /**
-        * @dataProvider dataEquals
+        * @dataProvider provideEquals
         */
        public function testEquals( $titleA, $titleB, $expectedBool ) {
                $titleA = Title::newFromText( $titleA );
@@ -25,7 +61,7 @@ class TitleMethodsTest extends MediaWikiTestCase {
                $this->assertEquals( $expectedBool, $titleB->equals( $titleA ) );
        }
 
-       public function dataInNamespace() {
+       public static function provideInNamespace() {
                return array(
                        array( 'Main Page', NS_MAIN, true ),
                        array( 'Main Page', NS_TALK, false ),
@@ -39,11 +75,11 @@ class TitleMethodsTest extends MediaWikiTestCase {
        }
 
        /**
-        * @dataProvider dataInNamespace
+        * @dataProvider provideInNamespace
         */
        public function testInNamespace( $title, $ns, $expectedBool ) {
                $title = Title::newFromText( $title );
-               $this->assertEquals( $title->inNamespace( $ns ), $expectedBool );
+               $this->assertEquals( $expectedBool, $title->inNamespace( $ns ) );
        }
 
        public function testInNamespaces() {
@@ -54,7 +90,7 @@ class TitleMethodsTest extends MediaWikiTestCase {
                $this->assertFalse( $mainpage->inNamespaces( array( NS_PROJECT, NS_TEMPLATE ) ) );
        }
 
-       public function dataHasSubjectNamespace() {
+       public static function provideHasSubjectNamespace() {
                return array(
                        array( 'Main Page', NS_MAIN, true ),
                        array( 'Main Page', NS_TALK, true ),
@@ -68,11 +104,182 @@ class TitleMethodsTest extends MediaWikiTestCase {
        }
 
        /**
-        * @dataProvider dataHasSubjectNamespace
+        * @dataProvider provideHasSubjectNamespace
         */
        public function testHasSubjectNamespace( $title, $ns, $expectedBool ) {
                $title = Title::newFromText( $title );
                $this->assertEquals( $expectedBool, $title->hasSubjectNamespace( $ns ) );
        }
 
+       public function dataGetContentModel() {
+               return array(
+                       array( 'Help:Foo', CONTENT_MODEL_WIKITEXT ),
+                       array( 'Help:Foo.js', CONTENT_MODEL_WIKITEXT ),
+                       array( 'Help:Foo/bar.js', CONTENT_MODEL_WIKITEXT ),
+                       array( 'User:Foo', CONTENT_MODEL_WIKITEXT ),
+                       array( 'User:Foo.js', CONTENT_MODEL_WIKITEXT ),
+                       array( 'User:Foo/bar.js', CONTENT_MODEL_JAVASCRIPT ),
+                       array( 'User:Foo/bar.css', CONTENT_MODEL_CSS ),
+                       array( 'User talk:Foo/bar.css', CONTENT_MODEL_WIKITEXT ),
+                       array( 'User:Foo/bar.js.xxx', CONTENT_MODEL_WIKITEXT ),
+                       array( 'User:Foo/bar.xxx', CONTENT_MODEL_WIKITEXT ),
+                       array( 'MediaWiki:Foo.js', CONTENT_MODEL_JAVASCRIPT ),
+                       array( 'MediaWiki:Foo.css', CONTENT_MODEL_CSS ),
+                       array( 'MediaWiki:Foo/bar.css', CONTENT_MODEL_CSS ),
+                       array( 'MediaWiki:Foo.JS', CONTENT_MODEL_WIKITEXT ),
+                       array( 'MediaWiki:Foo.CSS', CONTENT_MODEL_WIKITEXT ),
+                       array( 'MediaWiki:Foo.css.xxx', CONTENT_MODEL_WIKITEXT ),
+                       array( 'TEST-JS:Foo', CONTENT_MODEL_JAVASCRIPT ),
+                       array( 'TEST-JS:Foo.js', CONTENT_MODEL_JAVASCRIPT ),
+                       array( 'TEST-JS:Foo/bar.js', CONTENT_MODEL_JAVASCRIPT ),
+                       array( 'TEST-JS_TALK:Foo.js', CONTENT_MODEL_WIKITEXT ),
+               );
+       }
+
+       /**
+        * @dataProvider dataGetContentModel
+        */
+       public function testGetContentModel( $title, $expectedModelId ) {
+               $title = Title::newFromText( $title );
+               $this->assertEquals( $expectedModelId, $title->getContentModel() );
+       }
+
+       /**
+        * @dataProvider dataGetContentModel
+        */
+       public function testHasContentModel( $title, $expectedModelId ) {
+               $title = Title::newFromText( $title );
+               $this->assertTrue( $title->hasContentModel( $expectedModelId ) );
+       }
+
+       public static function provideIsCssOrJsPage() {
+               return array(
+                       array( 'Help:Foo', false ),
+                       array( 'Help:Foo.js', false ),
+                       array( 'Help:Foo/bar.js', false ),
+                       array( 'User:Foo', false ),
+                       array( 'User:Foo.js', false ),
+                       array( 'User:Foo/bar.js', false ),
+                       array( 'User:Foo/bar.css', false ),
+                       array( 'User talk:Foo/bar.css', false ),
+                       array( 'User:Foo/bar.js.xxx', false ),
+                       array( 'User:Foo/bar.xxx', false ),
+                       array( 'MediaWiki:Foo.js', true ),
+                       array( 'MediaWiki:Foo.css', true ),
+                       array( 'MediaWiki:Foo.JS', false ),
+                       array( 'MediaWiki:Foo.CSS', false ),
+                       array( 'MediaWiki:Foo.css.xxx', false ),
+                       array( 'TEST-JS:Foo', false ),
+                       array( 'TEST-JS:Foo.js', false ),
+               );
+       }
+
+       /**
+        * @dataProvider provideIsCssOrJsPage
+        */
+       public function testIsCssOrJsPage( $title, $expectedBool ) {
+               $title = Title::newFromText( $title );
+               $this->assertEquals( $expectedBool, $title->isCssOrJsPage() );
+       }
+
+
+       public static function provideIsCssJsSubpage() {
+               return array(
+                       array( 'Help:Foo', false ),
+                       array( 'Help:Foo.js', false ),
+                       array( 'Help:Foo/bar.js', false ),
+                       array( 'User:Foo', false ),
+                       array( 'User:Foo.js', false ),
+                       array( 'User:Foo/bar.js', true ),
+                       array( 'User:Foo/bar.css', true ),
+                       array( 'User talk:Foo/bar.css', false ),
+                       array( 'User:Foo/bar.js.xxx', false ),
+                       array( 'User:Foo/bar.xxx', false ),
+                       array( 'MediaWiki:Foo.js', false ),
+                       array( 'User:Foo/bar.JS', false ),
+                       array( 'User:Foo/bar.CSS', false ),
+                       array( 'TEST-JS:Foo', false ),
+                       array( 'TEST-JS:Foo.js', false ),
+               );
+       }
+
+       /**
+        * @dataProvider provideIsCssJsSubpage
+        */
+       public function testIsCssJsSubpage( $title, $expectedBool ) {
+               $title = Title::newFromText( $title );
+               $this->assertEquals( $expectedBool, $title->isCssJsSubpage() );
+       }
+
+       public static function provideIsCssSubpage() {
+               return array(
+                       array( 'Help:Foo', false ),
+                       array( 'Help:Foo.css', false ),
+                       array( 'User:Foo', false ),
+                       array( 'User:Foo.js', false ),
+                       array( 'User:Foo.css', false ),
+                       array( 'User:Foo/bar.js', false ),
+                       array( 'User:Foo/bar.css', true ),
+               );
+       }
+
+       /**
+        * @dataProvider provideIsCssSubpage
+        */
+       public function testIsCssSubpage( $title, $expectedBool ) {
+               $title = Title::newFromText( $title );
+               $this->assertEquals( $expectedBool, $title->isCssSubpage() );
+       }
+
+       public static function provideIsJsSubpage() {
+               return array(
+                       array( 'Help:Foo', false ),
+                       array( 'Help:Foo.css', false ),
+                       array( 'User:Foo', false ),
+                       array( 'User:Foo.js', false ),
+                       array( 'User:Foo.css', false ),
+                       array( 'User:Foo/bar.js', true ),
+                       array( 'User:Foo/bar.css', false ),
+               );
+       }
+
+       /**
+        * @dataProvider provideIsJsSubpage
+        */
+       public function testIsJsSubpage( $title, $expectedBool ) {
+               $title = Title::newFromText( $title );
+               $this->assertEquals( $expectedBool, $title->isJsSubpage() );
+       }
+
+       public static function provideIsWikitextPage() {
+               return array(
+                       array( 'Help:Foo', true ),
+                       array( 'Help:Foo.js', true ),
+                       array( 'Help:Foo/bar.js', true ),
+                       array( 'User:Foo', true ),
+                       array( 'User:Foo.js', true ),
+                       array( 'User:Foo/bar.js', false ),
+                       array( 'User:Foo/bar.css', false ),
+                       array( 'User talk:Foo/bar.css', true ),
+                       array( 'User:Foo/bar.js.xxx', true ),
+                       array( 'User:Foo/bar.xxx', true ),
+                       array( 'MediaWiki:Foo.js', false ),
+                       array( 'MediaWiki:Foo.css', false ),
+                       array( 'MediaWiki:Foo/bar.css', false ),
+                       array( 'User:Foo/bar.JS', true ),
+                       array( 'User:Foo/bar.CSS', true ),
+                       array( 'TEST-JS:Foo', false ),
+                       array( 'TEST-JS:Foo.js', false ),
+                       array( 'TEST-JS_TALK:Foo.js', true ),
+               );
+       }
+
+       /**
+        * @dataProvider provideIsWikitextPage
+        */
+       public function testIsWikitextPage( $title, $expectedBool ) {
+               $title = Title::newFromText( $title );
+               $this->assertEquals( $expectedBool, $title->isWikitextPage() );
+       }
+
 }