4 * @group ContentHandler
7 * @note: We don't make assumptions about the main namespace.
8 * But we do expect the Help namespace to contain Wikitext.
11 class TitleMethodsTest
extends MediaWikiTestCase
{
13 public function setUp() {
18 $this->mergeMwGlobalArrayValue(
22 12303 => 'TEST-JS_TALK',
26 $this->mergeMwGlobalArrayValue(
27 'wgNamespaceContentModels',
29 12302 => CONTENT_MODEL_JAVASCRIPT
,
33 MWNamespace
::getCanonicalNamespaces( true ); # reset namespace cache
34 $wgContLang->resetNamespaces(); # reset namespace cache
37 public function tearDown() {
42 MWNamespace
::getCanonicalNamespaces( true ); # reset namespace cache
43 $wgContLang->resetNamespaces(); # reset namespace cache
46 public static function provideEquals() {
48 array( 'Main Page', 'Main Page', true ),
49 array( 'Main Page', 'Not The Main Page', false ),
50 array( 'Main Page', 'Project:Main Page', false ),
51 array( 'File:Example.png', 'Image:Example.png', true ),
52 array( 'Special:Version', 'Special:Version', true ),
53 array( 'Special:Version', 'Special:Recentchanges', false ),
54 array( 'Special:Version', 'Main Page', false ),
59 * @dataProvider provideEquals
61 public function testEquals( $titleA, $titleB, $expectedBool ) {
62 $titleA = Title
::newFromText( $titleA );
63 $titleB = Title
::newFromText( $titleB );
65 $this->assertEquals( $expectedBool, $titleA->equals( $titleB ) );
66 $this->assertEquals( $expectedBool, $titleB->equals( $titleA ) );
69 public static function provideInNamespace() {
71 array( 'Main Page', NS_MAIN
, true ),
72 array( 'Main Page', NS_TALK
, false ),
73 array( 'Main Page', NS_USER
, false ),
74 array( 'User:Foo', NS_USER
, true ),
75 array( 'User:Foo', NS_USER_TALK
, false ),
76 array( 'User:Foo', NS_TEMPLATE
, false ),
77 array( 'User_talk:Foo', NS_USER_TALK
, true ),
78 array( 'User_talk:Foo', NS_USER
, false ),
83 * @dataProvider provideInNamespace
85 public function testInNamespace( $title, $ns, $expectedBool ) {
86 $title = Title
::newFromText( $title );
87 $this->assertEquals( $expectedBool, $title->inNamespace( $ns ) );
90 public function testInNamespaces() {
91 $mainpage = Title
::newFromText( 'Main Page' );
92 $this->assertTrue( $mainpage->inNamespaces( NS_MAIN
, NS_USER
) );
93 $this->assertTrue( $mainpage->inNamespaces( array( NS_MAIN
, NS_USER
) ) );
94 $this->assertTrue( $mainpage->inNamespaces( array( NS_USER
, NS_MAIN
) ) );
95 $this->assertFalse( $mainpage->inNamespaces( array( NS_PROJECT
, NS_TEMPLATE
) ) );
98 public static function provideHasSubjectNamespace() {
100 array( 'Main Page', NS_MAIN
, true ),
101 array( 'Main Page', NS_TALK
, true ),
102 array( 'Main Page', NS_USER
, false ),
103 array( 'User:Foo', NS_USER
, true ),
104 array( 'User:Foo', NS_USER_TALK
, true ),
105 array( 'User:Foo', NS_TEMPLATE
, false ),
106 array( 'User_talk:Foo', NS_USER_TALK
, true ),
107 array( 'User_talk:Foo', NS_USER
, true ),
112 * @dataProvider provideHasSubjectNamespace
114 public function testHasSubjectNamespace( $title, $ns, $expectedBool ) {
115 $title = Title
::newFromText( $title );
116 $this->assertEquals( $expectedBool, $title->hasSubjectNamespace( $ns ) );
119 public function dataGetContentModel() {
121 array( 'Help:Foo', CONTENT_MODEL_WIKITEXT
),
122 array( 'Help:Foo.js', CONTENT_MODEL_WIKITEXT
),
123 array( 'Help:Foo/bar.js', CONTENT_MODEL_WIKITEXT
),
124 array( 'User:Foo', CONTENT_MODEL_WIKITEXT
),
125 array( 'User:Foo.js', CONTENT_MODEL_WIKITEXT
),
126 array( 'User:Foo/bar.js', CONTENT_MODEL_JAVASCRIPT
),
127 array( 'User:Foo/bar.css', CONTENT_MODEL_CSS
),
128 array( 'User talk:Foo/bar.css', CONTENT_MODEL_WIKITEXT
),
129 array( 'User:Foo/bar.js.xxx', CONTENT_MODEL_WIKITEXT
),
130 array( 'User:Foo/bar.xxx', CONTENT_MODEL_WIKITEXT
),
131 array( 'MediaWiki:Foo.js', CONTENT_MODEL_JAVASCRIPT
),
132 array( 'MediaWiki:Foo.css', CONTENT_MODEL_CSS
),
133 array( 'MediaWiki:Foo/bar.css', CONTENT_MODEL_CSS
),
134 array( 'MediaWiki:Foo.JS', CONTENT_MODEL_WIKITEXT
),
135 array( 'MediaWiki:Foo.CSS', CONTENT_MODEL_WIKITEXT
),
136 array( 'MediaWiki:Foo.css.xxx', CONTENT_MODEL_WIKITEXT
),
137 array( 'TEST-JS:Foo', CONTENT_MODEL_JAVASCRIPT
),
138 array( 'TEST-JS:Foo.js', CONTENT_MODEL_JAVASCRIPT
),
139 array( 'TEST-JS:Foo/bar.js', CONTENT_MODEL_JAVASCRIPT
),
140 array( 'TEST-JS_TALK:Foo.js', CONTENT_MODEL_WIKITEXT
),
145 * @dataProvider dataGetContentModel
147 public function testGetContentModel( $title, $expectedModelId ) {
148 $title = Title
::newFromText( $title );
149 $this->assertEquals( $expectedModelId, $title->getContentModel() );
153 * @dataProvider dataGetContentModel
155 public function testHasContentModel( $title, $expectedModelId ) {
156 $title = Title
::newFromText( $title );
157 $this->assertTrue( $title->hasContentModel( $expectedModelId ) );
160 public static function provideIsCssOrJsPage() {
162 array( 'Help:Foo', false ),
163 array( 'Help:Foo.js', false ),
164 array( 'Help:Foo/bar.js', false ),
165 array( 'User:Foo', false ),
166 array( 'User:Foo.js', false ),
167 array( 'User:Foo/bar.js', false ),
168 array( 'User:Foo/bar.css', false ),
169 array( 'User talk:Foo/bar.css', false ),
170 array( 'User:Foo/bar.js.xxx', false ),
171 array( 'User:Foo/bar.xxx', false ),
172 array( 'MediaWiki:Foo.js', true ),
173 array( 'MediaWiki:Foo.css', true ),
174 array( 'MediaWiki:Foo.JS', false ),
175 array( 'MediaWiki:Foo.CSS', false ),
176 array( 'MediaWiki:Foo.css.xxx', false ),
177 array( 'TEST-JS:Foo', false ),
178 array( 'TEST-JS:Foo.js', false ),
183 * @dataProvider provideIsCssOrJsPage
185 public function testIsCssOrJsPage( $title, $expectedBool ) {
186 $title = Title
::newFromText( $title );
187 $this->assertEquals( $expectedBool, $title->isCssOrJsPage() );
191 public static function provideIsCssJsSubpage() {
193 array( 'Help:Foo', false ),
194 array( 'Help:Foo.js', false ),
195 array( 'Help:Foo/bar.js', false ),
196 array( 'User:Foo', false ),
197 array( 'User:Foo.js', false ),
198 array( 'User:Foo/bar.js', true ),
199 array( 'User:Foo/bar.css', true ),
200 array( 'User talk:Foo/bar.css', false ),
201 array( 'User:Foo/bar.js.xxx', false ),
202 array( 'User:Foo/bar.xxx', false ),
203 array( 'MediaWiki:Foo.js', false ),
204 array( 'User:Foo/bar.JS', false ),
205 array( 'User:Foo/bar.CSS', false ),
206 array( 'TEST-JS:Foo', false ),
207 array( 'TEST-JS:Foo.js', false ),
212 * @dataProvider provideIsCssJsSubpage
214 public function testIsCssJsSubpage( $title, $expectedBool ) {
215 $title = Title
::newFromText( $title );
216 $this->assertEquals( $expectedBool, $title->isCssJsSubpage() );
219 public static function provideIsCssSubpage() {
221 array( 'Help:Foo', false ),
222 array( 'Help:Foo.css', false ),
223 array( 'User:Foo', false ),
224 array( 'User:Foo.js', false ),
225 array( 'User:Foo.css', false ),
226 array( 'User:Foo/bar.js', false ),
227 array( 'User:Foo/bar.css', true ),
232 * @dataProvider provideIsCssSubpage
234 public function testIsCssSubpage( $title, $expectedBool ) {
235 $title = Title
::newFromText( $title );
236 $this->assertEquals( $expectedBool, $title->isCssSubpage() );
239 public static function provideIsJsSubpage() {
241 array( 'Help:Foo', false ),
242 array( 'Help:Foo.css', false ),
243 array( 'User:Foo', false ),
244 array( 'User:Foo.js', false ),
245 array( 'User:Foo.css', false ),
246 array( 'User:Foo/bar.js', true ),
247 array( 'User:Foo/bar.css', false ),
252 * @dataProvider provideIsJsSubpage
254 public function testIsJsSubpage( $title, $expectedBool ) {
255 $title = Title
::newFromText( $title );
256 $this->assertEquals( $expectedBool, $title->isJsSubpage() );
259 public static function provideIsWikitextPage() {
261 array( 'Help:Foo', true ),
262 array( 'Help:Foo.js', true ),
263 array( 'Help:Foo/bar.js', true ),
264 array( 'User:Foo', true ),
265 array( 'User:Foo.js', true ),
266 array( 'User:Foo/bar.js', false ),
267 array( 'User:Foo/bar.css', false ),
268 array( 'User talk:Foo/bar.css', true ),
269 array( 'User:Foo/bar.js.xxx', true ),
270 array( 'User:Foo/bar.xxx', true ),
271 array( 'MediaWiki:Foo.js', false ),
272 array( 'MediaWiki:Foo.css', false ),
273 array( 'MediaWiki:Foo/bar.css', false ),
274 array( 'User:Foo/bar.JS', true ),
275 array( 'User:Foo/bar.CSS', true ),
276 array( 'TEST-JS:Foo', false ),
277 array( 'TEST-JS:Foo.js', false ),
278 array( 'TEST-JS_TALK:Foo.js', true ),
283 * @dataProvider provideIsWikitextPage
285 public function testIsWikitextPage( $title, $expectedBool ) {
286 $title = Title
::newFromText( $title );
287 $this->assertEquals( $expectedBool, $title->isWikitextPage() );