Merge "Split classes in Import.php into separate files"
[lhc/web/wiklou.git] / tests / phpunit / includes / registration / ExtensionRegistryTest.php
1 <?php
2
3 class ExtensionRegistryTest extends MediaWikiTestCase {
4
5 /**
6 * @covers ExtensionRegistry::exportExtractedData
7 * @dataProvider provideExportExtractedDataGlobals
8 */
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 = array(
23 'globals' => $globals,
24 'callbacks' => array(),
25 'defines' => array(),
26 'credits' => array(),
27 'attributes' => array(),
28 );
29 $registry = new ExtensionRegistry();
30 $class = new ReflectionClass( 'ExtensionRegistry' );
31 $method = $class->getMethod( 'exportExtractedData' );
32 $method->setAccessible( true );
33 $method->invokeArgs( $registry, array( $info ) );
34 foreach ( $expected as $name => $value ) {
35 $this->assertArrayHasKey( $name, $GLOBALS, $desc );
36 $this->assertEquals( $value, $GLOBALS[$name], $desc );
37 }
38
39 // Remove mw prefixed globals
40 if ( $before ) {
41 foreach ( $before as $key => $value ) {
42 if ( substr( $key, 0, 2 ) == 'mw' ) {
43 unset( $GLOBALS[$key] );
44 }
45 }
46 }
47 }
48
49 public static function provideExportExtractedDataGlobals() {
50 // "mwtest" prefix used instead of "$wg" to avoid potential conflicts
51 return array(
52 array(
53 'Simple non-array values',
54 array(
55 'mwtestFooBarConfig' => true,
56 'mwtestFooBarConfig2' => 'string',
57 ),
58 array(
59 'mwtestFooBarDefault' => 1234,
60 'mwtestFooBarConfig' => false,
61 ),
62 array(
63 'mwtestFooBarConfig' => true,
64 'mwtestFooBarConfig2' => 'string',
65 'mwtestFooBarDefault' => 1234,
66 ),
67 ),
68 array(
69 'No global already set, simple array',
70 null,
71 array(
72 'mwtestDefaultOptions' => array(
73 'foobar' => true,
74 )
75 ),
76 array(
77 'mwtestDefaultOptions' => array(
78 'foobar' => true,
79 )
80 ),
81 ),
82 array(
83 'Global already set, simple array',
84 array(
85 'mwtestDefaultOptions' => array(
86 'foobar' => true,
87 'foo' => 'string'
88 ),
89 ),
90 array(
91 'mwtestDefaultOptions' => array(
92 'barbaz' => 12345,
93 'foobar' => false,
94 ),
95 ),
96 array(
97 'mwtestDefaultOptions' => array(
98 'barbaz' => 12345,
99 'foo' => 'string',
100 'foobar' => true,
101 ),
102 )
103 ),
104 array(
105 'Global already set, 1d array that appends',
106 array(
107 'mwAvailableRights' => array(
108 'foobar',
109 'foo'
110 ),
111 ),
112 array(
113 'mwAvailableRights' => array(
114 'barbaz',
115 ),
116 ),
117 array(
118 'mwAvailableRights' => array(
119 'barbaz',
120 'foobar',
121 'foo',
122 ),
123 )
124 ),
125 array(
126 'Global already set, array with integer keys',
127 array(
128 'mwNamespacesFoo' => array(
129 100 => true,
130 102 => false
131 ),
132 ),
133 array(
134 'mwNamespacesFoo' => array(
135 100 => false,
136 500 => true,
137 ExtensionRegistry::MERGE_STRATEGY => 'array_plus',
138 ),
139 ),
140 array(
141 'mwNamespacesFoo' => array(
142 100 => true,
143 102 => false,
144 500 => true,
145 ),
146 )
147 ),
148 array(
149 'No global already set, $wgHooks',
150 array(
151 'wgHooks' => array(),
152 ),
153 array(
154 'wgHooks' => array(
155 'FooBarEvent' => array(
156 'FooBarClass::onFooBarEvent'
157 ),
158 ExtensionRegistry::MERGE_STRATEGY => 'array_merge_recursive'
159 ),
160 ),
161 array(
162 'wgHooks' => array(
163 'FooBarEvent' => array(
164 'FooBarClass::onFooBarEvent'
165 ),
166 ),
167 ),
168 ),
169 array(
170 'Global already set, $wgHooks',
171 array(
172 'wgHooks' => array(
173 'FooBarEvent' => array(
174 'FooBarClass::onFooBarEvent'
175 ),
176 'BazBarEvent' => array(
177 'FooBarClass::onBazBarEvent',
178 ),
179 ),
180 ),
181 array(
182 'wgHooks' => array(
183 'FooBarEvent' => array(
184 'BazBarClass::onFooBarEvent',
185 ),
186 ExtensionRegistry::MERGE_STRATEGY => 'array_merge_recursive',
187 ),
188 ),
189 array(
190 'wgHooks' => array(
191 'FooBarEvent' => array(
192 'FooBarClass::onFooBarEvent',
193 'BazBarClass::onFooBarEvent',
194 ),
195 'BazBarEvent' => array(
196 'FooBarClass::onBazBarEvent',
197 ),
198 ),
199 ),
200 ),
201 array(
202 'Global already set, $wgGroupPermissions',
203 array(
204 'wgGroupPermissions' => array(
205 'sysop' => array(
206 'something' => true,
207 ),
208 'user' => array(
209 'somethingtwo' => true,
210 )
211 ),
212 ),
213 array(
214 'wgGroupPermissions' => array(
215 'customgroup' => array(
216 'right' => true,
217 ),
218 'user' => array(
219 'right' => true,
220 'somethingtwo' => false,
221 'nonduplicated' => true,
222 ),
223 ExtensionRegistry::MERGE_STRATEGY => 'array_plus_2d',
224 ),
225 ),
226 array(
227 'wgGroupPermissions' => array(
228 'customgroup' => array(
229 'right' => true,
230 ),
231 'sysop' => array(
232 'something' => true,
233 ),
234 'user' => array(
235 'somethingtwo' => true,
236 'right' => true,
237 'nonduplicated' => true,
238 )
239 ),
240 ),
241 ),
242 array(
243 'False local setting should not be overridden (T100767)',
244 array(
245 'mwtestT100767' => false,
246 ),
247 array(
248 'mwtestT100767' => true,
249 ),
250 array(
251 'mwtestT100767' => false,
252 ),
253 ),
254 );
255 }
256 }