4 * @covers ExtensionRegistry
6 class ExtensionRegistryTest
extends MediaWikiTestCase
{
10 public function setUp() {
12 $this->dataDir
= __DIR__
. '/../../data/registration';
15 public function testQueue_invalid() {
16 $registry = new ExtensionRegistry();
17 $path = __DIR__
. '/doesnotexist.json';
18 $this->setExpectedException(
20 "$path does not exist!"
22 $registry->queue( $path );
25 public function testQueue() {
26 $registry = new ExtensionRegistry();
27 $path = "{$this->dataDir}/good.json";
28 $registry->queue( $path );
29 $this->assertArrayHasKey(
33 $registry->clearQueue();
34 $this->assertEmpty( $registry->getQueue() );
37 public function testLoadFromQueue_empty() {
38 $registry = new ExtensionRegistry();
39 $registry->loadFromQueue();
40 $this->assertEmpty( $registry->getAllThings() );
43 public function testLoadFromQueue_late() {
44 $registry = new ExtensionRegistry();
46 $registry->queue( "{$this->dataDir}/good.json" );
47 $this->setExpectedException(
49 "The following paths tried to load late: {$this->dataDir}/good.json"
51 $registry->loadFromQueue();
55 * @dataProvider provideExportExtractedDataGlobals
57 public function testExportExtractedDataGlobals( $desc, $before, $globals, $expected ) {
58 // Set globals for test
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;
65 $this->setMwGlobals( $key, $value );
71 'globals' => $globals,
76 'autoloaderPaths' => []
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 );
88 // Remove mw prefixed globals
90 foreach ( $before as $key => $value ) {
91 if ( substr( $key, 0, 2 ) == 'mw' ) {
92 unset( $GLOBALS[$key] );
98 public static function provideExportExtractedDataGlobals() {
99 // "mwtest" prefix used instead of "$wg" to avoid potential conflicts
102 'Simple non-array values',
104 'mwtestFooBarConfig' => true,
105 'mwtestFooBarConfig2' => 'string',
108 'mwtestFooBarDefault' => 1234,
109 'mwtestFooBarConfig' => false,
112 'mwtestFooBarConfig' => true,
113 'mwtestFooBarConfig2' => 'string',
114 'mwtestFooBarDefault' => 1234,
118 'No global already set, simple array',
121 'mwtestDefaultOptions' => [
126 'mwtestDefaultOptions' => [
132 'Global already set, simple array',
134 'mwtestDefaultOptions' => [
140 'mwtestDefaultOptions' => [
146 'mwtestDefaultOptions' => [
154 'Global already set, 1d array that appends',
156 'mwAvailableRights' => [
162 'mwAvailableRights' => [
167 'mwAvailableRights' => [
175 'Global already set, array with integer keys',
177 'mwNamespacesFoo' => [
183 'mwNamespacesFoo' => [
186 ExtensionRegistry
::MERGE_STRATEGY
=> 'array_plus',
190 'mwNamespacesFoo' => [
198 'No global already set, $wgHooks',
205 'FooBarClass::onFooBarEvent'
207 ExtensionRegistry
::MERGE_STRATEGY
=> 'array_merge_recursive'
213 'FooBarClass::onFooBarEvent'
219 'Global already set, $wgHooks',
223 'FooBarClass::onFooBarEvent'
226 'FooBarClass::onBazBarEvent',
233 'BazBarClass::onFooBarEvent',
235 ExtensionRegistry
::MERGE_STRATEGY
=> 'array_merge_recursive',
241 'FooBarClass::onFooBarEvent',
242 'BazBarClass::onFooBarEvent',
245 'FooBarClass::onBazBarEvent',
251 'Global already set, $wgGroupPermissions',
253 'wgGroupPermissions' => [
258 'somethingtwo' => true,
263 'wgGroupPermissions' => [
269 'somethingtwo' => false,
270 'nonduplicated' => true,
272 ExtensionRegistry
::MERGE_STRATEGY
=> 'array_plus_2d',
276 'wgGroupPermissions' => [
284 'somethingtwo' => true,
286 'nonduplicated' => true,
292 'False local setting should not be overridden (T100767)',
294 'mwtestT100767' => false,
297 'mwtestT100767' => true,
300 'mwtestT100767' => false,
304 'test array_replace_recursive',
306 'mwtestJsonConfigs' => [
307 'JsonZeroConfig' => [
315 'mwtestJsonConfigs' => [
316 'JsonZeroConfig' => [
322 ExtensionRegistry
::MERGE_STRATEGY
=> 'array_replace_recursive',
326 'mwtestJsonConfigs' => [
327 'JsonZeroConfig' => [
339 'global is null before',
341 'NullGlobal' => null,
344 'NullGlobal' => 'not-null'