MediaWiki  1.23.8
ResourceLoaderStartupModuleTest.php
Go to the documentation of this file.
1 <?php
2 
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  ),
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  ) ),
176  ),
177  'out' => '
178 mw.loader.addSource( {
179  "local": {
180  "loadScript": "/w/load.php",
181  "apiScript": "/w/api.php"
182  },
183  "example": {
184  "loadScript": "http://example.org/w/load.php",
185  "apiScript": "http://example.org/w/api.php"
186  }
187 } );mw.loader.register( [
188  [
189  "test.blank",
190  "1388534400"
191  ],
192  [
193  "test.x.core",
194  "1388534400"
195  ],
196  [
197  "test.x.util",
198  "1388534400",
199  [
200  "test.x.core"
201  ]
202  ],
203  [
204  "test.x.foo",
205  "1388534400",
206  [
207  "test.x.core"
208  ]
209  ],
210  [
211  "test.x.bar",
212  "1388534400",
213  [
214  "test.x.core",
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.util"
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 
261  public function testGetModuleRegistrations( $case ) {
262  if ( isset( $case['sources'] ) ) {
263  $this->setMwGlobals( 'wgResourceLoaderSources', $case['sources'] );
264  }
265 
266  $context = self::getResourceLoaderContext();
267  $rl = $context->getResourceLoader();
268 
269  $rl->register( $case['modules'] );
270 
271  $this->assertEquals(
272  ltrim( $case['out'], "\n" ),
274  $case['msg']
275  );
276  }
277 
278 }
ResourceLoaderStartupModuleTest\testGetModuleRegistrations
testGetModuleRegistrations( $case)
@dataProvider provideGetModuleRegistrations @covers ResourceLoaderStartUpModule::getModuleRegistratio...
Definition: ResourceLoaderStartupModuleTest.php:261
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
ResourceLoaderStartUpModule\getModuleRegistrations
static getModuleRegistrations(ResourceLoaderContext $context)
Get registration code for all modules.
Definition: ResourceLoaderStartUpModule.php:126
ResourceLoaderTestCase\getResourceLoaderContext
static getResourceLoaderContext()
Definition: ResourceLoaderTestCase.php:5
MediaWikiTestCase\setMwGlobals
setMwGlobals( $pairs, $value=null)
Definition: MediaWikiTestCase.php:302
ResourceLoaderStartupModuleTest
Definition: ResourceLoaderStartupModuleTest.php:3
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
ResourceLoaderTestModule
Definition: ResourceLoaderTestCase.php:42
ResourceLoaderStartupModuleTest\provideGetModuleRegistrations
static provideGetModuleRegistrations()
Definition: ResourceLoaderStartupModuleTest.php:5
ResourceLoaderTestCase
Definition: ResourceLoaderTestCase.php:3