merged from master
[lhc/web/wiklou.git] / tests / phpunit / includes / TitleMethodsTest.php
1 <?php
2
3 class TitleMethodsTest extends MediaWikiTestCase {
4
5 public function setup() {
6 global $wgExtraNamespaces, $wgNamespaceContentModels;
7
8 $wgExtraNamespaces[ 12302 ] = 'TEST-JS';
9 $wgExtraNamespaces[ 12303 ] = 'TEST-JS_TALK';
10
11 $wgNamespaceContentModels[ 12302 ] = CONTENT_MODEL_JAVASCRIPT;
12 }
13
14 public function teardown() {
15 global $wgExtraNamespaces, $wgNamespaceContentModels;
16
17 unset( $wgExtraNamespaces[ 12302 ] );
18 unset( $wgExtraNamespaces[ 12303 ] );
19
20 unset( $wgNamespaceContentModels[ 12302 ] );
21 }
22
23 public function dataEquals() {
24 return array(
25 array( 'Main Page', 'Main Page', true ),
26 array( 'Main Page', 'Not The Main Page', false ),
27 array( 'Main Page', 'Project:Main Page', false ),
28 array( 'File:Example.png', 'Image:Example.png', true ),
29 array( 'Special:Version', 'Special:Version', true ),
30 array( 'Special:Version', 'Special:Recentchanges', false ),
31 array( 'Special:Version', 'Main Page', false ),
32 );
33 }
34
35 /**
36 * @dataProvider dataEquals
37 */
38 public function testEquals( $titleA, $titleB, $expectedBool ) {
39 $titleA = Title::newFromText( $titleA );
40 $titleB = Title::newFromText( $titleB );
41
42 $this->assertEquals( $expectedBool, $titleA->equals( $titleB ) );
43 $this->assertEquals( $expectedBool, $titleB->equals( $titleA ) );
44 }
45
46 public function dataInNamespace() {
47 return array(
48 array( 'Main Page', NS_MAIN, true ),
49 array( 'Main Page', NS_TALK, false ),
50 array( 'Main Page', NS_USER, false ),
51 array( 'User:Foo', NS_USER, true ),
52 array( 'User:Foo', NS_USER_TALK, false ),
53 array( 'User:Foo', NS_TEMPLATE, false ),
54 array( 'User_talk:Foo', NS_USER_TALK, true ),
55 array( 'User_talk:Foo', NS_USER, false ),
56 );
57 }
58
59 /**
60 * @dataProvider dataInNamespace
61 */
62 public function testInNamespace( $title, $ns, $expectedBool ) {
63 $title = Title::newFromText( $title );
64 $this->assertEquals( $expectedBool, $title->inNamespace( $ns ) );
65 }
66
67 public function testInNamespaces() {
68 $mainpage = Title::newFromText( 'Main Page' );
69 $this->assertTrue( $mainpage->inNamespaces( NS_MAIN, NS_USER ) );
70 $this->assertTrue( $mainpage->inNamespaces( array( NS_MAIN, NS_USER ) ) );
71 $this->assertTrue( $mainpage->inNamespaces( array( NS_USER, NS_MAIN ) ) );
72 $this->assertFalse( $mainpage->inNamespaces( array( NS_PROJECT, NS_TEMPLATE ) ) );
73 }
74
75 public function dataHasSubjectNamespace() {
76 return array(
77 array( 'Main Page', NS_MAIN, true ),
78 array( 'Main Page', NS_TALK, true ),
79 array( 'Main Page', NS_USER, false ),
80 array( 'User:Foo', NS_USER, true ),
81 array( 'User:Foo', NS_USER_TALK, true ),
82 array( 'User:Foo', NS_TEMPLATE, false ),
83 array( 'User_talk:Foo', NS_USER_TALK, true ),
84 array( 'User_talk:Foo', NS_USER, true ),
85 );
86 }
87
88 /**
89 * @dataProvider dataHasSubjectNamespace
90 */
91 public function testHasSubjectNamespace( $title, $ns, $expectedBool ) {
92 $title = Title::newFromText( $title );
93 $this->assertEquals( $expectedBool, $title->hasSubjectNamespace( $ns ) );
94 }
95
96
97 public function dataGetContentModelName() {
98 return array(
99 array( 'Foo', CONTENT_MODEL_WIKITEXT ),
100 array( 'Foo.js', CONTENT_MODEL_WIKITEXT ),
101 array( 'Foo/bar.js', CONTENT_MODEL_WIKITEXT ),
102 array( 'User:Foo', CONTENT_MODEL_WIKITEXT ),
103 array( 'User:Foo.js', CONTENT_MODEL_WIKITEXT ),
104 array( 'User:Foo/bar.js', CONTENT_MODEL_JAVASCRIPT ),
105 array( 'User:Foo/bar.css', CONTENT_MODEL_CSS ),
106 array( 'User talk:Foo/bar.css', CONTENT_MODEL_WIKITEXT ),
107 array( 'User:Foo/bar.js.xxx', CONTENT_MODEL_WIKITEXT ),
108 array( 'User:Foo/bar.xxx', CONTENT_MODEL_WIKITEXT ),
109 array( 'MediaWiki:Foo.js', CONTENT_MODEL_JAVASCRIPT ),
110 array( 'MediaWiki:Foo.css', CONTENT_MODEL_CSS ),
111 array( 'MediaWiki:Foo/bar.css', CONTENT_MODEL_CSS ),
112 array( 'MediaWiki:Foo.JS', CONTENT_MODEL_WIKITEXT ),
113 array( 'MediaWiki:Foo.CSS', CONTENT_MODEL_WIKITEXT ),
114 array( 'MediaWiki:Foo.css.xxx', CONTENT_MODEL_WIKITEXT ),
115 array( 'TEST-JS:Foo', CONTENT_MODEL_JAVASCRIPT ),
116 array( 'TEST-JS:Foo.js', CONTENT_MODEL_JAVASCRIPT ),
117 array( 'TEST-JS:Foo/bar.js', CONTENT_MODEL_JAVASCRIPT ),
118 array( 'TEST-JS_TALK:Foo.js', CONTENT_MODEL_WIKITEXT ),
119 );
120 }
121
122 /**
123 * @dataProvider dataGetContentModelName
124 */
125 public function testGetContentModelName( $title, $expectedModelName ) {
126 $title = Title::newFromText( $title );
127 $this->assertEquals( $expectedModelName, $title->getContentModelName() );
128 }
129
130 /**
131 * @dataProvider dataGetContentModelName
132 */
133 public function testHasContentModel( $title, $expectedModelName ) {
134 $title = Title::newFromText( $title );
135 $this->assertTrue( $title->hasContentModel( $expectedModelName ) );
136 }
137
138 public function dataIsCssOrJsPage() {
139 return array(
140 array( 'Foo', false ),
141 array( 'Foo.js', false ),
142 array( 'Foo/bar.js', false ),
143 array( 'User:Foo', false ),
144 array( 'User:Foo.js', false ),
145 array( 'User:Foo/bar.js', false ),
146 array( 'User:Foo/bar.css', false ),
147 array( 'User talk:Foo/bar.css', false ),
148 array( 'User:Foo/bar.js.xxx', false ),
149 array( 'User:Foo/bar.xxx', false ),
150 array( 'MediaWiki:Foo.js', true ),
151 array( 'MediaWiki:Foo.css', true ),
152 array( 'MediaWiki:Foo.JS', false ),
153 array( 'MediaWiki:Foo.CSS', false ),
154 array( 'MediaWiki:Foo.css.xxx', false ),
155 array( 'TEST-JS:Foo', false ),
156 array( 'TEST-JS:Foo.js', false ),
157 );
158 }
159
160 /**
161 * @dataProvider dataIsCssOrJsPage
162 */
163 public function testIsCssOrJsPage( $title, $expectedBool ) {
164 $title = Title::newFromText( $title );
165 $this->assertEquals( $expectedBool, $title->isCssOrJsPage() );
166 }
167
168
169 public function dataIsCssJsSubpage() {
170 return array(
171 array( 'Foo', false ),
172 array( 'Foo.js', false ),
173 array( 'Foo/bar.js', false ),
174 array( 'User:Foo', false ),
175 array( 'User:Foo.js', false ),
176 array( 'User:Foo/bar.js', true ),
177 array( 'User:Foo/bar.css', true ),
178 array( 'User talk:Foo/bar.css', false ),
179 array( 'User:Foo/bar.js.xxx', false ),
180 array( 'User:Foo/bar.xxx', false ),
181 array( 'MediaWiki:Foo.js', false ),
182 array( 'User:Foo/bar.JS', false ),
183 array( 'User:Foo/bar.CSS', false ),
184 array( 'TEST-JS:Foo', false ),
185 array( 'TEST-JS:Foo.js', false ),
186 );
187 }
188
189 /**
190 * @dataProvider dataIsCssJsSubpage
191 */
192 public function testIsCssJsSubpage( $title, $expectedBool ) {
193 $title = Title::newFromText( $title );
194 $this->assertEquals( $expectedBool, $title->isCssJsSubpage() );
195 }
196
197 public function dataIsCssSubpage() {
198 return array(
199 array( 'Foo', false ),
200 array( 'Foo.css', false ),
201 array( 'User:Foo', false ),
202 array( 'User:Foo.js', false ),
203 array( 'User:Foo.css', false ),
204 array( 'User:Foo/bar.js', false ),
205 array( 'User:Foo/bar.css', true ),
206 );
207 }
208
209 /**
210 * @dataProvider dataIsCssSubpage
211 */
212 public function testIsCssSubpage( $title, $expectedBool ) {
213 $title = Title::newFromText( $title );
214 $this->assertEquals( $expectedBool, $title->isCssSubpage() );
215 }
216
217 public function dataIsJsSubpage() {
218 return array(
219 array( 'Foo', false ),
220 array( 'Foo.css', false ),
221 array( 'User:Foo', false ),
222 array( 'User:Foo.js', false ),
223 array( 'User:Foo.css', false ),
224 array( 'User:Foo/bar.js', true ),
225 array( 'User:Foo/bar.css', false ),
226 );
227 }
228
229 /**
230 * @dataProvider dataIsJsSubpage
231 */
232 public function testIsJsSubpage( $title, $expectedBool ) {
233 $title = Title::newFromText( $title );
234 $this->assertEquals( $expectedBool, $title->isJsSubpage() );
235 }
236
237 public function dataIsWikitextPage() {
238 return array(
239 array( 'Foo', true ),
240 array( 'Foo.js', true ),
241 array( 'Foo/bar.js', true ),
242 array( 'User:Foo', true ),
243 array( 'User:Foo.js', true ),
244 array( 'User:Foo/bar.js', false ),
245 array( 'User:Foo/bar.css', false ),
246 array( 'User talk:Foo/bar.css', true ),
247 array( 'User:Foo/bar.js.xxx', true ),
248 array( 'User:Foo/bar.xxx', true ),
249 array( 'MediaWiki:Foo.js', false ),
250 array( 'MediaWiki:Foo.css', false ),
251 array( 'MediaWiki:Foo/bar.css', false ),
252 array( 'User:Foo/bar.JS', true ),
253 array( 'User:Foo/bar.CSS', true ),
254 array( 'TEST-JS:Foo', false ),
255 array( 'TEST-JS:Foo.js', false ),
256 array( 'TEST-JS_TALK:Foo.js', true ),
257 );
258 }
259
260 /**
261 * @dataProvider dataIsWikitextPage
262 */
263 public function testIsWikitextPage( $title, $expectedBool ) {
264 $title = Title::newFromText( $title );
265 $this->assertEquals( $expectedBool, $title->isWikitextPage() );
266 }
267
268 }