3 class ResourceLoaderStartUpModuleTest
extends ResourceLoaderTestCase
{
5 protected static function expandPlaceholders( $text ) {
7 '{blankVer}' => self
::BLANK_VERSION
11 public static function provideGetModuleRegistrations() {
14 'msg' => 'Empty registry',
17 mw.loader.addSource( {
18 "local": "/w/load.php"
20 mw.loader.register( [] );'
23 'msg' => 'Basic registry',
25 'test.blank' => new ResourceLoaderTestModule(),
28 mw.loader.addSource( {
29 "local": "/w/load.php"
39 'msg' => 'Group signature',
41 'test.blank' => new ResourceLoaderTestModule(),
42 'test.group.foo' => new ResourceLoaderTestModule( [ 'group' => 'x-foo' ] ),
43 'test.group.bar' => new ResourceLoaderTestModule( [ 'group' => 'x-bar' ] ),
46 mw.loader.addSource( {
47 "local": "/w/load.php"
69 'msg' => 'Different target (non-test should not be registered)',
71 'test.blank' => new ResourceLoaderTestModule(),
72 'test.target.foo' => new ResourceLoaderTestModule( [ 'targets' => [ 'x-foo' ] ] ),
75 mw.loader.addSource( {
76 "local": "/w/load.php"
86 'msg' => 'Foreign source',
89 'loadScript' => 'http://example.org/w/load.php',
90 'apiScript' => 'http://example.org/w/api.php',
94 'test.blank' => new ResourceLoaderTestModule( [ 'source' => 'example' ] ),
97 mw.loader.addSource( {
98 "local": "/w/load.php",
99 "example": "http://example.org/w/load.php"
101 mw.loader.register( [
112 'msg' => 'Conditional dependency function',
114 'test.x.core' => new ResourceLoaderTestModule(),
115 'test.x.polyfill' => new ResourceLoaderTestModule( [
116 'skipFunction' => 'return true;'
118 'test.y.polyfill' => new ResourceLoaderTestModule( [
126 'test.z.foo' => new ResourceLoaderTestModule( [
135 mw.loader.addSource( {
136 "local": "/w/load.php"
138 mw.loader.register( [
157 "return !!( window.JSON \u0026\u0026 JSON.parse \u0026\u0026 JSON.stringify);"
171 // This may seem like an edge case, but a plain MediaWiki core install
172 // with a few extensions installed is likely far more complex than this
173 // even, not to mention an install like Wikipedia.
174 // TODO: Make this even more realistic.
175 'msg' => 'Advanced (everything combined)',
178 'loadScript' => 'http://example.org/w/load.php',
179 'apiScript' => 'http://example.org/w/api.php',
183 'test.blank' => new ResourceLoaderTestModule(),
184 'test.x.core' => new ResourceLoaderTestModule(),
185 'test.x.util' => new ResourceLoaderTestModule( [
190 'test.x.foo' => new ResourceLoaderTestModule( [
195 'test.x.bar' => new ResourceLoaderTestModule( [
201 'test.x.quux' => new ResourceLoaderTestModule( [
209 'test.group.foo.1' => new ResourceLoaderTestModule( [
212 'test.group.foo.2' => new ResourceLoaderTestModule( [
215 'test.group.bar.1' => new ResourceLoaderTestModule( [
218 'test.group.bar.2' => new ResourceLoaderTestModule( [
220 'source' => 'example',
222 'test.target.foo' => new ResourceLoaderTestModule( [
223 'targets' => [ 'x-foo' ],
225 'test.target.bar' => new ResourceLoaderTestModule( [
226 'source' => 'example',
227 'targets' => [ 'x-foo' ],
231 mw.loader.addSource( {
232 "local": "/w/load.php",
233 "example": "http://example.org/w/load.php"
235 mw.loader.register( [
305 * @dataProvider provideGetModuleRegistrations
306 * @covers ResourceLoaderStartUpModule::compileUnresolvedDependencies
307 * @covers ResourceLoaderStartUpModule::getModuleRegistrations
308 * @covers ResourceLoader::makeLoaderRegisterScript
310 public function testGetModuleRegistrations( $case ) {
311 if ( isset( $case['sources'] ) ) {
312 $this->setMwGlobals( 'wgResourceLoaderSources', $case['sources'] );
315 $context = $this->getResourceLoaderContext();
316 $rl = $context->getResourceLoader();
317 $rl->register( $case['modules'] );
318 $module = new ResourceLoaderStartUpModule();
319 $out = ltrim( $case['out'], "\n" );
322 self
::expandPlaceholders( $out ),
323 $module->getModuleRegistrations( $context ),
328 public static function provideRegistrations() {
331 'test.blank' => new ResourceLoaderTestModule(),
332 'test.min' => new ResourceLoaderTestModule( [
347 * @dataProvider provideRegistrations
349 public function testRegistrationsMinified( $modules ) {
350 $this->setMwGlobals( 'wgResourceLoaderDebug', false );
352 $context = $this->getResourceLoaderContext();
353 $rl = $context->getResourceLoader();
354 $rl->register( $modules );
355 $module = new ResourceLoaderStartUpModule();
356 $out = 'mw.loader.addSource({"local":"/w/load.php"});' . "\n"
357 . 'mw.loader.register(['
358 . '["test.blank","{blankVer}"],'
359 . '["test.min","{blankVer}",[0],null,null,'
360 . '"return!!(window.JSON\u0026\u0026JSON.parse\u0026\u0026JSON.stringify);"'
364 self
::expandPlaceholders( $out ),
365 $module->getModuleRegistrations( $context ),
371 * @dataProvider provideRegistrations
373 public function testRegistrationsUnminified( $modules ) {
374 $context = $this->getResourceLoaderContext();
375 $rl = $context->getResourceLoader();
376 $rl->register( $modules );
377 $module = new ResourceLoaderStartUpModule();
379 'mw.loader.addSource( {
380 "local": "/w/load.php"
382 mw.loader.register( [
395 "return !!( window.JSON \u0026\u0026 JSON.parse \u0026\u0026 JSON.stringify);"
400 self
::expandPlaceholders( $out ),
401 $module->getModuleRegistrations( $context ),