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 // This may seem like an edge case, but a plain MediaWiki core install
120 // with a few extensions installed is likely far more complex than this
121 // even, not to mention an install like Wikipedia.
122 // TODO: Make this even more realistic.
123 'msg' => 'Advanced (everything combined)',
126 'loadScript' => 'http://example.org/w/load.php',
127 'apiScript' => 'http://example.org/w/api.php',
131 'test.blank' => new ResourceLoaderTestModule(),
132 'test.x.core' => new ResourceLoaderTestModule(),
133 'test.x.util' => new ResourceLoaderTestModule( array(
134 'dependencies' => array(
138 'test.x.foo' => new ResourceLoaderTestModule( array(
139 'dependencies' => array(
143 'test.x.bar' => new ResourceLoaderTestModule( array(
144 'dependencies' => array(
149 'test.x.quux' => new ResourceLoaderTestModule( array(
150 'dependencies' => array(
157 'test.group.foo.1' => new ResourceLoaderTestModule( array(
160 'test.group.foo.2' => new ResourceLoaderTestModule( array(
163 'test.group.bar.1' => new ResourceLoaderTestModule( array(
166 'test.group.bar.2' => new ResourceLoaderTestModule( array(
168 'source' => 'example',
170 'test.target.foo' => new ResourceLoaderTestModule( array(
171 'targets' => array( 'x-foo' ),
173 'test.target.bar' => new ResourceLoaderTestModule( array(
174 'source' => 'example',
175 'targets' => array( 'x-foo' ),
179 mw.loader.addSource( {
181 "loadScript": "/w/load.php",
182 "apiScript": "/w/api.php"
185 "loadScript": "http://example.org/w/load.php",
186 "apiScript": "http://example.org/w/api.php"
188 } );mw.loader.register( [
258 * @dataProvider provideGetModuleRegistrations
259 * @covers ResourceLoaderStartupModule::optimizeDependencies
260 * @covers ResourceLoaderStartUpModule::getModuleRegistrations
261 * @covers ResourceLoader::makeLoaderSourcesScript
262 * @covers ResourceLoader::makeLoaderRegisterScript
264 public function testGetModuleRegistrations( $case ) {
265 if ( isset( $case['sources'] ) ) {
266 $this->setMwGlobals( 'wgResourceLoaderSources', $case['sources'] );
269 $context = self
::getResourceLoaderContext();
270 $rl = $context->getResourceLoader();
272 $rl->register( $case['modules'] );
275 ltrim( $case['out'], "\n" ),
276 ResourceLoaderStartUpModule
::getModuleRegistrations( $context ),