diff options
Diffstat (limited to 'tests/phpunit/includes/TitleMethodsTest.php')
-rw-r--r-- | tests/phpunit/includes/TitleMethodsTest.php | 161 |
1 files changed, 130 insertions, 31 deletions
diff --git a/tests/phpunit/includes/TitleMethodsTest.php b/tests/phpunit/includes/TitleMethodsTest.php index aed658ba..3079d73a 100644 --- a/tests/phpunit/includes/TitleMethodsTest.php +++ b/tests/phpunit/includes/TitleMethodsTest.php @@ -1,8 +1,48 @@ <?php +/** + * @group ContentHandler + * @group Database + * + * @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 $wgContLang; + + parent::setUp(); + + $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; + + parent::tearDown(); + + 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 +55,8 @@ class TitleMethodsTest extends MediaWikiTestCase { } /** - * @dataProvider dataEquals + * @dataProvider provideEquals + * @covers Title::equals */ public function testEquals( $titleA, $titleB, $expectedBool ) { $titleA = Title::newFromText( $titleA ); @@ -25,7 +66,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,13 +80,17 @@ class TitleMethodsTest extends MediaWikiTestCase { } /** - * @dataProvider dataInNamespace + * @dataProvider provideInNamespace + * @covers Title::inNamespace */ public function testInNamespace( $title, $ns, $expectedBool ) { $title = Title::newFromText( $title ); $this->assertEquals( $expectedBool, $title->inNamespace( $ns ) ); } + /** + * @covers Title::inNamespaces + */ public function testInNamespaces() { $mainpage = Title::newFromText( 'Main Page' ); $this->assertTrue( $mainpage->inNamespaces( NS_MAIN, NS_USER ) ); @@ -54,7 +99,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,18 +113,62 @@ class TitleMethodsTest extends MediaWikiTestCase { } /** - * @dataProvider dataHasSubjectNamespace + * @dataProvider provideHasSubjectNamespace + * @covers Title::hasSubjectNamespace */ public function testHasSubjectNamespace( $title, $ns, $expectedBool ) { $title = Title::newFromText( $title ); $this->assertEquals( $expectedBool, $title->hasSubjectNamespace( $ns ) ); } - public function dataIsCssOrJsPage() { + 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 + * @covers Title::getContentModel + */ + public function testGetContentModel( $title, $expectedModelId ) { + $title = Title::newFromText( $title ); + $this->assertEquals( $expectedModelId, $title->getContentModel() ); + } + + /** + * @dataProvider dataGetContentModel + * @covers Title::hasContentModel + */ + public function testHasContentModel( $title, $expectedModelId ) { + $title = Title::newFromText( $title ); + $this->assertTrue( $title->hasContentModel( $expectedModelId ) ); + } + + public static function provideIsCssOrJsPage() { return array( - array( 'Foo', false ), - array( 'Foo.js', false ), - array( 'Foo/bar.js', false ), + 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 ), @@ -92,23 +181,25 @@ class TitleMethodsTest extends MediaWikiTestCase { 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 dataIsCssOrJsPage + * @dataProvider provideIsCssOrJsPage + * @covers Title::isCssOrJsPage */ public function testIsCssOrJsPage( $title, $expectedBool ) { $title = Title::newFromText( $title ); $this->assertEquals( $expectedBool, $title->isCssOrJsPage() ); } - - public function dataIsCssJsSubpage() { + public static function provideIsCssJsSubpage() { return array( - array( 'Foo', false ), - array( 'Foo.js', false ), - array( 'Foo/bar.js', false ), + 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 ), @@ -119,21 +210,24 @@ class TitleMethodsTest extends MediaWikiTestCase { 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 dataIsCssJsSubpage + * @dataProvider provideIsCssJsSubpage + * @covers Title::isCssJsSubpage */ public function testIsCssJsSubpage( $title, $expectedBool ) { $title = Title::newFromText( $title ); $this->assertEquals( $expectedBool, $title->isCssJsSubpage() ); } - public function dataIsCssSubpage() { + public static function provideIsCssSubpage() { return array( - array( 'Foo', false ), - array( 'Foo.css', false ), + array( 'Help:Foo', false ), + array( 'Help:Foo.css', false ), array( 'User:Foo', false ), array( 'User:Foo.js', false ), array( 'User:Foo.css', false ), @@ -143,17 +237,18 @@ class TitleMethodsTest extends MediaWikiTestCase { } /** - * @dataProvider dataIsCssSubpage + * @dataProvider provideIsCssSubpage + * @covers Title::isCssSubpage */ public function testIsCssSubpage( $title, $expectedBool ) { $title = Title::newFromText( $title ); $this->assertEquals( $expectedBool, $title->isCssSubpage() ); } - public function dataIsJsSubpage() { + public static function provideIsJsSubpage() { return array( - array( 'Foo', false ), - array( 'Foo.css', false ), + array( 'Help:Foo', false ), + array( 'Help:Foo.css', false ), array( 'User:Foo', false ), array( 'User:Foo.js', false ), array( 'User:Foo.css', false ), @@ -163,18 +258,19 @@ class TitleMethodsTest extends MediaWikiTestCase { } /** - * @dataProvider dataIsJsSubpage + * @dataProvider provideIsJsSubpage + * @covers Title::isJsSubpage */ public function testIsJsSubpage( $title, $expectedBool ) { $title = Title::newFromText( $title ); $this->assertEquals( $expectedBool, $title->isJsSubpage() ); } - public function dataIsWikitextPage() { + public static function provideIsWikitextPage() { return array( - array( 'Foo', true ), - array( 'Foo.js', true ), - array( 'Foo/bar.js', true ), + 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 ), @@ -187,15 +283,18 @@ class TitleMethodsTest extends MediaWikiTestCase { 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 dataIsWikitextPage + * @dataProvider provideIsWikitextPage + * @covers Title::isWikitextPage */ public function testIsWikitextPage( $title, $expectedBool ) { $title = Title::newFromText( $title ); $this->assertEquals( $expectedBool, $title->isWikitextPage() ); } - } |