Merge "Make abstract Config class truly implementation-agnostic"
[lhc/web/wiklou.git] / tests / phpunit / includes / resourceloader / ResourceLoaderStartupModuleTest.php
1 <?php
2
3 class ResourceLoaderStartupModuleTest extends ResourceLoaderTestCase {
4
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"
15 }
16 } );mw.loader.register( [] );'
17 ) ),
18 array( array(
19 'msg' => 'Basic registry',
20 'modules' => array(
21 'test.blank' => new ResourceLoaderTestModule(),
22 ),
23 'out' => '
24 mw.loader.addSource( {
25 "local": {
26 "loadScript": "/w/load.php",
27 "apiScript": "/w/api.php"
28 }
29 } );mw.loader.register( [
30 [
31 "test.blank",
32 "1388534400"
33 ]
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' ) ),
42 ),
43 'out' => '
44 mw.loader.addSource( {
45 "local": {
46 "loadScript": "/w/load.php",
47 "apiScript": "/w/api.php"
48 }
49 } );mw.loader.register( [
50 [
51 "test.blank",
52 "1388534400"
53 ],
54 [
55 "test.group.foo",
56 "1388534400",
57 [],
58 "x-foo"
59 ],
60 [
61 "test.group.bar",
62 "1388534400",
63 [],
64 "x-bar"
65 ]
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' ) ) ),
73 ),
74 'out' => '
75 mw.loader.addSource( {
76 "local": {
77 "loadScript": "/w/load.php",
78 "apiScript": "/w/api.php"
79 }
80 } );mw.loader.register( [
81 [
82 "test.blank",
83 "1388534400"
84 ]
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',
93 ),
94 ),
95 'modules' => array(
96 'test.blank' => new ResourceLoaderTestModule( array( 'source' => 'example' ) ),
97 ),
98 'out' => '
99 mw.loader.addSource( {
100 "local": {
101 "loadScript": "/w/load.php",
102 "apiScript": "/w/api.php"
103 },
104 "example": {
105 "loadScript": "http://example.org/w/load.php",
106 "apiScript": "http://example.org/w/api.php"
107 }
108 } );mw.loader.register( [
109 [
110 "test.blank",
111 "1388534400",
112 [],
113 null,
114 "example"
115 ]
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',
128 ),
129 ),
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',
136 ),
137 ) ),
138 'test.x.foo' => new ResourceLoaderTestModule( array(
139 'dependencies' => array(
140 'test.x.core',
141 ),
142 ) ),
143 'test.x.bar' => new ResourceLoaderTestModule( array(
144 'dependencies' => array(
145 'test.x.core',
146 'test.x.util',
147 ),
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',
155 ),
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 ) ),
177 ),
178 'out' => '
179 mw.loader.addSource( {
180 "local": {
181 "loadScript": "/w/load.php",
182 "apiScript": "/w/api.php"
183 },
184 "example": {
185 "loadScript": "http://example.org/w/load.php",
186 "apiScript": "http://example.org/w/api.php"
187 }
188 } );mw.loader.register( [
189 [
190 "test.blank",
191 "1388534400"
192 ],
193 [
194 "test.x.core",
195 "1388534400"
196 ],
197 [
198 "test.x.util",
199 "1388534400",
200 [
201 "test.x.core"
202 ]
203 ],
204 [
205 "test.x.foo",
206 "1388534400",
207 [
208 "test.x.core"
209 ]
210 ],
211 [
212 "test.x.bar",
213 "1388534400",
214 [
215 "test.x.util"
216 ]
217 ],
218 [
219 "test.x.quux",
220 "1388534400",
221 [
222 "test.x.foo",
223 "test.x.bar",
224 "test.x.unknown"
225 ]
226 ],
227 [
228 "test.group.foo.1",
229 "1388534400",
230 [],
231 "x-foo"
232 ],
233 [
234 "test.group.foo.2",
235 "1388534400",
236 [],
237 "x-foo"
238 ],
239 [
240 "test.group.bar.1",
241 "1388534400",
242 [],
243 "x-bar"
244 ],
245 [
246 "test.group.bar.2",
247 "1388534400",
248 [],
249 "x-bar",
250 "example"
251 ]
252 ] );'
253 ) ),
254 );
255 }
256
257 /**
258 * @dataProvider provideGetModuleRegistrations
259 * @covers ResourceLoaderStartupModule::optimizeDependencies
260 * @covers ResourceLoaderStartUpModule::getModuleRegistrations
261 * @covers ResourceLoader::makeLoaderSourcesScript
262 * @covers ResourceLoader::makeLoaderRegisterScript
263 */
264 public function testGetModuleRegistrations( $case ) {
265 if ( isset( $case['sources'] ) ) {
266 $this->setMwGlobals( 'wgResourceLoaderSources', $case['sources'] );
267 }
268
269 $context = self::getResourceLoaderContext();
270 $rl = $context->getResourceLoader();
271
272 $rl->register( $case['modules'] );
273
274 $this->assertEquals(
275 ltrim( $case['out'], "\n" ),
276 ResourceLoaderStartUpModule::getModuleRegistrations( $context ),
277 $case['msg']
278 );
279 }
280
281 }