4 * @group ContentHandler
6 * @note: We don't make assumptions about the main namespace.
7 * But we do expect the Help namespace to contain Wikitext.
10 class TitleMethodsTest
extends MediaWikiTestCase
{
12 public function setup() {
13 global $wgExtraNamespaces, $wgNamespaceContentModels, $wgContLang;
15 $wgExtraNamespaces[ 12302 ] = 'TEST-JS';
16 $wgExtraNamespaces[ 12303 ] = 'TEST-JS_TALK';
18 $wgNamespaceContentModels[ 12302 ] = CONTENT_MODEL_JAVASCRIPT
;
20 MWNamespace
::getCanonicalNamespaces( true ); # reset namespace cache
21 $wgContLang->resetNamespaces(); # reset namespace cache
24 public function teardown() {
25 global $wgExtraNamespaces, $wgNamespaceContentModels, $wgContLang;
27 unset( $wgExtraNamespaces[ 12302 ] );
28 unset( $wgExtraNamespaces[ 12303 ] );
30 unset( $wgNamespaceContentModels[ 12302 ] );
32 MWNamespace
::getCanonicalNamespaces( true ); # reset namespace cache
33 $wgContLang->resetNamespaces(); # reset namespace cache
36 public function dataEquals() {
38 array( 'Main Page', 'Main Page', true ),
39 array( 'Main Page', 'Not The Main Page', false ),
40 array( 'Main Page', 'Project:Main Page', false ),
41 array( 'File:Example.png', 'Image:Example.png', true ),
42 array( 'Special:Version', 'Special:Version', true ),
43 array( 'Special:Version', 'Special:Recentchanges', false ),
44 array( 'Special:Version', 'Main Page', false ),
49 * @dataProvider dataEquals
51 public function testEquals( $titleA, $titleB, $expectedBool ) {
52 $titleA = Title
::newFromText( $titleA );
53 $titleB = Title
::newFromText( $titleB );
55 $this->assertEquals( $expectedBool, $titleA->equals( $titleB ) );
56 $this->assertEquals( $expectedBool, $titleB->equals( $titleA ) );
59 public function dataInNamespace() {
61 array( 'Main Page', NS_MAIN
, true ),
62 array( 'Main Page', NS_TALK
, false ),
63 array( 'Main Page', NS_USER
, false ),
64 array( 'User:Foo', NS_USER
, true ),
65 array( 'User:Foo', NS_USER_TALK
, false ),
66 array( 'User:Foo', NS_TEMPLATE
, false ),
67 array( 'User_talk:Foo', NS_USER_TALK
, true ),
68 array( 'User_talk:Foo', NS_USER
, false ),
73 * @dataProvider dataInNamespace
75 public function testInNamespace( $title, $ns, $expectedBool ) {
76 $title = Title
::newFromText( $title );
77 $this->assertEquals( $expectedBool, $title->inNamespace( $ns ) );
80 public function testInNamespaces() {
81 $mainpage = Title
::newFromText( 'Main Page' );
82 $this->assertTrue( $mainpage->inNamespaces( NS_MAIN
, NS_USER
) );
83 $this->assertTrue( $mainpage->inNamespaces( array( NS_MAIN
, NS_USER
) ) );
84 $this->assertTrue( $mainpage->inNamespaces( array( NS_USER
, NS_MAIN
) ) );
85 $this->assertFalse( $mainpage->inNamespaces( array( NS_PROJECT
, NS_TEMPLATE
) ) );
88 public function dataHasSubjectNamespace() {
90 array( 'Main Page', NS_MAIN
, true ),
91 array( 'Main Page', NS_TALK
, true ),
92 array( 'Main Page', NS_USER
, false ),
93 array( 'User:Foo', NS_USER
, true ),
94 array( 'User:Foo', NS_USER_TALK
, true ),
95 array( 'User:Foo', NS_TEMPLATE
, false ),
96 array( 'User_talk:Foo', NS_USER_TALK
, true ),
97 array( 'User_talk:Foo', NS_USER
, true ),
102 * @dataProvider dataHasSubjectNamespace
104 public function testHasSubjectNamespace( $title, $ns, $expectedBool ) {
105 $title = Title
::newFromText( $title );
106 $this->assertEquals( $expectedBool, $title->hasSubjectNamespace( $ns ) );
109 public function dataGetContentModel() {
111 array( 'Help:Foo', CONTENT_MODEL_WIKITEXT
),
112 array( 'Help:Foo.js', CONTENT_MODEL_WIKITEXT
),
113 array( 'Help:Foo/bar.js', CONTENT_MODEL_WIKITEXT
),
114 array( 'User:Foo', CONTENT_MODEL_WIKITEXT
),
115 array( 'User:Foo.js', CONTENT_MODEL_WIKITEXT
),
116 array( 'User:Foo/bar.js', CONTENT_MODEL_JAVASCRIPT
),
117 array( 'User:Foo/bar.css', CONTENT_MODEL_CSS
),
118 array( 'User talk:Foo/bar.css', CONTENT_MODEL_WIKITEXT
),
119 array( 'User:Foo/bar.js.xxx', CONTENT_MODEL_WIKITEXT
),
120 array( 'User:Foo/bar.xxx', CONTENT_MODEL_WIKITEXT
),
121 array( 'MediaWiki:Foo.js', CONTENT_MODEL_JAVASCRIPT
),
122 array( 'MediaWiki:Foo.css', CONTENT_MODEL_CSS
),
123 array( 'MediaWiki:Foo/bar.css', CONTENT_MODEL_CSS
),
124 array( 'MediaWiki:Foo.JS', CONTENT_MODEL_WIKITEXT
),
125 array( 'MediaWiki:Foo.CSS', CONTENT_MODEL_WIKITEXT
),
126 array( 'MediaWiki:Foo.css.xxx', CONTENT_MODEL_WIKITEXT
),
127 array( 'TEST-JS:Foo', CONTENT_MODEL_JAVASCRIPT
),
128 array( 'TEST-JS:Foo.js', CONTENT_MODEL_JAVASCRIPT
),
129 array( 'TEST-JS:Foo/bar.js', CONTENT_MODEL_JAVASCRIPT
),
130 array( 'TEST-JS_TALK:Foo.js', CONTENT_MODEL_WIKITEXT
),
135 * @dataProvider dataGetContentModel
137 public function testGetContentModel( $title, $expectedModelId ) {
138 $title = Title
::newFromText( $title );
139 $this->assertEquals( $expectedModelId, $title->getContentModel() );
143 * @dataProvider dataGetContentModel
145 public function testHasContentModel( $title, $expectedModelId ) {
146 $title = Title
::newFromText( $title );
147 $this->assertTrue( $title->hasContentModel( $expectedModelId ) );
150 public function dataIsCssOrJsPage() {
152 array( 'Help:Foo', false ),
153 array( 'Help:Foo.js', false ),
154 array( 'Help:Foo/bar.js', false ),
155 array( 'User:Foo', false ),
156 array( 'User:Foo.js', false ),
157 array( 'User:Foo/bar.js', false ),
158 array( 'User:Foo/bar.css', false ),
159 array( 'User talk:Foo/bar.css', false ),
160 array( 'User:Foo/bar.js.xxx', false ),
161 array( 'User:Foo/bar.xxx', false ),
162 array( 'MediaWiki:Foo.js', true ),
163 array( 'MediaWiki:Foo.css', true ),
164 array( 'MediaWiki:Foo.JS', false ),
165 array( 'MediaWiki:Foo.CSS', false ),
166 array( 'MediaWiki:Foo.css.xxx', false ),
167 array( 'TEST-JS:Foo', false ),
168 array( 'TEST-JS:Foo.js', false ),
173 * @dataProvider dataIsCssOrJsPage
175 public function testIsCssOrJsPage( $title, $expectedBool ) {
176 $title = Title
::newFromText( $title );
177 $this->assertEquals( $expectedBool, $title->isCssOrJsPage() );
181 public function dataIsCssJsSubpage() {
183 array( 'Help:Foo', false ),
184 array( 'Help:Foo.js', false ),
185 array( 'Help:Foo/bar.js', false ),
186 array( 'User:Foo', false ),
187 array( 'User:Foo.js', false ),
188 array( 'User:Foo/bar.js', true ),
189 array( 'User:Foo/bar.css', true ),
190 array( 'User talk:Foo/bar.css', false ),
191 array( 'User:Foo/bar.js.xxx', false ),
192 array( 'User:Foo/bar.xxx', false ),
193 array( 'MediaWiki:Foo.js', false ),
194 array( 'User:Foo/bar.JS', false ),
195 array( 'User:Foo/bar.CSS', false ),
196 array( 'TEST-JS:Foo', false ),
197 array( 'TEST-JS:Foo.js', false ),
202 * @dataProvider dataIsCssJsSubpage
204 public function testIsCssJsSubpage( $title, $expectedBool ) {
205 $title = Title
::newFromText( $title );
206 $this->assertEquals( $expectedBool, $title->isCssJsSubpage() );
209 public function dataIsCssSubpage() {
211 array( 'Help:Foo', false ),
212 array( 'Help:Foo.css', false ),
213 array( 'User:Foo', false ),
214 array( 'User:Foo.js', false ),
215 array( 'User:Foo.css', false ),
216 array( 'User:Foo/bar.js', false ),
217 array( 'User:Foo/bar.css', true ),
222 * @dataProvider dataIsCssSubpage
224 public function testIsCssSubpage( $title, $expectedBool ) {
225 $title = Title
::newFromText( $title );
226 $this->assertEquals( $expectedBool, $title->isCssSubpage() );
229 public function dataIsJsSubpage() {
231 array( 'Help:Foo', false ),
232 array( 'Help:Foo.css', false ),
233 array( 'User:Foo', false ),
234 array( 'User:Foo.js', false ),
235 array( 'User:Foo.css', false ),
236 array( 'User:Foo/bar.js', true ),
237 array( 'User:Foo/bar.css', false ),
242 * @dataProvider dataIsJsSubpage
244 public function testIsJsSubpage( $title, $expectedBool ) {
245 $title = Title
::newFromText( $title );
246 $this->assertEquals( $expectedBool, $title->isJsSubpage() );
249 public function dataIsWikitextPage() {
251 array( 'Help:Foo', true ),
252 array( 'Help:Foo.js', true ),
253 array( 'Help:Foo/bar.js', true ),
254 array( 'User:Foo', true ),
255 array( 'User:Foo.js', true ),
256 array( 'User:Foo/bar.js', false ),
257 array( 'User:Foo/bar.css', false ),
258 array( 'User talk:Foo/bar.css', true ),
259 array( 'User:Foo/bar.js.xxx', true ),
260 array( 'User:Foo/bar.xxx', true ),
261 array( 'MediaWiki:Foo.js', false ),
262 array( 'MediaWiki:Foo.css', false ),
263 array( 'MediaWiki:Foo/bar.css', false ),
264 array( 'User:Foo/bar.JS', true ),
265 array( 'User:Foo/bar.CSS', true ),
266 array( 'TEST-JS:Foo', false ),
267 array( 'TEST-JS:Foo.js', false ),
268 array( 'TEST-JS_TALK:Foo.js', true ),
273 * @dataProvider dataIsWikitextPage
275 public function testIsWikitextPage( $title, $expectedBool ) {
276 $title = Title
::newFromText( $title );
277 $this->assertEquals( $expectedBool, $title->isWikitextPage() );