Remove unused 'XMPGetInfo' and 'XMPGetResults' hooks
[lhc/web/wiklou.git] / tests / phpunit / includes / resourceloader / ResourceLoaderStartUpModuleTest.php
1 <?php
2
3 class ResourceLoaderStartUpModuleTest extends ResourceLoaderTestCase {
4
5 public static function provideGetModuleRegistrations() {
6 return array(
7 array( array(
8 'msg' => 'Empty registry',
9 'modules' => array(),
10 'out' => '
11 mw.loader.addSource( {
12 "local": "/w/load.php"
13 } );mw.loader.register( [] );'
14 ) ),
15 array( array(
16 'msg' => 'Basic registry',
17 'modules' => array(
18 'test.blank' => new ResourceLoaderTestModule(),
19 ),
20 'out' => '
21 mw.loader.addSource( {
22 "local": "/w/load.php"
23 } );mw.loader.register( [
24 [
25 "test.blank",
26 1388534400
27 ]
28 ] );',
29 ) ),
30 array( array(
31 'msg' => 'Group signature',
32 'modules' => array(
33 'test.blank' => new ResourceLoaderTestModule(),
34 'test.group.foo' => new ResourceLoaderTestModule( array( 'group' => 'x-foo' ) ),
35 'test.group.bar' => new ResourceLoaderTestModule( array( 'group' => 'x-bar' ) ),
36 ),
37 'out' => '
38 mw.loader.addSource( {
39 "local": "/w/load.php"
40 } );mw.loader.register( [
41 [
42 "test.blank",
43 1388534400
44 ],
45 [
46 "test.group.foo",
47 1388534400,
48 [],
49 "x-foo"
50 ],
51 [
52 "test.group.bar",
53 1388534400,
54 [],
55 "x-bar"
56 ]
57 ] );'
58 ) ),
59 array( array(
60 'msg' => 'Different target (non-test should not be registered)',
61 'modules' => array(
62 'test.blank' => new ResourceLoaderTestModule(),
63 'test.target.foo' => new ResourceLoaderTestModule( array( 'targets' => array( 'x-foo' ) ) ),
64 ),
65 'out' => '
66 mw.loader.addSource( {
67 "local": "/w/load.php"
68 } );mw.loader.register( [
69 [
70 "test.blank",
71 1388534400
72 ]
73 ] );'
74 ) ),
75 array( array(
76 'msg' => 'Foreign source',
77 'sources' => array(
78 'example' => array(
79 'loadScript' => 'http://example.org/w/load.php',
80 'apiScript' => 'http://example.org/w/api.php',
81 ),
82 ),
83 'modules' => array(
84 'test.blank' => new ResourceLoaderTestModule( array( 'source' => 'example' ) ),
85 ),
86 'out' => '
87 mw.loader.addSource( {
88 "local": "/w/load.php",
89 "example": "http://example.org/w/load.php"
90 } );mw.loader.register( [
91 [
92 "test.blank",
93 1388534400,
94 [],
95 null,
96 "example"
97 ]
98 ] );'
99 ) ),
100 array( array(
101 'msg' => 'Conditional dependency function',
102 'modules' => array(
103 'test.x.core' => new ResourceLoaderTestModule(),
104 'test.x.polyfill' => new ResourceLoaderTestModule( array(
105 'skipFunction' => 'return true;'
106 ) ),
107 'test.y.polyfill' => new ResourceLoaderTestModule( array(
108 'skipFunction' =>
109 'return !!(' .
110 ' window.JSON &&' .
111 ' JSON.parse &&' .
112 ' JSON.stringify' .
113 ');'
114 ) ),
115 'test.z.foo' => new ResourceLoaderTestModule( array(
116 'dependencies' => array(
117 'test.x.core',
118 'test.x.polyfill',
119 'test.y.polyfill',
120 ),
121 ) ),
122 ),
123 'out' => '
124 mw.loader.addSource( {
125 "local": "/w/load.php"
126 } );mw.loader.register( [
127 [
128 "test.x.core",
129 1388534400
130 ],
131 [
132 "test.x.polyfill",
133 1388534400,
134 [],
135 null,
136 null,
137 "return true;"
138 ],
139 [
140 "test.y.polyfill",
141 1388534400,
142 [],
143 null,
144 null,
145 "return !!( window.JSON \u0026\u0026 JSON.parse \u0026\u0026 JSON.stringify);"
146 ],
147 [
148 "test.z.foo",
149 1388534400,
150 [
151 0,
152 1,
153 2
154 ]
155 ]
156 ] );',
157 ) ),
158 array( array(
159 // This may seem like an edge case, but a plain MediaWiki core install
160 // with a few extensions installed is likely far more complex than this
161 // even, not to mention an install like Wikipedia.
162 // TODO: Make this even more realistic.
163 'msg' => 'Advanced (everything combined)',
164 'sources' => array(
165 'example' => array(
166 'loadScript' => 'http://example.org/w/load.php',
167 'apiScript' => 'http://example.org/w/api.php',
168 ),
169 ),
170 'modules' => array(
171 'test.blank' => new ResourceLoaderTestModule(),
172 'test.x.core' => new ResourceLoaderTestModule(),
173 'test.x.util' => new ResourceLoaderTestModule( array(
174 'dependencies' => array(
175 'test.x.core',
176 ),
177 ) ),
178 'test.x.foo' => new ResourceLoaderTestModule( array(
179 'dependencies' => array(
180 'test.x.core',
181 ),
182 ) ),
183 'test.x.bar' => new ResourceLoaderTestModule( array(
184 'dependencies' => array(
185 'test.x.core',
186 'test.x.util',
187 ),
188 ) ),
189 'test.x.quux' => new ResourceLoaderTestModule( array(
190 'dependencies' => array(
191 'test.x.foo',
192 'test.x.bar',
193 'test.x.util',
194 'test.x.unknown',
195 ),
196 ) ),
197 'test.group.foo.1' => new ResourceLoaderTestModule( array(
198 'group' => 'x-foo',
199 ) ),
200 'test.group.foo.2' => new ResourceLoaderTestModule( array(
201 'group' => 'x-foo',
202 ) ),
203 'test.group.bar.1' => new ResourceLoaderTestModule( array(
204 'group' => 'x-bar',
205 ) ),
206 'test.group.bar.2' => new ResourceLoaderTestModule( array(
207 'group' => 'x-bar',
208 'source' => 'example',
209 ) ),
210 'test.target.foo' => new ResourceLoaderTestModule( array(
211 'targets' => array( 'x-foo' ),
212 ) ),
213 'test.target.bar' => new ResourceLoaderTestModule( array(
214 'source' => 'example',
215 'targets' => array( 'x-foo' ),
216 ) ),
217 ),
218 'out' => '
219 mw.loader.addSource( {
220 "local": "/w/load.php",
221 "example": "http://example.org/w/load.php"
222 } );mw.loader.register( [
223 [
224 "test.blank",
225 1388534400
226 ],
227 [
228 "test.x.core",
229 1388534400
230 ],
231 [
232 "test.x.util",
233 1388534400,
234 [
235 1
236 ]
237 ],
238 [
239 "test.x.foo",
240 1388534400,
241 [
242 1
243 ]
244 ],
245 [
246 "test.x.bar",
247 1388534400,
248 [
249 2
250 ]
251 ],
252 [
253 "test.x.quux",
254 1388534400,
255 [
256 3,
257 4,
258 "test.x.unknown"
259 ]
260 ],
261 [
262 "test.group.foo.1",
263 1388534400,
264 [],
265 "x-foo"
266 ],
267 [
268 "test.group.foo.2",
269 1388534400,
270 [],
271 "x-foo"
272 ],
273 [
274 "test.group.bar.1",
275 1388534400,
276 [],
277 "x-bar"
278 ],
279 [
280 "test.group.bar.2",
281 1388534400,
282 [],
283 "x-bar",
284 "example"
285 ]
286 ] );'
287 ) ),
288 );
289 }
290
291 /**
292 * @dataProvider provideGetModuleRegistrations
293 * @covers ResourceLoaderStartUpModule::compileUnresolvedDependencies
294 * @covers ResourceLoaderStartUpModule::getModuleRegistrations
295 * @covers ResourceLoader::makeLoaderSourcesScript
296 * @covers ResourceLoader::makeLoaderRegisterScript
297 */
298 public function testGetModuleRegistrations( $case ) {
299 if ( isset( $case['sources'] ) ) {
300 $this->setMwGlobals( 'wgResourceLoaderSources', $case['sources'] );
301 }
302
303 $context = $this->getResourceLoaderContext();
304 $rl = $context->getResourceLoader();
305
306 $rl->register( $case['modules'] );
307
308 $module = new ResourceLoaderStartUpModule();
309 $this->assertEquals(
310 ltrim( $case['out'], "\n" ),
311 $module->getModuleRegistrations( $context ),
312 $case['msg']
313 );
314 }
315
316 public static function provideRegistrations() {
317 return array(
318 array( array(
319 'test.blank' => new ResourceLoaderTestModule(),
320 'test.min' => new ResourceLoaderTestModule( array(
321 'skipFunction' =>
322 'return !!(' .
323 ' window.JSON &&' .
324 ' JSON.parse &&' .
325 ' JSON.stringify' .
326 ');',
327 'dependencies' => array(
328 'test.blank',
329 ),
330 ) ),
331 ) )
332 );
333 }
334 /**
335 * @dataProvider provideRegistrations
336 */
337 public function testRegistrationsMinified( $modules ) {
338 $this->setMwGlobals( 'wgResourceLoaderDebug', false );
339
340 $context = $this->getResourceLoaderContext();
341 $rl = $context->getResourceLoader();
342 $rl->register( $modules );
343 $module = new ResourceLoaderStartUpModule();
344 $this->assertEquals(
345 'mw.loader.addSource({"local":"/w/load.php"});'
346 . 'mw.loader.register(['
347 . '["test.blank",1388534400],'
348 . '["test.min",1388534400,[0],null,null,'
349 . '"return!!(window.JSON\u0026\u0026JSON.parse\u0026\u0026JSON.stringify);"'
350 . ']]);',
351 $module->getModuleRegistrations( $context ),
352 'Minified output'
353 );
354 }
355
356 /**
357 * @dataProvider provideRegistrations
358 */
359 public function testRegistrationsUnminified( $modules ) {
360 $context = $this->getResourceLoaderContext();
361 $rl = $context->getResourceLoader();
362 $rl->register( $modules );
363 $module = new ResourceLoaderStartUpModule();
364 $this->assertEquals(
365 'mw.loader.addSource( {
366 "local": "/w/load.php"
367 } );mw.loader.register( [
368 [
369 "test.blank",
370 1388534400
371 ],
372 [
373 "test.min",
374 1388534400,
375 [
376 0
377 ],
378 null,
379 null,
380 "return !!( window.JSON \u0026\u0026 JSON.parse \u0026\u0026 JSON.stringify);"
381 ]
382 ] );',
383 $module->getModuleRegistrations( $context ),
384 'Unminified output'
385 );
386 }
387
388 }