MediaWiki
REL1_20
|
00001 <?php 00002 00003 class TitleMethodsTest extends MediaWikiTestCase { 00004 00005 public function dataEquals() { 00006 return array( 00007 array( 'Main Page', 'Main Page', true ), 00008 array( 'Main Page', 'Not The Main Page', false ), 00009 array( 'Main Page', 'Project:Main Page', false ), 00010 array( 'File:Example.png', 'Image:Example.png', true ), 00011 array( 'Special:Version', 'Special:Version', true ), 00012 array( 'Special:Version', 'Special:Recentchanges', false ), 00013 array( 'Special:Version', 'Main Page', false ), 00014 ); 00015 } 00016 00020 public function testEquals( $titleA, $titleB, $expectedBool ) { 00021 $titleA = Title::newFromText( $titleA ); 00022 $titleB = Title::newFromText( $titleB ); 00023 00024 $this->assertEquals( $expectedBool, $titleA->equals( $titleB ) ); 00025 $this->assertEquals( $expectedBool, $titleB->equals( $titleA ) ); 00026 } 00027 00028 public function dataInNamespace() { 00029 return array( 00030 array( 'Main Page', NS_MAIN, true ), 00031 array( 'Main Page', NS_TALK, false ), 00032 array( 'Main Page', NS_USER, false ), 00033 array( 'User:Foo', NS_USER, true ), 00034 array( 'User:Foo', NS_USER_TALK, false ), 00035 array( 'User:Foo', NS_TEMPLATE, false ), 00036 array( 'User_talk:Foo', NS_USER_TALK, true ), 00037 array( 'User_talk:Foo', NS_USER, false ), 00038 ); 00039 } 00040 00044 public function testInNamespace( $title, $ns, $expectedBool ) { 00045 $title = Title::newFromText( $title ); 00046 $this->assertEquals( $expectedBool, $title->inNamespace( $ns ) ); 00047 } 00048 00049 public function testInNamespaces() { 00050 $mainpage = Title::newFromText( 'Main Page' ); 00051 $this->assertTrue( $mainpage->inNamespaces( NS_MAIN, NS_USER ) ); 00052 $this->assertTrue( $mainpage->inNamespaces( array( NS_MAIN, NS_USER ) ) ); 00053 $this->assertTrue( $mainpage->inNamespaces( array( NS_USER, NS_MAIN ) ) ); 00054 $this->assertFalse( $mainpage->inNamespaces( array( NS_PROJECT, NS_TEMPLATE ) ) ); 00055 } 00056 00057 public function dataHasSubjectNamespace() { 00058 return array( 00059 array( 'Main Page', NS_MAIN, true ), 00060 array( 'Main Page', NS_TALK, true ), 00061 array( 'Main Page', NS_USER, false ), 00062 array( 'User:Foo', NS_USER, true ), 00063 array( 'User:Foo', NS_USER_TALK, true ), 00064 array( 'User:Foo', NS_TEMPLATE, false ), 00065 array( 'User_talk:Foo', NS_USER_TALK, true ), 00066 array( 'User_talk:Foo', NS_USER, true ), 00067 ); 00068 } 00069 00073 public function testHasSubjectNamespace( $title, $ns, $expectedBool ) { 00074 $title = Title::newFromText( $title ); 00075 $this->assertEquals( $expectedBool, $title->hasSubjectNamespace( $ns ) ); 00076 } 00077 00078 public function dataIsCssOrJsPage() { 00079 return array( 00080 array( 'Foo', false ), 00081 array( 'Foo.js', false ), 00082 array( 'Foo/bar.js', false ), 00083 array( 'User:Foo', false ), 00084 array( 'User:Foo.js', false ), 00085 array( 'User:Foo/bar.js', false ), 00086 array( 'User:Foo/bar.css', false ), 00087 array( 'User talk:Foo/bar.css', false ), 00088 array( 'User:Foo/bar.js.xxx', false ), 00089 array( 'User:Foo/bar.xxx', false ), 00090 array( 'MediaWiki:Foo.js', true ), 00091 array( 'MediaWiki:Foo.css', true ), 00092 array( 'MediaWiki:Foo.JS', false ), 00093 array( 'MediaWiki:Foo.CSS', false ), 00094 array( 'MediaWiki:Foo.css.xxx', false ), 00095 ); 00096 } 00097 00101 public function testIsCssOrJsPage( $title, $expectedBool ) { 00102 $title = Title::newFromText( $title ); 00103 $this->assertEquals( $expectedBool, $title->isCssOrJsPage() ); 00104 } 00105 00106 00107 public function dataIsCssJsSubpage() { 00108 return array( 00109 array( 'Foo', false ), 00110 array( 'Foo.js', false ), 00111 array( 'Foo/bar.js', false ), 00112 array( 'User:Foo', false ), 00113 array( 'User:Foo.js', false ), 00114 array( 'User:Foo/bar.js', true ), 00115 array( 'User:Foo/bar.css', true ), 00116 array( 'User talk:Foo/bar.css', false ), 00117 array( 'User:Foo/bar.js.xxx', false ), 00118 array( 'User:Foo/bar.xxx', false ), 00119 array( 'MediaWiki:Foo.js', false ), 00120 array( 'User:Foo/bar.JS', false ), 00121 array( 'User:Foo/bar.CSS', false ), 00122 ); 00123 } 00124 00128 public function testIsCssJsSubpage( $title, $expectedBool ) { 00129 $title = Title::newFromText( $title ); 00130 $this->assertEquals( $expectedBool, $title->isCssJsSubpage() ); 00131 } 00132 00133 public function dataIsCssSubpage() { 00134 return array( 00135 array( 'Foo', false ), 00136 array( 'Foo.css', false ), 00137 array( 'User:Foo', false ), 00138 array( 'User:Foo.js', false ), 00139 array( 'User:Foo.css', false ), 00140 array( 'User:Foo/bar.js', false ), 00141 array( 'User:Foo/bar.css', true ), 00142 ); 00143 } 00144 00148 public function testIsCssSubpage( $title, $expectedBool ) { 00149 $title = Title::newFromText( $title ); 00150 $this->assertEquals( $expectedBool, $title->isCssSubpage() ); 00151 } 00152 00153 public function dataIsJsSubpage() { 00154 return array( 00155 array( 'Foo', false ), 00156 array( 'Foo.css', false ), 00157 array( 'User:Foo', false ), 00158 array( 'User:Foo.js', false ), 00159 array( 'User:Foo.css', false ), 00160 array( 'User:Foo/bar.js', true ), 00161 array( 'User:Foo/bar.css', false ), 00162 ); 00163 } 00164 00168 public function testIsJsSubpage( $title, $expectedBool ) { 00169 $title = Title::newFromText( $title ); 00170 $this->assertEquals( $expectedBool, $title->isJsSubpage() ); 00171 } 00172 00173 public function dataIsWikitextPage() { 00174 return array( 00175 array( 'Foo', true ), 00176 array( 'Foo.js', true ), 00177 array( 'Foo/bar.js', true ), 00178 array( 'User:Foo', true ), 00179 array( 'User:Foo.js', true ), 00180 array( 'User:Foo/bar.js', false ), 00181 array( 'User:Foo/bar.css', false ), 00182 array( 'User talk:Foo/bar.css', true ), 00183 array( 'User:Foo/bar.js.xxx', true ), 00184 array( 'User:Foo/bar.xxx', true ), 00185 array( 'MediaWiki:Foo.js', false ), 00186 array( 'MediaWiki:Foo.css', false ), 00187 array( 'MediaWiki:Foo/bar.css', false ), 00188 array( 'User:Foo/bar.JS', true ), 00189 array( 'User:Foo/bar.CSS', true ), 00190 ); 00191 } 00192 00196 public function testIsWikitextPage( $title, $expectedBool ) { 00197 $title = Title::newFromText( $title ); 00198 $this->assertEquals( $expectedBool, $title->isWikitextPage() ); 00199 } 00200 00201 }