3 class ResourceLoaderStartupModuleTest
extends ResourceLoaderTestCase
{
5 public static function provideGetModuleRegistrations() {
8 'msg' => 'Empty registry',
11 mw.loader.addSource( {
13 "loadScript": "/w/load.php",
14 "apiScript": "/w/api.php"
16 } );mw.loader.register( [] );'
19 'msg' => 'Basic registry',
21 'test.blank' => new ResourceLoaderTestModule(),
24 mw.loader.addSource( {
26 "loadScript": "/w/load.php",
27 "apiScript": "/w/api.php"
29 } );mw.loader.register( [
37 'msg' => 'Group signature',
39 'test.blank' => new ResourceLoaderTestModule(),
40 'test.group.foo' => new ResourceLoaderTestModule( array( 'group' => 'x-foo' ) ),
41 'test.group.bar' => new ResourceLoaderTestModule( array( 'group' => 'x-bar' ) ),
44 mw.loader.addSource( {
46 "loadScript": "/w/load.php",
47 "apiScript": "/w/api.php"
49 } );mw.loader.register( [
69 'msg' => 'Different target (non-test should not be registered)',
71 'test.blank' => new ResourceLoaderTestModule(),
72 'test.target.foo' => new ResourceLoaderTestModule( array( 'targets' => array( 'x-foo' ) ) ),
75 mw.loader.addSource( {
77 "loadScript": "/w/load.php",
78 "apiScript": "/w/api.php"
80 } );mw.loader.register( [
88 'msg' => 'Foreign source',
91 'loadScript' => 'http://example.org/w/load.php',
92 'apiScript' => 'http://example.org/w/api.php',
96 'test.blank' => new ResourceLoaderTestModule( array( 'source' => 'example' ) ),
99 mw.loader.addSource( {
101 "loadScript": "/w/load.php",
102 "apiScript": "/w/api.php"
105 "loadScript": "http://example.org/w/load.php",
106 "apiScript": "http://example.org/w/api.php"
108 } );mw.loader.register( [
119 'msg' => 'Conditional dependency function',
121 'test.x.core' => new ResourceLoaderTestModule(),
122 'test.x.polyfill' => new ResourceLoaderTestModule( array(
123 'skipFunction' => 'return true;'
125 'test.y.polyfill' => new ResourceLoaderTestModule( array(
133 'test.z.foo' => new ResourceLoaderTestModule( array(
134 'dependencies' => array(
142 mw.loader.addSource( {
144 "loadScript": "/w/load.php",
145 "apiScript": "/w/api.php"
147 } );mw.loader.register( [
166 "return !!( window.JSON \u0026\u0026 JSON.parse \u0026\u0026 JSON.stringify);"
180 // This may seem like an edge case, but a plain MediaWiki core install
181 // with a few extensions installed is likely far more complex than this
182 // even, not to mention an install like Wikipedia.
183 // TODO: Make this even more realistic.
184 'msg' => 'Advanced (everything combined)',
187 'loadScript' => 'http://example.org/w/load.php',
188 'apiScript' => 'http://example.org/w/api.php',
192 'test.blank' => new ResourceLoaderTestModule(),
193 'test.x.core' => new ResourceLoaderTestModule(),
194 'test.x.util' => new ResourceLoaderTestModule( array(
195 'dependencies' => array(
199 'test.x.foo' => new ResourceLoaderTestModule( array(
200 'dependencies' => array(
204 'test.x.bar' => new ResourceLoaderTestModule( array(
205 'dependencies' => array(
210 'test.x.quux' => new ResourceLoaderTestModule( array(
211 'dependencies' => array(
218 'test.group.foo.1' => new ResourceLoaderTestModule( array(
221 'test.group.foo.2' => new ResourceLoaderTestModule( array(
224 'test.group.bar.1' => new ResourceLoaderTestModule( array(
227 'test.group.bar.2' => new ResourceLoaderTestModule( array(
229 'source' => 'example',
231 'test.target.foo' => new ResourceLoaderTestModule( array(
232 'targets' => array( 'x-foo' ),
234 'test.target.bar' => new ResourceLoaderTestModule( array(
235 'source' => 'example',
236 'targets' => array( 'x-foo' ),
240 mw.loader.addSource( {
242 "loadScript": "/w/load.php",
243 "apiScript": "/w/api.php"
246 "loadScript": "http://example.org/w/load.php",
247 "apiScript": "http://example.org/w/api.php"
249 } );mw.loader.register( [
319 * @dataProvider provideGetModuleRegistrations
320 * @covers ResourceLoaderStartupModule::optimizeDependencies
321 * @covers ResourceLoaderStartUpModule::getModuleRegistrations
322 * @covers ResourceLoader::makeLoaderSourcesScript
323 * @covers ResourceLoader::makeLoaderRegisterScript
325 public function testGetModuleRegistrations( $case ) {
326 if ( isset( $case['sources'] ) ) {
327 $this->setMwGlobals( 'wgResourceLoaderSources', $case['sources'] );
330 $context = self
::getResourceLoaderContext();
331 $rl = $context->getResourceLoader();
333 $rl->register( $case['modules'] );
335 $module = new ResourceLoaderStartUpModule();
337 ltrim( $case['out'], "\n" ),
338 $module->getModuleRegistrations( $context ),
343 public static function provideRegistrations() {
346 'test.blank' => new ResourceLoaderTestModule(),
347 'test.min' => new ResourceLoaderTestModule( array(
354 'dependencies' => array(
362 * @dataProvider provideRegistrations
364 public function testRegistrationsMinified( $modules ) {
365 $this->setMwGlobals( 'wgResourceLoaderDebug', false );
367 $context = self
::getResourceLoaderContext();
368 $rl = $context->getResourceLoader();
369 $rl->register( $modules );
370 $module = new ResourceLoaderStartUpModule();
372 'mw.loader.addSource({"local":{"loadScript":"/w/load.php","apiScript":"/w/api.php"}});'
373 . 'mw.loader.register(['
374 . '["test.blank","1388534400"],'
375 . '["test.min","1388534400",["test.blank"],null,"local",'
376 . '"return!!(window.JSON\u0026\u0026JSON.parse\u0026\u0026JSON.stringify);"'
378 $module->getModuleRegistrations( $context ),
384 * @dataProvider provideRegistrations
386 public function testRegistrationsUnminified( $modules ) {
387 $context = self
::getResourceLoaderContext();
388 $rl = $context->getResourceLoader();
389 $rl->register( $modules );
390 $module = new ResourceLoaderStartUpModule();
392 'mw.loader.addSource( {
394 "loadScript": "/w/load.php",
395 "apiScript": "/w/api.php"
397 } );mw.loader.register( [
410 "return !!( window.JSON \u0026\u0026 JSON.parse \u0026\u0026 JSON.stringify);"
413 $module->getModuleRegistrations( $context ),