Pass phpcs-strict on some test files (10/11)
[mediawiki.git] / tests / phpunit / includes / resourceloader / ResourceLoaderStartupModuleTest.php
blob5b51ef89375ac1cba8369536c171938eb28df704
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',
155 ) ),
156 'test.group.foo.1' => new ResourceLoaderTestModule( array(
157 'group' => 'x-foo',
158 ) ),
159 'test.group.foo.2' => new ResourceLoaderTestModule( array(
160 'group' => 'x-foo',
161 ) ),
162 'test.group.bar.1' => new ResourceLoaderTestModule( array(
163 'group' => 'x-bar',
164 ) ),
165 'test.group.bar.2' => new ResourceLoaderTestModule( array(
166 'group' => 'x-bar',
167 'source' => 'example',
168 ) ),
169 'test.target.foo' => new ResourceLoaderTestModule( array(
170 'targets' => array( 'x-foo' ),
171 ) ),
172 'test.target.bar' => new ResourceLoaderTestModule( array(
173 'source' => 'example',
174 'targets' => array( 'x-foo' ),
175 ) ),
177 'out' => '
178 mw.loader.addSource( {
179 "local": {
180 "loadScript": "/w/load.php",
181 "apiScript": "/w/api.php"
183 "example": {
184 "loadScript": "http://example.org/w/load.php",
185 "apiScript": "http://example.org/w/api.php"
187 } );mw.loader.register( [
189 "test.blank",
190 "1388534400"
193 "test.x.core",
194 "1388534400"
197 "test.x.util",
198 "1388534400",
200 "test.x.core"
204 "test.x.foo",
205 "1388534400",
207 "test.x.core"
211 "test.x.bar",
212 "1388534400",
214 "test.x.core",
215 "test.x.util"
219 "test.x.quux",
220 "1388534400",
222 "test.x.foo",
223 "test.x.bar",
224 "test.x.util"
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::getModuleRegistrations
261 public function testGetModuleRegistrations( $case ) {
262 if ( isset( $case['sources'] ) ) {
263 $this->setMwGlobals( 'wgResourceLoaderSources', $case['sources'] );
266 $context = self::getResourceLoaderContext();
267 $rl = $context->getResourceLoader();
269 $rl->register( $case['modules'] );
271 $this->assertEquals(
272 ltrim( $case['out'], "\n" ),
273 ResourceLoaderStartUpModule::getModuleRegistrations( $context ),
274 $case['msg']