MediaWiki  REL1_22
TitleMethodsTest.php
Go to the documentation of this file.
00001 <?php
00002 
00010 class TitleMethodsTest extends MediaWikiTestCase {
00011 
00012     public function setUp() {
00013         global $wgContLang;
00014 
00015         parent::setUp();
00016 
00017         $this->mergeMwGlobalArrayValue(
00018             'wgExtraNamespaces',
00019             array(
00020                 12302 => 'TEST-JS',
00021                 12303 => 'TEST-JS_TALK',
00022             )
00023         );
00024 
00025         $this->mergeMwGlobalArrayValue(
00026             'wgNamespaceContentModels',
00027             array(
00028                 12302 => CONTENT_MODEL_JAVASCRIPT,
00029             )
00030         );
00031 
00032         MWNamespace::getCanonicalNamespaces( true ); # reset namespace cache
00033         $wgContLang->resetNamespaces(); # reset namespace cache
00034     }
00035 
00036     public function tearDown() {
00037         global $wgContLang;
00038 
00039         parent::tearDown();
00040 
00041         MWNamespace::getCanonicalNamespaces( true ); # reset namespace cache
00042         $wgContLang->resetNamespaces(); # reset namespace cache
00043     }
00044 
00045     public static function provideEquals() {
00046         return array(
00047             array( 'Main Page', 'Main Page', true ),
00048             array( 'Main Page', 'Not The Main Page', false ),
00049             array( 'Main Page', 'Project:Main Page', false ),
00050             array( 'File:Example.png', 'Image:Example.png', true ),
00051             array( 'Special:Version', 'Special:Version', true ),
00052             array( 'Special:Version', 'Special:Recentchanges', false ),
00053             array( 'Special:Version', 'Main Page', false ),
00054         );
00055     }
00056 
00061     public function testEquals( $titleA, $titleB, $expectedBool ) {
00062         $titleA = Title::newFromText( $titleA );
00063         $titleB = Title::newFromText( $titleB );
00064 
00065         $this->assertEquals( $expectedBool, $titleA->equals( $titleB ) );
00066         $this->assertEquals( $expectedBool, $titleB->equals( $titleA ) );
00067     }
00068 
00069     public static function provideInNamespace() {
00070         return array(
00071             array( 'Main Page', NS_MAIN, true ),
00072             array( 'Main Page', NS_TALK, false ),
00073             array( 'Main Page', NS_USER, false ),
00074             array( 'User:Foo', NS_USER, true ),
00075             array( 'User:Foo', NS_USER_TALK, false ),
00076             array( 'User:Foo', NS_TEMPLATE, false ),
00077             array( 'User_talk:Foo', NS_USER_TALK, true ),
00078             array( 'User_talk:Foo', NS_USER, false ),
00079         );
00080     }
00081 
00086     public function testInNamespace( $title, $ns, $expectedBool ) {
00087         $title = Title::newFromText( $title );
00088         $this->assertEquals( $expectedBool, $title->inNamespace( $ns ) );
00089     }
00090 
00094     public function testInNamespaces() {
00095         $mainpage = Title::newFromText( 'Main Page' );
00096         $this->assertTrue( $mainpage->inNamespaces( NS_MAIN, NS_USER ) );
00097         $this->assertTrue( $mainpage->inNamespaces( array( NS_MAIN, NS_USER ) ) );
00098         $this->assertTrue( $mainpage->inNamespaces( array( NS_USER, NS_MAIN ) ) );
00099         $this->assertFalse( $mainpage->inNamespaces( array( NS_PROJECT, NS_TEMPLATE ) ) );
00100     }
00101 
00102     public static function provideHasSubjectNamespace() {
00103         return array(
00104             array( 'Main Page', NS_MAIN, true ),
00105             array( 'Main Page', NS_TALK, true ),
00106             array( 'Main Page', NS_USER, false ),
00107             array( 'User:Foo', NS_USER, true ),
00108             array( 'User:Foo', NS_USER_TALK, true ),
00109             array( 'User:Foo', NS_TEMPLATE, false ),
00110             array( 'User_talk:Foo', NS_USER_TALK, true ),
00111             array( 'User_talk:Foo', NS_USER, true ),
00112         );
00113     }
00114 
00119     public function testHasSubjectNamespace( $title, $ns, $expectedBool ) {
00120         $title = Title::newFromText( $title );
00121         $this->assertEquals( $expectedBool, $title->hasSubjectNamespace( $ns ) );
00122     }
00123 
00124     public function dataGetContentModel() {
00125         return array(
00126             array( 'Help:Foo', CONTENT_MODEL_WIKITEXT ),
00127             array( 'Help:Foo.js', CONTENT_MODEL_WIKITEXT ),
00128             array( 'Help:Foo/bar.js', CONTENT_MODEL_WIKITEXT ),
00129             array( 'User:Foo', CONTENT_MODEL_WIKITEXT ),
00130             array( 'User:Foo.js', CONTENT_MODEL_WIKITEXT ),
00131             array( 'User:Foo/bar.js', CONTENT_MODEL_JAVASCRIPT ),
00132             array( 'User:Foo/bar.css', CONTENT_MODEL_CSS ),
00133             array( 'User talk:Foo/bar.css', CONTENT_MODEL_WIKITEXT ),
00134             array( 'User:Foo/bar.js.xxx', CONTENT_MODEL_WIKITEXT ),
00135             array( 'User:Foo/bar.xxx', CONTENT_MODEL_WIKITEXT ),
00136             array( 'MediaWiki:Foo.js', CONTENT_MODEL_JAVASCRIPT ),
00137             array( 'MediaWiki:Foo.css', CONTENT_MODEL_CSS ),
00138             array( 'MediaWiki:Foo/bar.css', CONTENT_MODEL_CSS ),
00139             array( 'MediaWiki:Foo.JS', CONTENT_MODEL_WIKITEXT ),
00140             array( 'MediaWiki:Foo.CSS', CONTENT_MODEL_WIKITEXT ),
00141             array( 'MediaWiki:Foo.css.xxx', CONTENT_MODEL_WIKITEXT ),
00142             array( 'TEST-JS:Foo', CONTENT_MODEL_JAVASCRIPT ),
00143             array( 'TEST-JS:Foo.js', CONTENT_MODEL_JAVASCRIPT ),
00144             array( 'TEST-JS:Foo/bar.js', CONTENT_MODEL_JAVASCRIPT ),
00145             array( 'TEST-JS_TALK:Foo.js', CONTENT_MODEL_WIKITEXT ),
00146         );
00147     }
00148 
00153     public function testGetContentModel( $title, $expectedModelId ) {
00154         $title = Title::newFromText( $title );
00155         $this->assertEquals( $expectedModelId, $title->getContentModel() );
00156     }
00157 
00162     public function testHasContentModel( $title, $expectedModelId ) {
00163         $title = Title::newFromText( $title );
00164         $this->assertTrue( $title->hasContentModel( $expectedModelId ) );
00165     }
00166 
00167     public static function provideIsCssOrJsPage() {
00168         return array(
00169             array( 'Help:Foo', false ),
00170             array( 'Help:Foo.js', false ),
00171             array( 'Help:Foo/bar.js', false ),
00172             array( 'User:Foo', false ),
00173             array( 'User:Foo.js', false ),
00174             array( 'User:Foo/bar.js', false ),
00175             array( 'User:Foo/bar.css', false ),
00176             array( 'User talk:Foo/bar.css', false ),
00177             array( 'User:Foo/bar.js.xxx', false ),
00178             array( 'User:Foo/bar.xxx', false ),
00179             array( 'MediaWiki:Foo.js', true ),
00180             array( 'MediaWiki:Foo.css', true ),
00181             array( 'MediaWiki:Foo.JS', false ),
00182             array( 'MediaWiki:Foo.CSS', false ),
00183             array( 'MediaWiki:Foo.css.xxx', false ),
00184             array( 'TEST-JS:Foo', false ),
00185             array( 'TEST-JS:Foo.js', false ),
00186         );
00187     }
00188 
00193     public function testIsCssOrJsPage( $title, $expectedBool ) {
00194         $title = Title::newFromText( $title );
00195         $this->assertEquals( $expectedBool, $title->isCssOrJsPage() );
00196     }
00197 
00198     public static function provideIsCssJsSubpage() {
00199         return array(
00200             array( 'Help:Foo', false ),
00201             array( 'Help:Foo.js', false ),
00202             array( 'Help:Foo/bar.js', false ),
00203             array( 'User:Foo', false ),
00204             array( 'User:Foo.js', false ),
00205             array( 'User:Foo/bar.js', true ),
00206             array( 'User:Foo/bar.css', true ),
00207             array( 'User talk:Foo/bar.css', false ),
00208             array( 'User:Foo/bar.js.xxx', false ),
00209             array( 'User:Foo/bar.xxx', false ),
00210             array( 'MediaWiki:Foo.js', false ),
00211             array( 'User:Foo/bar.JS', false ),
00212             array( 'User:Foo/bar.CSS', false ),
00213             array( 'TEST-JS:Foo', false ),
00214             array( 'TEST-JS:Foo.js', false ),
00215         );
00216     }
00217 
00222     public function testIsCssJsSubpage( $title, $expectedBool ) {
00223         $title = Title::newFromText( $title );
00224         $this->assertEquals( $expectedBool, $title->isCssJsSubpage() );
00225     }
00226 
00227     public static function provideIsCssSubpage() {
00228         return array(
00229             array( 'Help:Foo', false ),
00230             array( 'Help:Foo.css', false ),
00231             array( 'User:Foo', false ),
00232             array( 'User:Foo.js', false ),
00233             array( 'User:Foo.css', false ),
00234             array( 'User:Foo/bar.js', false ),
00235             array( 'User:Foo/bar.css', true ),
00236         );
00237     }
00238 
00243     public function testIsCssSubpage( $title, $expectedBool ) {
00244         $title = Title::newFromText( $title );
00245         $this->assertEquals( $expectedBool, $title->isCssSubpage() );
00246     }
00247 
00248     public static function provideIsJsSubpage() {
00249         return array(
00250             array( 'Help:Foo', false ),
00251             array( 'Help:Foo.css', false ),
00252             array( 'User:Foo', false ),
00253             array( 'User:Foo.js', false ),
00254             array( 'User:Foo.css', false ),
00255             array( 'User:Foo/bar.js', true ),
00256             array( 'User:Foo/bar.css', false ),
00257         );
00258     }
00259 
00264     public function testIsJsSubpage( $title, $expectedBool ) {
00265         $title = Title::newFromText( $title );
00266         $this->assertEquals( $expectedBool, $title->isJsSubpage() );
00267     }
00268 
00269     public static function provideIsWikitextPage() {
00270         return array(
00271             array( 'Help:Foo', true ),
00272             array( 'Help:Foo.js', true ),
00273             array( 'Help:Foo/bar.js', true ),
00274             array( 'User:Foo', true ),
00275             array( 'User:Foo.js', true ),
00276             array( 'User:Foo/bar.js', false ),
00277             array( 'User:Foo/bar.css', false ),
00278             array( 'User talk:Foo/bar.css', true ),
00279             array( 'User:Foo/bar.js.xxx', true ),
00280             array( 'User:Foo/bar.xxx', true ),
00281             array( 'MediaWiki:Foo.js', false ),
00282             array( 'MediaWiki:Foo.css', false ),
00283             array( 'MediaWiki:Foo/bar.css', false ),
00284             array( 'User:Foo/bar.JS', true ),
00285             array( 'User:Foo/bar.CSS', true ),
00286             array( 'TEST-JS:Foo', false ),
00287             array( 'TEST-JS:Foo.js', false ),
00288             array( 'TEST-JS_TALK:Foo.js', true ),
00289         );
00290     }
00291 
00296     public function testIsWikitextPage( $title, $expectedBool ) {
00297         $title = Title::newFromText( $title );
00298         $this->assertEquals( $expectedBool, $title->isWikitextPage() );
00299     }
00300 }