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();
54 public function testLoadFromQueue() {
55 $registry = new ExtensionRegistry();
56 $registry->queue( "{$this->dataDir}/good.json" );
57 $registry->loadFromQueue();
58 $this->assertArrayHasKey( 'FooBar', $registry->getAllThings() );
59 $this->assertTrue( $registry->isLoaded( 'FooBar' ) );
60 $this->assertSame( [ 'test' ], $registry->getAttribute( 'FooBarAttr' ) );
61 $this->assertSame( [], $registry->getAttribute( 'NotLoadedAttr' ) );
65 * @expectedException PHPUnit_Framework_Error
67 public function testReadFromQueue_nonexistent() {
68 $registry = new ExtensionRegistry();
69 $registry->readFromQueue( [
70 __DIR__
. '/doesnotexist.json' => 1
75 * @dataProvider provideExportExtractedDataGlobals
77 public function testExportExtractedDataGlobals( $desc, $before, $globals, $expected ) {
78 // Set globals for test
80 foreach ( $before as $key => $value ) {
81 // mw prefixed globals does not exist normally
82 if ( substr( $key, 0, 2 ) == 'mw' ) {
83 $GLOBALS[$key] = $value;
85 $this->setMwGlobals( $key, $value );
91 'globals' => $globals,
96 'autoloaderPaths' => []
98 $registry = new ExtensionRegistry();
99 $class = new ReflectionClass( ExtensionRegistry
::class );
100 $method = $class->getMethod( 'exportExtractedData' );
101 $method->setAccessible( true );
102 $method->invokeArgs( $registry, [ $info ] );
103 foreach ( $expected as $name => $value ) {
104 $this->assertArrayHasKey( $name, $GLOBALS, $desc );
105 $this->assertEquals( $value, $GLOBALS[$name], $desc );
108 // Remove mw prefixed globals
110 foreach ( $before as $key => $value ) {
111 if ( substr( $key, 0, 2 ) == 'mw' ) {
112 unset( $GLOBALS[$key] );
118 public static function provideExportExtractedDataGlobals() {
119 // "mwtest" prefix used instead of "$wg" to avoid potential conflicts
122 'Simple non-array values',
124 'mwtestFooBarConfig' => true,
125 'mwtestFooBarConfig2' => 'string',
128 'mwtestFooBarDefault' => 1234,
129 'mwtestFooBarConfig' => false,
132 'mwtestFooBarConfig' => true,
133 'mwtestFooBarConfig2' => 'string',
134 'mwtestFooBarDefault' => 1234,
138 'No global already set, simple array',
141 'mwtestDefaultOptions' => [
146 'mwtestDefaultOptions' => [
152 'Global already set, simple array',
154 'mwtestDefaultOptions' => [
160 'mwtestDefaultOptions' => [
166 'mwtestDefaultOptions' => [
174 'Global already set, 1d array that appends',
176 'mwAvailableRights' => [
182 'mwAvailableRights' => [
187 'mwAvailableRights' => [
195 'Global already set, array with integer keys',
197 'mwNamespacesFoo' => [
203 'mwNamespacesFoo' => [
206 ExtensionRegistry
::MERGE_STRATEGY
=> 'array_plus',
210 'mwNamespacesFoo' => [
218 'No global already set, $wgHooks',
225 'FooBarClass::onFooBarEvent'
227 ExtensionRegistry
::MERGE_STRATEGY
=> 'array_merge_recursive'
233 'FooBarClass::onFooBarEvent'
239 'Global already set, $wgHooks',
243 'FooBarClass::onFooBarEvent'
246 'FooBarClass::onBazBarEvent',
253 'BazBarClass::onFooBarEvent',
255 ExtensionRegistry
::MERGE_STRATEGY
=> 'array_merge_recursive',
261 'FooBarClass::onFooBarEvent',
262 'BazBarClass::onFooBarEvent',
265 'FooBarClass::onBazBarEvent',
271 'Global already set, $wgGroupPermissions',
273 'wgGroupPermissions' => [
278 'somethingtwo' => true,
283 'wgGroupPermissions' => [
289 'somethingtwo' => false,
290 'nonduplicated' => true,
292 ExtensionRegistry
::MERGE_STRATEGY
=> 'array_plus_2d',
296 'wgGroupPermissions' => [
304 'somethingtwo' => true,
306 'nonduplicated' => true,
312 'False local setting should not be overridden (T100767)',
314 'mwtestT100767' => false,
317 'mwtestT100767' => true,
320 'mwtestT100767' => false,
324 'test array_replace_recursive',
326 'mwtestJsonConfigs' => [
327 'JsonZeroConfig' => [
335 'mwtestJsonConfigs' => [
336 'JsonZeroConfig' => [
342 ExtensionRegistry
::MERGE_STRATEGY
=> 'array_replace_recursive',
346 'mwtestJsonConfigs' => [
347 'JsonZeroConfig' => [
359 'global is null before',
361 'NullGlobal' => null,
364 'NullGlobal' => 'not-null'