4 * @group ContentHandler
6 class TitleMethodsTest
extends MediaWikiTestCase
{
8 public function setup() {
9 global $wgExtraNamespaces, $wgNamespaceContentModels, $wgContLang;
11 $wgExtraNamespaces[ 12302 ] = 'TEST-JS';
12 $wgExtraNamespaces[ 12303 ] = 'TEST-JS_TALK';
14 $wgNamespaceContentModels[ 12302 ] = CONTENT_MODEL_JAVASCRIPT
;
16 MWNamespace
::getCanonicalNamespaces( true ); # reset namespace cache
17 $wgContLang->resetNamespaces(); # reset namespace cache
20 public function teardown() {
21 global $wgExtraNamespaces, $wgNamespaceContentModels, $wgContLang;
23 unset( $wgExtraNamespaces[ 12302 ] );
24 unset( $wgExtraNamespaces[ 12303 ] );
26 unset( $wgNamespaceContentModels[ 12302 ] );
28 MWNamespace
::getCanonicalNamespaces( true ); # reset namespace cache
29 $wgContLang->resetNamespaces(); # reset namespace cache
32 public function dataEquals() {
34 array( 'Main Page', 'Main Page', true ),
35 array( 'Main Page', 'Not The Main Page', false ),
36 array( 'Main Page', 'Project:Main Page', false ),
37 array( 'File:Example.png', 'Image:Example.png', true ),
38 array( 'Special:Version', 'Special:Version', true ),
39 array( 'Special:Version', 'Special:Recentchanges', false ),
40 array( 'Special:Version', 'Main Page', false ),
45 * @dataProvider dataEquals
47 public function testEquals( $titleA, $titleB, $expectedBool ) {
48 $titleA = Title
::newFromText( $titleA );
49 $titleB = Title
::newFromText( $titleB );
51 $this->assertEquals( $expectedBool, $titleA->equals( $titleB ) );
52 $this->assertEquals( $expectedBool, $titleB->equals( $titleA ) );
55 public function dataInNamespace() {
57 array( 'Main Page', NS_MAIN
, true ),
58 array( 'Main Page', NS_TALK
, false ),
59 array( 'Main Page', NS_USER
, false ),
60 array( 'User:Foo', NS_USER
, true ),
61 array( 'User:Foo', NS_USER_TALK
, false ),
62 array( 'User:Foo', NS_TEMPLATE
, false ),
63 array( 'User_talk:Foo', NS_USER_TALK
, true ),
64 array( 'User_talk:Foo', NS_USER
, false ),
69 * @dataProvider dataInNamespace
71 public function testInNamespace( $title, $ns, $expectedBool ) {
72 $title = Title
::newFromText( $title );
73 $this->assertEquals( $expectedBool, $title->inNamespace( $ns ) );
76 public function testInNamespaces() {
77 $mainpage = Title
::newFromText( 'Main Page' );
78 $this->assertTrue( $mainpage->inNamespaces( NS_MAIN
, NS_USER
) );
79 $this->assertTrue( $mainpage->inNamespaces( array( NS_MAIN
, NS_USER
) ) );
80 $this->assertTrue( $mainpage->inNamespaces( array( NS_USER
, NS_MAIN
) ) );
81 $this->assertFalse( $mainpage->inNamespaces( array( NS_PROJECT
, NS_TEMPLATE
) ) );
84 public function dataHasSubjectNamespace() {
86 array( 'Main Page', NS_MAIN
, true ),
87 array( 'Main Page', NS_TALK
, true ),
88 array( 'Main Page', NS_USER
, false ),
89 array( 'User:Foo', NS_USER
, true ),
90 array( 'User:Foo', NS_USER_TALK
, true ),
91 array( 'User:Foo', NS_TEMPLATE
, false ),
92 array( 'User_talk:Foo', NS_USER_TALK
, true ),
93 array( 'User_talk:Foo', NS_USER
, true ),
98 * @dataProvider dataHasSubjectNamespace
100 public function testHasSubjectNamespace( $title, $ns, $expectedBool ) {
101 $title = Title
::newFromText( $title );
102 $this->assertEquals( $expectedBool, $title->hasSubjectNamespace( $ns ) );
105 public function dataGetContentModel() {
107 array( 'Foo', CONTENT_MODEL_WIKITEXT
),
108 array( 'Foo.js', CONTENT_MODEL_WIKITEXT
),
109 array( 'Foo/bar.js', CONTENT_MODEL_WIKITEXT
),
110 array( 'User:Foo', CONTENT_MODEL_WIKITEXT
),
111 array( 'User:Foo.js', CONTENT_MODEL_WIKITEXT
),
112 array( 'User:Foo/bar.js', CONTENT_MODEL_JAVASCRIPT
),
113 array( 'User:Foo/bar.css', CONTENT_MODEL_CSS
),
114 array( 'User talk:Foo/bar.css', CONTENT_MODEL_WIKITEXT
),
115 array( 'User:Foo/bar.js.xxx', CONTENT_MODEL_WIKITEXT
),
116 array( 'User:Foo/bar.xxx', CONTENT_MODEL_WIKITEXT
),
117 array( 'MediaWiki:Foo.js', CONTENT_MODEL_JAVASCRIPT
),
118 array( 'MediaWiki:Foo.css', CONTENT_MODEL_CSS
),
119 array( 'MediaWiki:Foo/bar.css', CONTENT_MODEL_CSS
),
120 array( 'MediaWiki:Foo.JS', CONTENT_MODEL_WIKITEXT
),
121 array( 'MediaWiki:Foo.CSS', CONTENT_MODEL_WIKITEXT
),
122 array( 'MediaWiki:Foo.css.xxx', CONTENT_MODEL_WIKITEXT
),
123 array( 'TEST-JS:Foo', CONTENT_MODEL_JAVASCRIPT
),
124 array( 'TEST-JS:Foo.js', CONTENT_MODEL_JAVASCRIPT
),
125 array( 'TEST-JS:Foo/bar.js', CONTENT_MODEL_JAVASCRIPT
),
126 array( 'TEST-JS_TALK:Foo.js', CONTENT_MODEL_WIKITEXT
),
131 * @dataProvider dataGetContentModel
133 public function testGetContentModel( $title, $expectedModelId ) {
134 $title = Title
::newFromText( $title );
135 $this->assertEquals( $expectedModelId, $title->getContentModel() );
139 * @dataProvider dataGetContentModel
141 public function testHasContentModel( $title, $expectedModelId ) {
142 $title = Title
::newFromText( $title );
143 $this->assertTrue( $title->hasContentModel( $expectedModelId ) );
146 public function dataIsCssOrJsPage() {
148 array( 'Foo', false ),
149 array( 'Foo.js', false ),
150 array( 'Foo/bar.js', false ),
151 array( 'User:Foo', false ),
152 array( 'User:Foo.js', false ),
153 array( 'User:Foo/bar.js', false ),
154 array( 'User:Foo/bar.css', false ),
155 array( 'User talk:Foo/bar.css', false ),
156 array( 'User:Foo/bar.js.xxx', false ),
157 array( 'User:Foo/bar.xxx', false ),
158 array( 'MediaWiki:Foo.js', true ),
159 array( 'MediaWiki:Foo.css', true ),
160 array( 'MediaWiki:Foo.JS', false ),
161 array( 'MediaWiki:Foo.CSS', false ),
162 array( 'MediaWiki:Foo.css.xxx', false ),
163 array( 'TEST-JS:Foo', false ),
164 array( 'TEST-JS:Foo.js', false ),
169 * @dataProvider dataIsCssOrJsPage
171 public function testIsCssOrJsPage( $title, $expectedBool ) {
172 $title = Title
::newFromText( $title );
173 $this->assertEquals( $expectedBool, $title->isCssOrJsPage() );
177 public function dataIsCssJsSubpage() {
179 array( 'Foo', false ),
180 array( 'Foo.js', false ),
181 array( 'Foo/bar.js', false ),
182 array( 'User:Foo', false ),
183 array( 'User:Foo.js', false ),
184 array( 'User:Foo/bar.js', true ),
185 array( 'User:Foo/bar.css', true ),
186 array( 'User talk:Foo/bar.css', false ),
187 array( 'User:Foo/bar.js.xxx', false ),
188 array( 'User:Foo/bar.xxx', false ),
189 array( 'MediaWiki:Foo.js', false ),
190 array( 'User:Foo/bar.JS', false ),
191 array( 'User:Foo/bar.CSS', false ),
192 array( 'TEST-JS:Foo', false ),
193 array( 'TEST-JS:Foo.js', false ),
198 * @dataProvider dataIsCssJsSubpage
200 public function testIsCssJsSubpage( $title, $expectedBool ) {
201 $title = Title
::newFromText( $title );
202 $this->assertEquals( $expectedBool, $title->isCssJsSubpage() );
205 public function dataIsCssSubpage() {
207 array( 'Foo', false ),
208 array( 'Foo.css', false ),
209 array( 'User:Foo', false ),
210 array( 'User:Foo.js', false ),
211 array( 'User:Foo.css', false ),
212 array( 'User:Foo/bar.js', false ),
213 array( 'User:Foo/bar.css', true ),
218 * @dataProvider dataIsCssSubpage
220 public function testIsCssSubpage( $title, $expectedBool ) {
221 $title = Title
::newFromText( $title );
222 $this->assertEquals( $expectedBool, $title->isCssSubpage() );
225 public function dataIsJsSubpage() {
227 array( 'Foo', false ),
228 array( 'Foo.css', false ),
229 array( 'User:Foo', false ),
230 array( 'User:Foo.js', false ),
231 array( 'User:Foo.css', false ),
232 array( 'User:Foo/bar.js', true ),
233 array( 'User:Foo/bar.css', false ),
238 * @dataProvider dataIsJsSubpage
240 public function testIsJsSubpage( $title, $expectedBool ) {
241 $title = Title
::newFromText( $title );
242 $this->assertEquals( $expectedBool, $title->isJsSubpage() );
245 public function dataIsWikitextPage() {
247 array( 'Foo', true ),
248 array( 'Foo.js', true ),
249 array( 'Foo/bar.js', true ),
250 array( 'User:Foo', true ),
251 array( 'User:Foo.js', true ),
252 array( 'User:Foo/bar.js', false ),
253 array( 'User:Foo/bar.css', false ),
254 array( 'User talk:Foo/bar.css', true ),
255 array( 'User:Foo/bar.js.xxx', true ),
256 array( 'User:Foo/bar.xxx', true ),
257 array( 'MediaWiki:Foo.js', false ),
258 array( 'MediaWiki:Foo.css', false ),
259 array( 'MediaWiki:Foo/bar.css', false ),
260 array( 'User:Foo/bar.JS', true ),
261 array( 'User:Foo/bar.CSS', true ),
262 array( 'TEST-JS:Foo', false ),
263 array( 'TEST-JS:Foo.js', false ),
264 array( 'TEST-JS_TALK:Foo.js', true ),
269 * @dataProvider dataIsWikitextPage
271 public function testIsWikitextPage( $title, $expectedBool ) {
272 $title = Title
::newFromText( $title );
273 $this->assertEquals( $expectedBool, $title->isWikitextPage() );