3 class ResourceLoaderStartUpModuleTest
extends ResourceLoaderTestCase
{
5 public static function provideGetModuleRegistrations() {
8 'msg' => 'Empty registry',
11 mw.loader.addSource( {
12 "local": "/w/load.php"
14 mw.loader.register( [] );'
17 'msg' => 'Basic registry',
19 'test.blank' => new ResourceLoaderTestModule(),
22 mw.loader.addSource( {
23 "local": "/w/load.php"
33 'msg' => 'Group signature',
35 'test.blank' => new ResourceLoaderTestModule(),
36 'test.group.foo' => new ResourceLoaderTestModule( array( 'group' => 'x-foo' ) ),
37 'test.group.bar' => new ResourceLoaderTestModule( array( 'group' => 'x-bar' ) ),
40 mw.loader.addSource( {
41 "local": "/w/load.php"
63 'msg' => 'Different target (non-test should not be registered)',
65 'test.blank' => new ResourceLoaderTestModule(),
66 'test.target.foo' => new ResourceLoaderTestModule( array( 'targets' => array( 'x-foo' ) ) ),
69 mw.loader.addSource( {
70 "local": "/w/load.php"
80 'msg' => 'Foreign source',
83 'loadScript' => 'http://example.org/w/load.php',
84 'apiScript' => 'http://example.org/w/api.php',
88 'test.blank' => new ResourceLoaderTestModule( array( 'source' => 'example' ) ),
91 mw.loader.addSource( {
92 "local": "/w/load.php",
93 "example": "http://example.org/w/load.php"
106 'msg' => 'Conditional dependency function',
108 'test.x.core' => new ResourceLoaderTestModule(),
109 'test.x.polyfill' => new ResourceLoaderTestModule( array(
110 'skipFunction' => 'return true;'
112 'test.y.polyfill' => new ResourceLoaderTestModule( array(
120 'test.z.foo' => new ResourceLoaderTestModule( array(
121 'dependencies' => array(
129 mw.loader.addSource( {
130 "local": "/w/load.php"
132 mw.loader.register( [
151 "return !!( window.JSON \u0026\u0026 JSON.parse \u0026\u0026 JSON.stringify);"
165 // This may seem like an edge case, but a plain MediaWiki core install
166 // with a few extensions installed is likely far more complex than this
167 // even, not to mention an install like Wikipedia.
168 // TODO: Make this even more realistic.
169 'msg' => 'Advanced (everything combined)',
172 'loadScript' => 'http://example.org/w/load.php',
173 'apiScript' => 'http://example.org/w/api.php',
177 'test.blank' => new ResourceLoaderTestModule(),
178 'test.x.core' => new ResourceLoaderTestModule(),
179 'test.x.util' => new ResourceLoaderTestModule( array(
180 'dependencies' => array(
184 'test.x.foo' => new ResourceLoaderTestModule( array(
185 'dependencies' => array(
189 'test.x.bar' => new ResourceLoaderTestModule( array(
190 'dependencies' => array(
195 'test.x.quux' => new ResourceLoaderTestModule( array(
196 'dependencies' => array(
203 'test.group.foo.1' => new ResourceLoaderTestModule( array(
206 'test.group.foo.2' => new ResourceLoaderTestModule( array(
209 'test.group.bar.1' => new ResourceLoaderTestModule( array(
212 'test.group.bar.2' => new ResourceLoaderTestModule( array(
214 'source' => 'example',
216 'test.target.foo' => new ResourceLoaderTestModule( array(
217 'targets' => array( 'x-foo' ),
219 'test.target.bar' => new ResourceLoaderTestModule( array(
220 'source' => 'example',
221 'targets' => array( 'x-foo' ),
225 mw.loader.addSource( {
226 "local": "/w/load.php",
227 "example": "http://example.org/w/load.php"
229 mw.loader.register( [
299 * @dataProvider provideGetModuleRegistrations
300 * @covers ResourceLoaderStartUpModule::compileUnresolvedDependencies
301 * @covers ResourceLoaderStartUpModule::getModuleRegistrations
302 * @covers ResourceLoader::makeLoaderSourcesScript
303 * @covers ResourceLoader::makeLoaderRegisterScript
305 public function testGetModuleRegistrations( $case ) {
306 if ( isset( $case['sources'] ) ) {
307 $this->setMwGlobals( 'wgResourceLoaderSources', $case['sources'] );
310 $context = $this->getResourceLoaderContext();
311 $rl = $context->getResourceLoader();
313 $rl->register( $case['modules'] );
315 $module = new ResourceLoaderStartUpModule();
317 ltrim( $case['out'], "\n" ),
318 $module->getModuleRegistrations( $context ),
323 public static function provideRegistrations() {
326 'test.blank' => new ResourceLoaderTestModule(),
327 'test.min' => new ResourceLoaderTestModule( array(
334 'dependencies' => array(
342 * @dataProvider provideRegistrations
344 public function testRegistrationsMinified( $modules ) {
345 $this->setMwGlobals( 'wgResourceLoaderDebug', false );
347 $context = $this->getResourceLoaderContext();
348 $rl = $context->getResourceLoader();
349 $rl->register( $modules );
350 $module = new ResourceLoaderStartUpModule();
352 'mw.loader.addSource({"local":"/w/load.php"});' . "\n"
353 . 'mw.loader.register(['
354 . '["test.blank","wvTifjse"],'
355 . '["test.min","wvTifjse",[0],null,null,'
356 . '"return!!(window.JSON\u0026\u0026JSON.parse\u0026\u0026JSON.stringify);"'
358 $module->getModuleRegistrations( $context ),
364 * @dataProvider provideRegistrations
366 public function testRegistrationsUnminified( $modules ) {
367 $context = $this->getResourceLoaderContext();
368 $rl = $context->getResourceLoader();
369 $rl->register( $modules );
370 $module = new ResourceLoaderStartUpModule();
372 'mw.loader.addSource( {
373 "local": "/w/load.php"
375 mw.loader.register( [
388 "return !!( window.JSON \u0026\u0026 JSON.parse \u0026\u0026 JSON.stringify);"
391 $module->getModuleRegistrations( $context ),