MediaWiki  1.28.0
ExtensionRegistryTest.php
Go to the documentation of this file.
1 <?php
2 
4 
9  public function testExportExtractedDataGlobals( $desc, $before, $globals, $expected ) {
10  // Set globals for test
11  if ( $before ) {
12  foreach ( $before as $key => $value ) {
13  // mw prefixed globals does not exist normally
14  if ( substr( $key, 0, 2 ) == 'mw' ) {
15  $GLOBALS[$key] = $value;
16  } else {
17  $this->setMwGlobals( $key, $value );
18  }
19  }
20  }
21 
22  $info = [
23  'globals' => $globals,
24  'callbacks' => [],
25  'defines' => [],
26  'credits' => [],
27  'attributes' => [],
28  'autoloaderPaths' => []
29  ];
30  $registry = new ExtensionRegistry();
31  $class = new ReflectionClass( 'ExtensionRegistry' );
32  $method = $class->getMethod( 'exportExtractedData' );
33  $method->setAccessible( true );
34  $method->invokeArgs( $registry, [ $info ] );
35  foreach ( $expected as $name => $value ) {
36  $this->assertArrayHasKey( $name, $GLOBALS, $desc );
37  $this->assertEquals( $value, $GLOBALS[$name], $desc );
38  }
39 
40  // Remove mw prefixed globals
41  if ( $before ) {
42  foreach ( $before as $key => $value ) {
43  if ( substr( $key, 0, 2 ) == 'mw' ) {
44  unset( $GLOBALS[$key] );
45  }
46  }
47  }
48  }
49 
50  public static function provideExportExtractedDataGlobals() {
51  // "mwtest" prefix used instead of "$wg" to avoid potential conflicts
52  return [
53  [
54  'Simple non-array values',
55  [
56  'mwtestFooBarConfig' => true,
57  'mwtestFooBarConfig2' => 'string',
58  ],
59  [
60  'mwtestFooBarDefault' => 1234,
61  'mwtestFooBarConfig' => false,
62  ],
63  [
64  'mwtestFooBarConfig' => true,
65  'mwtestFooBarConfig2' => 'string',
66  'mwtestFooBarDefault' => 1234,
67  ],
68  ],
69  [
70  'No global already set, simple array',
71  null,
72  [
73  'mwtestDefaultOptions' => [
74  'foobar' => true,
75  ]
76  ],
77  [
78  'mwtestDefaultOptions' => [
79  'foobar' => true,
80  ]
81  ],
82  ],
83  [
84  'Global already set, simple array',
85  [
86  'mwtestDefaultOptions' => [
87  'foobar' => true,
88  'foo' => 'string'
89  ],
90  ],
91  [
92  'mwtestDefaultOptions' => [
93  'barbaz' => 12345,
94  'foobar' => false,
95  ],
96  ],
97  [
98  'mwtestDefaultOptions' => [
99  'barbaz' => 12345,
100  'foo' => 'string',
101  'foobar' => true,
102  ],
103  ]
104  ],
105  [
106  'Global already set, 1d array that appends',
107  [
108  'mwAvailableRights' => [
109  'foobar',
110  'foo'
111  ],
112  ],
113  [
114  'mwAvailableRights' => [
115  'barbaz',
116  ],
117  ],
118  [
119  'mwAvailableRights' => [
120  'barbaz',
121  'foobar',
122  'foo',
123  ],
124  ]
125  ],
126  [
127  'Global already set, array with integer keys',
128  [
129  'mwNamespacesFoo' => [
130  100 => true,
131  102 => false
132  ],
133  ],
134  [
135  'mwNamespacesFoo' => [
136  100 => false,
137  500 => true,
138  ExtensionRegistry::MERGE_STRATEGY => 'array_plus',
139  ],
140  ],
141  [
142  'mwNamespacesFoo' => [
143  100 => true,
144  102 => false,
145  500 => true,
146  ],
147  ]
148  ],
149  [
150  'No global already set, $wgHooks',
151  [
152  'wgHooks' => [],
153  ],
154  [
155  'wgHooks' => [
156  'FooBarEvent' => [
157  'FooBarClass::onFooBarEvent'
158  ],
159  ExtensionRegistry::MERGE_STRATEGY => 'array_merge_recursive'
160  ],
161  ],
162  [
163  'wgHooks' => [
164  'FooBarEvent' => [
165  'FooBarClass::onFooBarEvent'
166  ],
167  ],
168  ],
169  ],
170  [
171  'Global already set, $wgHooks',
172  [
173  'wgHooks' => [
174  'FooBarEvent' => [
175  'FooBarClass::onFooBarEvent'
176  ],
177  'BazBarEvent' => [
178  'FooBarClass::onBazBarEvent',
179  ],
180  ],
181  ],
182  [
183  'wgHooks' => [
184  'FooBarEvent' => [
185  'BazBarClass::onFooBarEvent',
186  ],
187  ExtensionRegistry::MERGE_STRATEGY => 'array_merge_recursive',
188  ],
189  ],
190  [
191  'wgHooks' => [
192  'FooBarEvent' => [
193  'FooBarClass::onFooBarEvent',
194  'BazBarClass::onFooBarEvent',
195  ],
196  'BazBarEvent' => [
197  'FooBarClass::onBazBarEvent',
198  ],
199  ],
200  ],
201  ],
202  [
203  'Global already set, $wgGroupPermissions',
204  [
205  'wgGroupPermissions' => [
206  'sysop' => [
207  'something' => true,
208  ],
209  'user' => [
210  'somethingtwo' => true,
211  ]
212  ],
213  ],
214  [
215  'wgGroupPermissions' => [
216  'customgroup' => [
217  'right' => true,
218  ],
219  'user' => [
220  'right' => true,
221  'somethingtwo' => false,
222  'nonduplicated' => true,
223  ],
224  ExtensionRegistry::MERGE_STRATEGY => 'array_plus_2d',
225  ],
226  ],
227  [
228  'wgGroupPermissions' => [
229  'customgroup' => [
230  'right' => true,
231  ],
232  'sysop' => [
233  'something' => true,
234  ],
235  'user' => [
236  'somethingtwo' => true,
237  'right' => true,
238  'nonduplicated' => true,
239  ]
240  ],
241  ],
242  ],
243  [
244  'False local setting should not be overridden (T100767)',
245  [
246  'mwtestT100767' => false,
247  ],
248  [
249  'mwtestT100767' => true,
250  ],
251  [
252  'mwtestT100767' => false,
253  ],
254  ],
255  [
256  'test array_replace_recursive',
257  [
258  'mwtestJsonConfigs' => [
259  'JsonZeroConfig' => [
260  'namespace' => 480,
261  'nsName' => 'Zero',
262  'isLocal' => false,
263  ],
264  ],
265  ],
266  [
267  'mwtestJsonConfigs' => [
268  'JsonZeroConfig' => [
269  'isLocal' => false,
270  'remote' => [
271  'username' => 'foo',
272  ],
273  ],
274  ExtensionRegistry::MERGE_STRATEGY => 'array_replace_recursive',
275  ],
276  ],
277  [
278  'mwtestJsonConfigs' => [
279  'JsonZeroConfig' => [
280  'namespace' => 480,
281  'nsName' => 'Zero',
282  'isLocal' => false,
283  'remote' => [
284  'username' => 'foo',
285  ],
286  ],
287  ],
288  ],
289  ],
290  ];
291  }
292 }
processing should stop and the error should be shown to the user * false
Definition: hooks.txt:189
$value
const MERGE_STRATEGY
Special key that defines the merge strategy.
$GLOBALS['IP']
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
Definition: distributors.txt:9
ExtensionRegistry class.
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:35
testExportExtractedDataGlobals($desc, $before, $globals, $expected)
ExtensionRegistry::exportExtractedData provideExportExtractedDataGlobals.
setMwGlobals($pairs, $value=null)
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:300