3 class ResourceLoaderStartupModuleTest
extends ResourceLoaderTestCase
{
5 public static function provideGetModuleRegistrations() {
8 'msg' => 'Empty registry',
11 mw.loader.addSource( {
12 "local": "/w/load.php"
13 } );mw.loader.register( [] );'
16 'msg' => 'Basic registry',
18 'test.blank' => new ResourceLoaderTestModule(),
21 mw.loader.addSource( {
22 "local": "/w/load.php"
23 } );mw.loader.register( [
31 'msg' => 'Group signature',
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' ) ),
38 mw.loader.addSource( {
39 "local": "/w/load.php"
40 } );mw.loader.register( [
60 'msg' => 'Different target (non-test should not be registered)',
62 'test.blank' => new ResourceLoaderTestModule(),
63 'test.target.foo' => new ResourceLoaderTestModule( array( 'targets' => array( 'x-foo' ) ) ),
66 mw.loader.addSource( {
67 "local": "/w/load.php"
68 } );mw.loader.register( [
76 'msg' => 'Foreign source',
79 'loadScript' => 'http://example.org/w/load.php',
80 'apiScript' => 'http://example.org/w/api.php',
84 'test.blank' => new ResourceLoaderTestModule( array( 'source' => 'example' ) ),
87 mw.loader.addSource( {
88 "local": "/w/load.php",
89 "example": "http://example.org/w/load.php"
90 } );mw.loader.register( [
101 'msg' => 'Conditional dependency function',
103 'test.x.core' => new ResourceLoaderTestModule(),
104 'test.x.polyfill' => new ResourceLoaderTestModule( array(
105 'skipFunction' => 'return true;'
107 'test.y.polyfill' => new ResourceLoaderTestModule( array(
115 'test.z.foo' => new ResourceLoaderTestModule( array(
116 'dependencies' => array(
124 mw.loader.addSource( {
125 "local": "/w/load.php"
126 } );mw.loader.register( [
145 "return !!( window.JSON \u0026\u0026 JSON.parse \u0026\u0026 JSON.stringify);"
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)',
166 'loadScript' => 'http://example.org/w/load.php',
167 'apiScript' => 'http://example.org/w/api.php',
171 'test.blank' => new ResourceLoaderTestModule(),
172 'test.x.core' => new ResourceLoaderTestModule(),
173 'test.x.util' => new ResourceLoaderTestModule( array(
174 'dependencies' => array(
178 'test.x.foo' => new ResourceLoaderTestModule( array(
179 'dependencies' => array(
183 'test.x.bar' => new ResourceLoaderTestModule( array(
184 'dependencies' => array(
189 'test.x.quux' => new ResourceLoaderTestModule( array(
190 'dependencies' => array(
197 'test.group.foo.1' => new ResourceLoaderTestModule( array(
200 'test.group.foo.2' => new ResourceLoaderTestModule( array(
203 'test.group.bar.1' => new ResourceLoaderTestModule( array(
206 'test.group.bar.2' => new ResourceLoaderTestModule( array(
208 'source' => 'example',
210 'test.target.foo' => new ResourceLoaderTestModule( array(
211 'targets' => array( 'x-foo' ),
213 'test.target.bar' => new ResourceLoaderTestModule( array(
214 'source' => 'example',
215 'targets' => array( 'x-foo' ),
219 mw.loader.addSource( {
220 "local": "/w/load.php",
221 "example": "http://example.org/w/load.php"
222 } );mw.loader.register( [
292 * @dataProvider provideGetModuleRegistrations
293 * @covers ResourceLoaderStartupModule::compileUnresolvedDependencies
294 * @covers ResourceLoaderStartUpModule::getModuleRegistrations
295 * @covers ResourceLoader::makeLoaderSourcesScript
296 * @covers ResourceLoader::makeLoaderRegisterScript
298 public function testGetModuleRegistrations( $case ) {
299 if ( isset( $case['sources'] ) ) {
300 $this->setMwGlobals( 'wgResourceLoaderSources', $case['sources'] );
303 $context = self
::getResourceLoaderContext();
304 $rl = $context->getResourceLoader();
306 $rl->register( $case['modules'] );
308 $module = new ResourceLoaderStartUpModule();
310 ltrim( $case['out'], "\n" ),
311 $module->getModuleRegistrations( $context ),
316 public static function provideRegistrations() {
319 'test.blank' => new ResourceLoaderTestModule(),
320 'test.min' => new ResourceLoaderTestModule( array(
327 'dependencies' => array(
335 * @dataProvider provideRegistrations
337 public function testRegistrationsMinified( $modules ) {
338 $this->setMwGlobals( 'wgResourceLoaderDebug', false );
340 $context = self
::getResourceLoaderContext();
341 $rl = $context->getResourceLoader();
342 $rl->register( $modules );
343 $module = new ResourceLoaderStartUpModule();
345 'mw.loader.addSource({"local":"/w/load.php"});'
346 . 'mw.loader.register(['
347 . '["test.blank","1388534400"],'
348 . '["test.min","1388534400",["test.blank"],null,"local",'
349 . '"return!!(window.JSON\u0026\u0026JSON.parse\u0026\u0026JSON.stringify);"'
351 $module->getModuleRegistrations( $context ),
357 * @dataProvider provideRegistrations
359 public function testRegistrationsUnminified( $modules ) {
360 $context = self
::getResourceLoaderContext();
361 $rl = $context->getResourceLoader();
362 $rl->register( $modules );
363 $module = new ResourceLoaderStartUpModule();
365 'mw.loader.addSource( {
366 "local": "/w/load.php"
367 } );mw.loader.register( [
380 "return !!( window.JSON \u0026\u0026 JSON.parse \u0026\u0026 JSON.stringify);"
383 $module->getModuleRegistrations( $context ),