3 use Wikimedia\ScopedCallback;
14 $this->dataDir = __DIR__ .
'/../../data/registration';
19 $path = __DIR__ .
'/doesnotexist.json';
20 $this->setExpectedException(
22 "$path does not exist!"
24 $registry->queue(
$path );
29 $path =
"{$this->dataDir}/good.json";
30 $registry->queue(
$path );
31 $this->assertArrayHasKey(
35 $registry->clearQueue();
36 $this->assertEmpty( $registry->getQueue() );
41 $registry->loadFromQueue();
42 $this->assertEmpty( $registry->getAllThings() );
48 $registry->queue(
"{$this->dataDir}/good.json" );
49 $this->setExpectedException(
51 "The following paths tried to load late: {$this->dataDir}/good.json"
53 $registry->loadFromQueue();
58 $registry->queue(
"{$this->dataDir}/good.json" );
59 $registry->loadFromQueue();
60 $this->assertArrayHasKey(
'FooBar', $registry->getAllThings() );
61 $this->assertTrue( $registry->isLoaded(
'FooBar' ) );
62 $this->assertTrue( $registry->isLoaded(
'FooBar',
'*' ) );
63 $this->assertSame( [
'test' ], $registry->getAttribute(
'FooBarAttr' ) );
64 $this->assertSame( [], $registry->getAttribute(
'NotLoadedAttr' ) );
69 $registry->queue(
"{$this->dataDir}/good_with_version.json" );
70 $registry->loadFromQueue();
71 $this->assertTrue( $registry->isLoaded(
'FooBar',
'>= 1.2.0' ) );
72 $this->assertFalse( $registry->isLoaded(
'FooBar',
'^1.3.0' ) );
80 $registry->queue(
"{$this->dataDir}/good.json" );
81 $registry->loadFromQueue();
82 $registry->isLoaded(
'FooBar',
'>= 1.2.0' );
90 $registry->readFromQueue( [
91 __DIR__ .
'/doesnotexist.json' => 1
97 $registry->readFromQueue( [
98 "{$this->dataDir}/autoload_namespaces.json" => 1
101 class_exists(
'Test\\MediaWiki\\AutoLoader\\TestFooBar' ),
102 "Registry initializes Autoloader from AutoloadNamespaces"
112 foreach ( $before
as $key =>
$value ) {
114 if ( substr( $key, 0, 2 ) ==
'mw' ) {
123 'globals' => $globals,
128 'autoloaderPaths' => []
132 $method = $class->getMethod(
'exportExtractedData' );
133 $method->setAccessible(
true );
134 $method->invokeArgs( $registry, [ $info ] );
142 foreach ( $before
as $key =>
$value ) {
143 if ( substr( $key, 0, 2 ) ==
'mw' ) {
154 'Simple non-array values',
156 'mwtestFooBarConfig' =>
true,
157 'mwtestFooBarConfig2' =>
'string',
160 'mwtestFooBarDefault' => 1234,
161 'mwtestFooBarConfig' =>
false,
164 'mwtestFooBarConfig' =>
true,
165 'mwtestFooBarConfig2' =>
'string',
166 'mwtestFooBarDefault' => 1234,
170 'No global already set, simple array',
173 'mwtestDefaultOptions' => [
178 'mwtestDefaultOptions' => [
184 'Global already set, simple array',
186 'mwtestDefaultOptions' => [
192 'mwtestDefaultOptions' => [
198 'mwtestDefaultOptions' => [
206 'Global already set, 1d array that appends',
208 'mwAvailableRights' => [
214 'mwAvailableRights' => [
219 'mwAvailableRights' => [
227 'Global already set, array with integer keys',
229 'mwNamespacesFoo' => [
235 'mwNamespacesFoo' => [
242 'mwNamespacesFoo' => [
250 'No global already set, $wgHooks',
257 'FooBarClass::onFooBarEvent'
265 'FooBarClass::onFooBarEvent'
271 'Global already set, $wgHooks',
275 'FooBarClass::onFooBarEvent'
278 'FooBarClass::onBazBarEvent',
285 'BazBarClass::onFooBarEvent',
293 'FooBarClass::onFooBarEvent',
294 'BazBarClass::onFooBarEvent',
297 'FooBarClass::onBazBarEvent',
303 'Global already set, $wgGroupPermissions',
305 'wgGroupPermissions' => [
310 'somethingtwo' =>
true,
315 'wgGroupPermissions' => [
321 'somethingtwo' =>
false,
322 'nonduplicated' =>
true,
328 'wgGroupPermissions' => [
336 'somethingtwo' =>
true,
338 'nonduplicated' =>
true,
344 'False local setting should not be overridden (T100767)',
346 'mwtestT100767' =>
false,
349 'mwtestT100767' =>
true,
352 'mwtestT100767' =>
false,
356 'test array_replace_recursive',
358 'mwtestJsonConfigs' => [
359 'JsonZeroConfig' => [
367 'mwtestJsonConfigs' => [
368 'JsonZeroConfig' => [
378 'mwtestJsonConfigs' => [
379 'JsonZeroConfig' => [
391 'global is null before',
393 'NullGlobal' =>
null,
396 'NullGlobal' =>
'not-null'
407 $registry->queue(
"{$this->dataDir}/good.json" );
408 $registry->loadFromQueue();
410 $this->assertSame( [
'test' ], $registry->getAttribute(
'FooBarAttr' ) );
411 $reset = $registry->setAttributeForTest(
'FooBarAttr', [
'override' ] );
413 $this->assertSame( [
'override' ], $registry->getAttribute(
'FooBarAttr' ) );
414 ScopedCallback::consume( $reset );
416 $this->assertSame( [
'test' ], $registry->getAttribute(
'FooBarAttr' ) );
425 $reset1 = $registry->setAttributeForTest(
'foo', [
'val1' ] );
426 $reset2 = $registry->setAttributeForTest(
'foo', [
'val2' ] );