MediaWiki REL1_31
ExtensionRegistryTest.php
Go to the documentation of this file.
1<?php
2
7
8 private $dataDir;
9
10 public function setUp() {
11 parent::setUp();
12 $this->dataDir = __DIR__ . '/../../data/registration';
13 }
14
15 public function testQueue_invalid() {
16 $registry = new ExtensionRegistry();
17 $path = __DIR__ . '/doesnotexist.json';
18 $this->setExpectedException(
19 Exception::class,
20 "$path does not exist!"
21 );
22 $registry->queue( $path );
23 }
24
25 public function testQueue() {
26 $registry = new ExtensionRegistry();
27 $path = "{$this->dataDir}/good.json";
28 $registry->queue( $path );
29 $this->assertArrayHasKey(
30 $path,
31 $registry->getQueue()
32 );
33 $registry->clearQueue();
34 $this->assertEmpty( $registry->getQueue() );
35 }
36
37 public function testLoadFromQueue_empty() {
38 $registry = new ExtensionRegistry();
39 $registry->loadFromQueue();
40 $this->assertEmpty( $registry->getAllThings() );
41 }
42
43 public function testLoadFromQueue_late() {
44 $registry = new ExtensionRegistry();
45 $registry->finish();
46 $registry->queue( "{$this->dataDir}/good.json" );
47 $this->setExpectedException(
48 MWException::class,
49 "The following paths tried to load late: {$this->dataDir}/good.json"
50 );
51 $registry->loadFromQueue();
52 }
53
57 public function testExportExtractedDataGlobals( $desc, $before, $globals, $expected ) {
58 // Set globals for test
59 if ( $before ) {
60 foreach ( $before as $key => $value ) {
61 // mw prefixed globals does not exist normally
62 if ( substr( $key, 0, 2 ) == 'mw' ) {
63 $GLOBALS[$key] = $value;
64 } else {
65 $this->setMwGlobals( $key, $value );
66 }
67 }
68 }
69
70 $info = [
71 'globals' => $globals,
72 'callbacks' => [],
73 'defines' => [],
74 'credits' => [],
75 'attributes' => [],
76 'autoloaderPaths' => []
77 ];
78 $registry = new ExtensionRegistry();
79 $class = new ReflectionClass( ExtensionRegistry::class );
80 $method = $class->getMethod( 'exportExtractedData' );
81 $method->setAccessible( true );
82 $method->invokeArgs( $registry, [ $info ] );
83 foreach ( $expected as $name => $value ) {
84 $this->assertArrayHasKey( $name, $GLOBALS, $desc );
85 $this->assertEquals( $value, $GLOBALS[$name], $desc );
86 }
87
88 // Remove mw prefixed globals
89 if ( $before ) {
90 foreach ( $before as $key => $value ) {
91 if ( substr( $key, 0, 2 ) == 'mw' ) {
92 unset( $GLOBALS[$key] );
93 }
94 }
95 }
96 }
97
98 public static function provideExportExtractedDataGlobals() {
99 // "mwtest" prefix used instead of "$wg" to avoid potential conflicts
100 return [
101 [
102 'Simple non-array values',
103 [
104 'mwtestFooBarConfig' => true,
105 'mwtestFooBarConfig2' => 'string',
106 ],
107 [
108 'mwtestFooBarDefault' => 1234,
109 'mwtestFooBarConfig' => false,
110 ],
111 [
112 'mwtestFooBarConfig' => true,
113 'mwtestFooBarConfig2' => 'string',
114 'mwtestFooBarDefault' => 1234,
115 ],
116 ],
117 [
118 'No global already set, simple array',
119 null,
120 [
121 'mwtestDefaultOptions' => [
122 'foobar' => true,
123 ]
124 ],
125 [
126 'mwtestDefaultOptions' => [
127 'foobar' => true,
128 ]
129 ],
130 ],
131 [
132 'Global already set, simple array',
133 [
134 'mwtestDefaultOptions' => [
135 'foobar' => true,
136 'foo' => 'string'
137 ],
138 ],
139 [
140 'mwtestDefaultOptions' => [
141 'barbaz' => 12345,
142 'foobar' => false,
143 ],
144 ],
145 [
146 'mwtestDefaultOptions' => [
147 'barbaz' => 12345,
148 'foo' => 'string',
149 'foobar' => true,
150 ],
151 ]
152 ],
153 [
154 'Global already set, 1d array that appends',
155 [
156 'mwAvailableRights' => [
157 'foobar',
158 'foo'
159 ],
160 ],
161 [
162 'mwAvailableRights' => [
163 'barbaz',
164 ],
165 ],
166 [
167 'mwAvailableRights' => [
168 'barbaz',
169 'foobar',
170 'foo',
171 ],
172 ]
173 ],
174 [
175 'Global already set, array with integer keys',
176 [
177 'mwNamespacesFoo' => [
178 100 => true,
179 102 => false
180 ],
181 ],
182 [
183 'mwNamespacesFoo' => [
184 100 => false,
185 500 => true,
186 ExtensionRegistry::MERGE_STRATEGY => 'array_plus',
187 ],
188 ],
189 [
190 'mwNamespacesFoo' => [
191 100 => true,
192 102 => false,
193 500 => true,
194 ],
195 ]
196 ],
197 [
198 'No global already set, $wgHooks',
199 [
200 'wgHooks' => [],
201 ],
202 [
203 'wgHooks' => [
204 'FooBarEvent' => [
205 'FooBarClass::onFooBarEvent'
206 ],
207 ExtensionRegistry::MERGE_STRATEGY => 'array_merge_recursive'
208 ],
209 ],
210 [
211 'wgHooks' => [
212 'FooBarEvent' => [
213 'FooBarClass::onFooBarEvent'
214 ],
215 ],
216 ],
217 ],
218 [
219 'Global already set, $wgHooks',
220 [
221 'wgHooks' => [
222 'FooBarEvent' => [
223 'FooBarClass::onFooBarEvent'
224 ],
225 'BazBarEvent' => [
226 'FooBarClass::onBazBarEvent',
227 ],
228 ],
229 ],
230 [
231 'wgHooks' => [
232 'FooBarEvent' => [
233 'BazBarClass::onFooBarEvent',
234 ],
235 ExtensionRegistry::MERGE_STRATEGY => 'array_merge_recursive',
236 ],
237 ],
238 [
239 'wgHooks' => [
240 'FooBarEvent' => [
241 'FooBarClass::onFooBarEvent',
242 'BazBarClass::onFooBarEvent',
243 ],
244 'BazBarEvent' => [
245 'FooBarClass::onBazBarEvent',
246 ],
247 ],
248 ],
249 ],
250 [
251 'Global already set, $wgGroupPermissions',
252 [
253 'wgGroupPermissions' => [
254 'sysop' => [
255 'something' => true,
256 ],
257 'user' => [
258 'somethingtwo' => true,
259 ]
260 ],
261 ],
262 [
263 'wgGroupPermissions' => [
264 'customgroup' => [
265 'right' => true,
266 ],
267 'user' => [
268 'right' => true,
269 'somethingtwo' => false,
270 'nonduplicated' => true,
271 ],
272 ExtensionRegistry::MERGE_STRATEGY => 'array_plus_2d',
273 ],
274 ],
275 [
276 'wgGroupPermissions' => [
277 'customgroup' => [
278 'right' => true,
279 ],
280 'sysop' => [
281 'something' => true,
282 ],
283 'user' => [
284 'somethingtwo' => true,
285 'right' => true,
286 'nonduplicated' => true,
287 ]
288 ],
289 ],
290 ],
291 [
292 'False local setting should not be overridden (T100767)',
293 [
294 'mwtestT100767' => false,
295 ],
296 [
297 'mwtestT100767' => true,
298 ],
299 [
300 'mwtestT100767' => false,
301 ],
302 ],
303 [
304 'test array_replace_recursive',
305 [
306 'mwtestJsonConfigs' => [
307 'JsonZeroConfig' => [
308 'namespace' => 480,
309 'nsName' => 'Zero',
310 'isLocal' => true,
311 ],
312 ],
313 ],
314 [
315 'mwtestJsonConfigs' => [
316 'JsonZeroConfig' => [
317 'isLocal' => false,
318 'remote' => [
319 'username' => 'foo',
320 ],
321 ],
322 ExtensionRegistry::MERGE_STRATEGY => 'array_replace_recursive',
323 ],
324 ],
325 [
326 'mwtestJsonConfigs' => [
327 'JsonZeroConfig' => [
328 'namespace' => 480,
329 'nsName' => 'Zero',
330 'isLocal' => false,
331 'remote' => [
332 'username' => 'foo',
333 ],
334 ],
335 ],
336 ],
337 ],
338 [
339 'global is null before',
340 [
341 'NullGlobal' => null,
342 ],
343 [
344 'NullGlobal' => 'not-null'
345 ],
346 [
347 'NullGlobal' => null
348 ],
349 ],
350 ];
351 }
352}
$GLOBALS['IP']
testExportExtractedDataGlobals( $desc, $before, $globals, $expected)
provideExportExtractedDataGlobals
ExtensionRegistry class.
const MERGE_STRATEGY
Special key that defines the merge strategy.
setMwGlobals( $pairs, $value=null)
Sets a global, maintaining a stashed version of the previous global to be restored in tearDown.
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Allows to change the fields on the form that will be generated $name
Definition hooks.txt:302
processing should stop and the error should be shown to the user * false
Definition hooks.txt:187
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition injection.txt:37