Remove messages.inc, rebuildLanguage.php, writeMessagesArray.inc
[mediawiki.git] / tests / phpunit / includes / resourceloader / ResourceLoaderStartupModuleTest.php
blobc4412de6a7cba925106132c23b7dec5f09e48245
1 <?php
3 class ResourceLoaderStartupModuleTest extends ResourceLoaderTestCase {
5 public static function provideGetModuleRegistrations() {
6 return array(
7 array( array(
8 'msg' => 'Empty registry',
9 'modules' => array(),
10 'out' => '
11 mw.loader.addSource( {
12 "local": {
13 "loadScript": "/w/load.php",
14 "apiScript": "/w/api.php"
16 } );mw.loader.register( [] );'
17 ) ),
18 array( array(
19 'msg' => 'Basic registry',
20 'modules' => array(
21 'test.blank' => new ResourceLoaderTestModule(),
23 'out' => '
24 mw.loader.addSource( {
25 "local": {
26 "loadScript": "/w/load.php",
27 "apiScript": "/w/api.php"
29 } );mw.loader.register( [
31 "test.blank",
32 "1388534400"
34 ] );',
35 ) ),
36 array( array(
37 'msg' => 'Group signature',
38 'modules' => array(
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' ) ),
43 'out' => '
44 mw.loader.addSource( {
45 "local": {
46 "loadScript": "/w/load.php",
47 "apiScript": "/w/api.php"
49 } );mw.loader.register( [
51 "test.blank",
52 "1388534400"
55 "test.group.foo",
56 "1388534400",
57 [],
58 "x-foo"
61 "test.group.bar",
62 "1388534400",
63 [],
64 "x-bar"
66 ] );'
67 ) ),
68 array( array(
69 'msg' => 'Different target (non-test should not be registered)',
70 'modules' => array(
71 'test.blank' => new ResourceLoaderTestModule(),
72 'test.target.foo' => new ResourceLoaderTestModule( array( 'targets' => array( 'x-foo' ) ) ),
74 'out' => '
75 mw.loader.addSource( {
76 "local": {
77 "loadScript": "/w/load.php",
78 "apiScript": "/w/api.php"
80 } );mw.loader.register( [
82 "test.blank",
83 "1388534400"
85 ] );'
86 ) ),
87 array( array(
88 'msg' => 'Foreign source',
89 'sources' => array(
90 'example' => array(
91 'loadScript' => 'http://example.org/w/load.php',
92 'apiScript' => 'http://example.org/w/api.php',
95 'modules' => array(
96 'test.blank' => new ResourceLoaderTestModule( array( 'source' => 'example' ) ),
98 'out' => '
99 mw.loader.addSource( {
100 "local": {
101 "loadScript": "/w/load.php",
102 "apiScript": "/w/api.php"
104 "example": {
105 "loadScript": "http://example.org/w/load.php",
106 "apiScript": "http://example.org/w/api.php"
108 } );mw.loader.register( [
110 "test.blank",
111 "1388534400",
113 null,
114 "example"
116 ] );'
117 ) ),
118 array( array(
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)',
124 'sources' => array(
125 'example' => array(
126 'loadScript' => 'http://example.org/w/load.php',
127 'apiScript' => 'http://example.org/w/api.php',
130 'modules' => array(
131 'test.blank' => new ResourceLoaderTestModule(),
132 'test.x.core' => new ResourceLoaderTestModule(),
133 'test.x.util' => new ResourceLoaderTestModule( array(
134 'dependencies' => array(
135 'test.x.core',
137 ) ),
138 'test.x.foo' => new ResourceLoaderTestModule( array(
139 'dependencies' => array(
140 'test.x.core',
142 ) ),
143 'test.x.bar' => new ResourceLoaderTestModule( array(
144 'dependencies' => array(
145 'test.x.core',
146 'test.x.util',
148 ) ),
149 'test.x.quux' => new ResourceLoaderTestModule( array(
150 'dependencies' => array(
151 'test.x.foo',
152 'test.x.bar',
153 'test.x.util',
154 'test.x.unknown',
156 ) ),
157 'test.group.foo.1' => new ResourceLoaderTestModule( array(
158 'group' => 'x-foo',
159 ) ),
160 'test.group.foo.2' => new ResourceLoaderTestModule( array(
161 'group' => 'x-foo',
162 ) ),
163 'test.group.bar.1' => new ResourceLoaderTestModule( array(
164 'group' => 'x-bar',
165 ) ),
166 'test.group.bar.2' => new ResourceLoaderTestModule( array(
167 'group' => 'x-bar',
168 'source' => 'example',
169 ) ),
170 'test.target.foo' => new ResourceLoaderTestModule( array(
171 'targets' => array( 'x-foo' ),
172 ) ),
173 'test.target.bar' => new ResourceLoaderTestModule( array(
174 'source' => 'example',
175 'targets' => array( 'x-foo' ),
176 ) ),
178 'out' => '
179 mw.loader.addSource( {
180 "local": {
181 "loadScript": "/w/load.php",
182 "apiScript": "/w/api.php"
184 "example": {
185 "loadScript": "http://example.org/w/load.php",
186 "apiScript": "http://example.org/w/api.php"
188 } );mw.loader.register( [
190 "test.blank",
191 "1388534400"
194 "test.x.core",
195 "1388534400"
198 "test.x.util",
199 "1388534400",
201 "test.x.core"
205 "test.x.foo",
206 "1388534400",
208 "test.x.core"
212 "test.x.bar",
213 "1388534400",
215 "test.x.util"
219 "test.x.quux",
220 "1388534400",
222 "test.x.foo",
223 "test.x.bar",
224 "test.x.unknown"
228 "test.group.foo.1",
229 "1388534400",
231 "x-foo"
234 "test.group.foo.2",
235 "1388534400",
237 "x-foo"
240 "test.group.bar.1",
241 "1388534400",
243 "x-bar"
246 "test.group.bar.2",
247 "1388534400",
249 "x-bar",
250 "example"
252 ] );'
253 ) ),
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'] );
274 $this->assertEquals(
275 ltrim( $case['out'], "\n" ),
276 ResourceLoaderStartUpModule::getModuleRegistrations( $context ),
277 $case['msg']