2015-02-13 07:40:13 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
class ExtensionRegistryTest extends MediaWikiTestCase {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers ExtensionRegistry::exportExtractedData
|
|
|
|
|
* @dataProvider provideExportExtractedDataGlobals
|
|
|
|
|
*/
|
|
|
|
|
public function testExportExtractedDataGlobals( $desc, $before, $globals, $expected ) {
|
2015-02-22 10:02:15 +00:00
|
|
|
// Set globals for test
|
2015-02-13 07:40:13 +00:00
|
|
|
if ( $before ) {
|
|
|
|
|
foreach ( $before as $key => $value ) {
|
2015-02-22 10:02:15 +00:00
|
|
|
// mw prefixed globals does not exist normally
|
|
|
|
|
if ( substr( $key, 0, 2 ) == 'mw' ) {
|
|
|
|
|
$GLOBALS[$key] = $value;
|
|
|
|
|
} else {
|
|
|
|
|
$this->setMwGlobals( $key, $value );
|
|
|
|
|
}
|
2015-02-13 07:40:13 +00:00
|
|
|
}
|
|
|
|
|
}
|
2015-02-22 10:02:15 +00:00
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$info = [
|
2015-02-13 07:40:13 +00:00
|
|
|
'globals' => $globals,
|
2016-02-17 09:09:32 +00:00
|
|
|
'callbacks' => [],
|
|
|
|
|
'defines' => [],
|
|
|
|
|
'credits' => [],
|
|
|
|
|
'attributes' => [],
|
|
|
|
|
'autoloaderPaths' => []
|
|
|
|
|
];
|
2015-02-13 07:40:13 +00:00
|
|
|
$registry = new ExtensionRegistry();
|
|
|
|
|
$class = new ReflectionClass( 'ExtensionRegistry' );
|
|
|
|
|
$method = $class->getMethod( 'exportExtractedData' );
|
|
|
|
|
$method->setAccessible( true );
|
2016-02-17 09:09:32 +00:00
|
|
|
$method->invokeArgs( $registry, [ $info ] );
|
2015-02-13 07:40:13 +00:00
|
|
|
foreach ( $expected as $name => $value ) {
|
|
|
|
|
$this->assertArrayHasKey( $name, $GLOBALS, $desc );
|
|
|
|
|
$this->assertEquals( $value, $GLOBALS[$name], $desc );
|
|
|
|
|
}
|
2015-02-22 10:02:15 +00:00
|
|
|
|
|
|
|
|
// Remove mw prefixed globals
|
|
|
|
|
if ( $before ) {
|
|
|
|
|
foreach ( $before as $key => $value ) {
|
|
|
|
|
if ( substr( $key, 0, 2 ) == 'mw' ) {
|
|
|
|
|
unset( $GLOBALS[$key] );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-02-13 07:40:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function provideExportExtractedDataGlobals() {
|
|
|
|
|
// "mwtest" prefix used instead of "$wg" to avoid potential conflicts
|
2016-02-17 09:09:32 +00:00
|
|
|
return [
|
|
|
|
|
[
|
2015-02-13 07:40:13 +00:00
|
|
|
'Simple non-array values',
|
2016-02-17 09:09:32 +00:00
|
|
|
[
|
2015-02-13 07:40:13 +00:00
|
|
|
'mwtestFooBarConfig' => true,
|
|
|
|
|
'mwtestFooBarConfig2' => 'string',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
[
|
2015-02-13 07:40:13 +00:00
|
|
|
'mwtestFooBarDefault' => 1234,
|
|
|
|
|
'mwtestFooBarConfig' => false,
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
[
|
2015-02-13 07:40:13 +00:00
|
|
|
'mwtestFooBarConfig' => true,
|
|
|
|
|
'mwtestFooBarConfig2' => 'string',
|
|
|
|
|
'mwtestFooBarDefault' => 1234,
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
[
|
2015-02-13 07:40:13 +00:00
|
|
|
'No global already set, simple array',
|
|
|
|
|
null,
|
2016-02-17 09:09:32 +00:00
|
|
|
[
|
|
|
|
|
'mwtestDefaultOptions' => [
|
2015-02-13 07:40:13 +00:00
|
|
|
'foobar' => true,
|
2016-02-17 09:09:32 +00:00
|
|
|
]
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'mwtestDefaultOptions' => [
|
2015-02-13 07:40:13 +00:00
|
|
|
'foobar' => true,
|
2016-02-17 09:09:32 +00:00
|
|
|
]
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
[
|
2015-02-13 07:40:13 +00:00
|
|
|
'Global already set, simple array',
|
2016-02-17 09:09:32 +00:00
|
|
|
[
|
|
|
|
|
'mwtestDefaultOptions' => [
|
2015-02-13 07:40:13 +00:00
|
|
|
'foobar' => true,
|
|
|
|
|
'foo' => 'string'
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'mwtestDefaultOptions' => [
|
2015-02-13 07:40:13 +00:00
|
|
|
'barbaz' => 12345,
|
|
|
|
|
'foobar' => false,
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'mwtestDefaultOptions' => [
|
2015-02-13 07:40:13 +00:00
|
|
|
'barbaz' => 12345,
|
|
|
|
|
'foo' => 'string',
|
|
|
|
|
'foobar' => true,
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
]
|
|
|
|
|
],
|
|
|
|
|
[
|
2015-08-01 07:38:27 +00:00
|
|
|
'Global already set, 1d array that appends',
|
2016-02-17 09:09:32 +00:00
|
|
|
[
|
|
|
|
|
'mwAvailableRights' => [
|
2015-08-01 07:38:27 +00:00
|
|
|
'foobar',
|
|
|
|
|
'foo'
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'mwAvailableRights' => [
|
2015-08-01 07:38:27 +00:00
|
|
|
'barbaz',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'mwAvailableRights' => [
|
2015-08-01 07:38:27 +00:00
|
|
|
'barbaz',
|
|
|
|
|
'foobar',
|
|
|
|
|
'foo',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
]
|
|
|
|
|
],
|
|
|
|
|
[
|
2015-09-17 17:28:38 +00:00
|
|
|
'Global already set, array with integer keys',
|
2016-02-17 09:09:32 +00:00
|
|
|
[
|
|
|
|
|
'mwNamespacesFoo' => [
|
2015-08-01 07:38:27 +00:00
|
|
|
100 => true,
|
|
|
|
|
102 => false
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'mwNamespacesFoo' => [
|
2015-08-01 07:38:27 +00:00
|
|
|
100 => false,
|
|
|
|
|
500 => true,
|
|
|
|
|
ExtensionRegistry::MERGE_STRATEGY => 'array_plus',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'mwNamespacesFoo' => [
|
2015-09-17 17:28:38 +00:00
|
|
|
100 => true,
|
2015-08-01 07:38:27 +00:00
|
|
|
102 => false,
|
|
|
|
|
500 => true,
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
]
|
|
|
|
|
],
|
|
|
|
|
[
|
2015-02-13 07:40:13 +00:00
|
|
|
'No global already set, $wgHooks',
|
2016-02-17 09:09:32 +00:00
|
|
|
[
|
|
|
|
|
'wgHooks' => [],
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'wgHooks' => [
|
|
|
|
|
'FooBarEvent' => [
|
2015-02-13 07:40:13 +00:00
|
|
|
'FooBarClass::onFooBarEvent'
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
2015-08-01 07:38:27 +00:00
|
|
|
ExtensionRegistry::MERGE_STRATEGY => 'array_merge_recursive'
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'wgHooks' => [
|
|
|
|
|
'FooBarEvent' => [
|
2015-02-13 07:40:13 +00:00
|
|
|
'FooBarClass::onFooBarEvent'
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
[
|
2015-02-13 07:40:13 +00:00
|
|
|
'Global already set, $wgHooks',
|
2016-02-17 09:09:32 +00:00
|
|
|
[
|
|
|
|
|
'wgHooks' => [
|
|
|
|
|
'FooBarEvent' => [
|
2015-02-13 07:40:13 +00:00
|
|
|
'FooBarClass::onFooBarEvent'
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
'BazBarEvent' => [
|
2015-02-13 07:40:13 +00:00
|
|
|
'FooBarClass::onBazBarEvent',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'wgHooks' => [
|
|
|
|
|
'FooBarEvent' => [
|
2015-02-13 07:40:13 +00:00
|
|
|
'BazBarClass::onFooBarEvent',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
2015-08-01 07:38:27 +00:00
|
|
|
ExtensionRegistry::MERGE_STRATEGY => 'array_merge_recursive',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'wgHooks' => [
|
|
|
|
|
'FooBarEvent' => [
|
2015-02-13 07:40:13 +00:00
|
|
|
'FooBarClass::onFooBarEvent',
|
|
|
|
|
'BazBarClass::onFooBarEvent',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
'BazBarEvent' => [
|
2015-02-13 07:40:13 +00:00
|
|
|
'FooBarClass::onBazBarEvent',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
[
|
2015-02-13 07:40:13 +00:00
|
|
|
'Global already set, $wgGroupPermissions',
|
2016-02-17 09:09:32 +00:00
|
|
|
[
|
|
|
|
|
'wgGroupPermissions' => [
|
|
|
|
|
'sysop' => [
|
2015-02-13 07:40:13 +00:00
|
|
|
'something' => true,
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
'user' => [
|
2015-02-13 07:40:13 +00:00
|
|
|
'somethingtwo' => true,
|
2016-02-17 09:09:32 +00:00
|
|
|
]
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'wgGroupPermissions' => [
|
|
|
|
|
'customgroup' => [
|
2015-02-13 07:40:13 +00:00
|
|
|
'right' => true,
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
'user' => [
|
2015-02-13 07:40:13 +00:00
|
|
|
'right' => true,
|
|
|
|
|
'somethingtwo' => false,
|
2015-05-16 00:57:12 +00:00
|
|
|
'nonduplicated' => true,
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
2015-08-01 07:38:27 +00:00
|
|
|
ExtensionRegistry::MERGE_STRATEGY => 'array_plus_2d',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'wgGroupPermissions' => [
|
|
|
|
|
'customgroup' => [
|
2015-02-13 07:40:13 +00:00
|
|
|
'right' => true,
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
'sysop' => [
|
2015-02-13 07:40:13 +00:00
|
|
|
'something' => true,
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
'user' => [
|
2015-02-13 07:40:13 +00:00
|
|
|
'somethingtwo' => true,
|
|
|
|
|
'right' => true,
|
2015-05-16 00:57:12 +00:00
|
|
|
'nonduplicated' => true,
|
2016-02-17 09:09:32 +00:00
|
|
|
]
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
[
|
2015-06-03 15:03:20 +00:00
|
|
|
'False local setting should not be overridden (T100767)',
|
2016-02-17 09:09:32 +00:00
|
|
|
[
|
2015-06-03 15:03:20 +00:00
|
|
|
'mwtestT100767' => false,
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
[
|
2015-06-03 15:03:20 +00:00
|
|
|
'mwtestT100767' => true,
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
[
|
2015-06-03 15:03:20 +00:00
|
|
|
'mwtestT100767' => false,
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
],
|
Added array_replace_recursive merge strategy
For extension registry, add array_replace_recursive merge strategy,
as some extensions/configuration may prefer that to array_merge_recursive.
In some cases, configuration is merged from multiple extensions,
such as JsonConfig's $wgJsonConfigs configuration: ZeroBanner defines
"JsonZeroConfig": {
"namespace": 480,
"nsName": "Zero",
"isLocal": false,
"cacheKey": "1"
}
and mobile.php overrides it with
$wgJsonConfigs['JsonZeroConfig']['isLocal'] = false;
$wgJsonConfigs['JsonZeroConfig']['remote'] = [
'url' => 'https://zero.wikimedia.org/w/api.php',
'username' => $wmgZeroPortalApiUserName,
'password' => $wmgZeroPortalApiPassword,
];
Having identical value 'isLocal' would be converted into an array
if array_merge_recursive is used, but the replace strategy fixes it.
Change-Id: Ica6ddd0ae76f23e60de9b6235c6e2a3f2754a95d
2016-10-18 05:23:56 +00:00
|
|
|
[
|
|
|
|
|
'test array_replace_recursive',
|
|
|
|
|
[
|
|
|
|
|
'mwtestJsonConfigs' => [
|
|
|
|
|
'JsonZeroConfig' => [
|
|
|
|
|
'namespace' => 480,
|
|
|
|
|
'nsName' => 'Zero',
|
|
|
|
|
'isLocal' => false,
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'mwtestJsonConfigs' => [
|
|
|
|
|
'JsonZeroConfig' => [
|
|
|
|
|
'isLocal' => false,
|
|
|
|
|
'remote' => [
|
|
|
|
|
'username' => 'foo',
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
ExtensionRegistry::MERGE_STRATEGY => 'array_replace_recursive',
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
[
|
|
|
|
|
'mwtestJsonConfigs' => [
|
|
|
|
|
'JsonZeroConfig' => [
|
|
|
|
|
'namespace' => 480,
|
|
|
|
|
'nsName' => 'Zero',
|
|
|
|
|
'isLocal' => false,
|
|
|
|
|
'remote' => [
|
|
|
|
|
'username' => 'foo',
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
],
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2015-02-13 07:40:13 +00:00
|
|
|
}
|
|
|
|
|
}
|