From: daniel Date: Wed, 2 May 2012 17:30:09 +0000 (+0200) Subject: Adding more tests for Title. X-Git-Tag: 1.31.0-rc.0~23751^2 X-Git-Url: https://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/banques/ajouter.php?a=commitdiff_plain;h=d85bbb107478f557860c839080da64b60246f75c;p=lhc%2Fweb%2Fwiklou.git Adding more tests for Title. This introduces tests for isCssJsSubpage, isCssOrJsPage, and isWikitextPage. New tests are added to avoid regressions when the ContentHandler facility is introduced. Change-Id: I68987490b01242cc0bcdc0d9dfaa99f1227f71a0 --- diff --git a/tests/phpunit/includes/TitleMethodsTest.php b/tests/phpunit/includes/TitleMethodsTest.php index badd04074a..aed658baa3 100644 --- a/tests/phpunit/includes/TitleMethodsTest.php +++ b/tests/phpunit/includes/TitleMethodsTest.php @@ -43,7 +43,7 @@ class TitleMethodsTest extends MediaWikiTestCase { */ 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() { @@ -75,4 +75,127 @@ class TitleMethodsTest extends MediaWikiTestCase { $this->assertEquals( $expectedBool, $title->hasSubjectNamespace( $ns ) ); } + public function dataIsCssOrJsPage() { + return array( + array( 'Foo', false ), + array( 'Foo.js', false ), + array( '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 ), + ); + } + + /** + * @dataProvider dataIsCssOrJsPage + */ + public function testIsCssOrJsPage( $title, $expectedBool ) { + $title = Title::newFromText( $title ); + $this->assertEquals( $expectedBool, $title->isCssOrJsPage() ); + } + + + public function dataIsCssJsSubpage() { + return array( + array( 'Foo', false ), + array( 'Foo.js', false ), + array( '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 ), + ); + } + + /** + * @dataProvider dataIsCssJsSubpage + */ + public function testIsCssJsSubpage( $title, $expectedBool ) { + $title = Title::newFromText( $title ); + $this->assertEquals( $expectedBool, $title->isCssJsSubpage() ); + } + + public function dataIsCssSubpage() { + return array( + array( 'Foo', false ), + array( '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 dataIsCssSubpage + */ + public function testIsCssSubpage( $title, $expectedBool ) { + $title = Title::newFromText( $title ); + $this->assertEquals( $expectedBool, $title->isCssSubpage() ); + } + + public function dataIsJsSubpage() { + return array( + array( 'Foo', false ), + array( '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 dataIsJsSubpage + */ + public function testIsJsSubpage( $title, $expectedBool ) { + $title = Title::newFromText( $title ); + $this->assertEquals( $expectedBool, $title->isJsSubpage() ); + } + + public function dataIsWikitextPage() { + return array( + array( 'Foo', true ), + array( 'Foo.js', true ), + array( '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 ), + ); + } + + /** + * @dataProvider dataIsWikitextPage + */ + public function testIsWikitextPage( $title, $expectedBool ) { + $title = Title::newFromText( $title ); + $this->assertEquals( $expectedBool, $title->isWikitextPage() ); + } + }