3 class ResourceLoaderStartUpModuleTest
extends ResourceLoaderTestCase
{
5 // Version hash for a blank file module.
6 // Result of ResourceLoader::makeHash(), ResourceLoaderTestModule
7 // and ResourceLoaderFileModule::getDefinitionSummary().
8 protected static $blankVersion = '09p30q0';
10 protected static function expandPlaceholders( $text ) {
11 return strtr( $text, [
12 '{blankVer}' => self
::$blankVersion
16 public static function provideGetModuleRegistrations() {
19 'msg' => 'Empty registry',
22 mw.loader.addSource( {
23 "local": "/w/load.php"
25 mw.loader.register( [] );'
28 'msg' => 'Basic registry',
30 'test.blank' => new ResourceLoaderTestModule(),
33 mw.loader.addSource( {
34 "local": "/w/load.php"
44 'msg' => 'Group signature',
46 'test.blank' => new ResourceLoaderTestModule(),
47 'test.group.foo' => new ResourceLoaderTestModule( [ 'group' => 'x-foo' ] ),
48 'test.group.bar' => new ResourceLoaderTestModule( [ 'group' => 'x-bar' ] ),
51 mw.loader.addSource( {
52 "local": "/w/load.php"
74 'msg' => 'Different target (non-test should not be registered)',
76 'test.blank' => new ResourceLoaderTestModule(),
77 'test.target.foo' => new ResourceLoaderTestModule( [ 'targets' => [ 'x-foo' ] ] ),
80 mw.loader.addSource( {
81 "local": "/w/load.php"
91 'msg' => 'Foreign source',
94 'loadScript' => 'http://example.org/w/load.php',
95 'apiScript' => 'http://example.org/w/api.php',
99 'test.blank' => new ResourceLoaderTestModule( [ 'source' => 'example' ] ),
102 mw.loader.addSource( {
103 "local": "/w/load.php",
104 "example": "http://example.org/w/load.php"
106 mw.loader.register( [
117 'msg' => 'Conditional dependency function',
119 'test.x.core' => new ResourceLoaderTestModule(),
120 'test.x.polyfill' => new ResourceLoaderTestModule( [
121 'skipFunction' => 'return true;'
123 'test.y.polyfill' => new ResourceLoaderTestModule( [
131 'test.z.foo' => new ResourceLoaderTestModule( [
140 mw.loader.addSource( {
141 "local": "/w/load.php"
143 mw.loader.register( [
162 "return !!( window.JSON \u0026\u0026 JSON.parse \u0026\u0026 JSON.stringify);"
176 // This may seem like an edge case, but a plain MediaWiki core install
177 // with a few extensions installed is likely far more complex than this
178 // even, not to mention an install like Wikipedia.
179 // TODO: Make this even more realistic.
180 'msg' => 'Advanced (everything combined)',
183 'loadScript' => 'http://example.org/w/load.php',
184 'apiScript' => 'http://example.org/w/api.php',
188 'test.blank' => new ResourceLoaderTestModule(),
189 'test.x.core' => new ResourceLoaderTestModule(),
190 'test.x.util' => new ResourceLoaderTestModule( [
195 'test.x.foo' => new ResourceLoaderTestModule( [
200 'test.x.bar' => new ResourceLoaderTestModule( [
206 'test.x.quux' => new ResourceLoaderTestModule( [
214 'test.group.foo.1' => new ResourceLoaderTestModule( [
217 'test.group.foo.2' => new ResourceLoaderTestModule( [
220 'test.group.bar.1' => new ResourceLoaderTestModule( [
223 'test.group.bar.2' => new ResourceLoaderTestModule( [
225 'source' => 'example',
227 'test.target.foo' => new ResourceLoaderTestModule( [
228 'targets' => [ 'x-foo' ],
230 'test.target.bar' => new ResourceLoaderTestModule( [
231 'source' => 'example',
232 'targets' => [ 'x-foo' ],
236 mw.loader.addSource( {
237 "local": "/w/load.php",
238 "example": "http://example.org/w/load.php"
240 mw.loader.register( [
310 * @dataProvider provideGetModuleRegistrations
311 * @covers ResourceLoaderStartUpModule::compileUnresolvedDependencies
312 * @covers ResourceLoaderStartUpModule::getModuleRegistrations
313 * @covers ResourceLoader::makeLoaderRegisterScript
315 public function testGetModuleRegistrations( $case ) {
316 if ( isset( $case['sources'] ) ) {
317 $this->setMwGlobals( 'wgResourceLoaderSources', $case['sources'] );
320 $context = $this->getResourceLoaderContext();
321 $rl = $context->getResourceLoader();
322 $rl->register( $case['modules'] );
323 $module = new ResourceLoaderStartUpModule();
324 $out = ltrim( $case['out'], "\n" );
327 self
::expandPlaceholders( $out ),
328 $module->getModuleRegistrations( $context ),
333 public static function provideRegistrations() {
336 'test.blank' => new ResourceLoaderTestModule(),
337 'test.min' => new ResourceLoaderTestModule( [
352 * @dataProvider provideRegistrations
354 public function testRegistrationsMinified( $modules ) {
355 $this->setMwGlobals( 'wgResourceLoaderDebug', false );
357 $context = $this->getResourceLoaderContext();
358 $rl = $context->getResourceLoader();
359 $rl->register( $modules );
360 $module = new ResourceLoaderStartUpModule();
361 $out = 'mw.loader.addSource({"local":"/w/load.php"});' . "\n"
362 . 'mw.loader.register(['
363 . '["test.blank","{blankVer}"],'
364 . '["test.min","{blankVer}",[0],null,null,'
365 . '"return!!(window.JSON\u0026\u0026JSON.parse\u0026\u0026JSON.stringify);"'
369 self
::expandPlaceholders( $out ),
370 $module->getModuleRegistrations( $context ),
376 * @dataProvider provideRegistrations
378 public function testRegistrationsUnminified( $modules ) {
379 $context = $this->getResourceLoaderContext();
380 $rl = $context->getResourceLoader();
381 $rl->register( $modules );
382 $module = new ResourceLoaderStartUpModule();
384 'mw.loader.addSource( {
385 "local": "/w/load.php"
387 mw.loader.register( [
400 "return !!( window.JSON \u0026\u0026 JSON.parse \u0026\u0026 JSON.stringify);"
405 self
::expandPlaceholders( $out ),
406 $module->getModuleRegistrations( $context ),