mediawiki-extensions-Math/tests/phpunit/unit/HooksTest.php
Umherirrender 7038c68f13 Use namespaced classes
Changes to the use statements done automatically via script
Addition of missing use statement done manually

Change-Id: I4cf7903b9700e6366bdf349f99ffd4a04da0c087
2024-10-20 09:27:34 +02:00

122 lines
3.4 KiB
PHP

<?php
namespace MediaWiki\Extension\Math\Tests;
use MediaWiki\Extension\Math\Hooks;
use MediaWiki\Registration\ExtensionRegistry;
use MediaWiki\Settings\Config\ArrayConfigBuilder;
use MediaWiki\Settings\Config\PhpIniSink;
use MediaWiki\Settings\SettingsBuilder;
use MediaWikiUnitTestCase;
/**
* @covers \MediaWiki\Extension\Math\Hooks
*/
class HooksTest extends MediaWikiUnitTestCase {
public static function provideOnConfig() {
$defaults = [
'MathFullRestbaseURL' => 'https://wikimedia.org/api/rest_',
'MathInternalRestbaseURL' => null,
'MathUseInternalRestbasePath' => true,
'VirtualRestConfig' => [],
];
yield 'defaults' => [
$defaults,
[
'MathFullRestbaseURL' => 'https://wikimedia.org/api/rest_',
'MathInternalRestbaseURL' => 'https://wikimedia.org/api/rest_',
]
];
yield 'explicit MathFullRestbaseURL' => [
[
'MathFullRestbaseURL' => 'https://mywiki.test/rest/'
] + $defaults,
[
'MathFullRestbaseURL' => 'https://mywiki.test/rest/',
'MathInternalRestbaseURL' => 'https://mywiki.test/rest/',
]
];
yield 'explicit MathInternalRestbaseURL' => [
[
'MathInternalRestbaseURL' => 'https://localhost:12345/rest/',
'VirtualRestConfig' => [ 'modules' => [ 'restbase' => [ // should be ignored
'url' => 'https://restbase.internal/rest/',
'domain' => 'mywiki',
] ] ]
] + $defaults,
[
'MathFullRestbaseURL' => 'https://wikimedia.org/api/rest_',
'MathInternalRestbaseURL' => 'https://localhost:12345/rest/',
]
];
yield 'use VirtualRestConfig' => [
[
'VirtualRestConfig' => [ 'modules' => [ 'restbase' => [
'url' => 'https://restbase.internal/rest/', // trailing slash should be normalized
'domain' => 'mywiki.test',
] ] ]
] + $defaults,
[
'MathFullRestbaseURL' => 'https://wikimedia.org/api/rest_',
'MathInternalRestbaseURL' => 'https://restbase.internal/rest/mywiki.test/',
]
];
yield 'use VirtualRestConfig with icky domain' => [
[
'VirtualRestConfig' => [ 'modules' => [ 'restbase' => [
'url' => 'https://restbase.internal/rest/',
'domain' => 'https://mywiki.test:8080', // domain name should get extracted
] ] ]
] + $defaults,
[
'MathFullRestbaseURL' => 'https://wikimedia.org/api/rest_',
'MathInternalRestbaseURL' => 'https://restbase.internal/rest/mywiki.test/',
]
];
yield 'disabled MathUseInternalRestbasePath' => [
[
'MathInternalRestbaseURL' => 'https://localhost:12345/rest/', // should be ignored
'VirtualRestConfig' => [ 'modules' => [ 'restbase' => [ // should be ignored
'url' => 'https://restbase.internal/rest/',
'domain' => 'mywiki',
] ] ],
'MathFullRestbaseURL' => 'https://mywiki.test/rest/',
'MathUseInternalRestbasePath' => false,
] + $defaults,
[
'MathFullRestbaseURL' => 'https://mywiki.test/rest/',
'MathInternalRestbaseURL' => 'https://mywiki.test/rest/',
]
];
}
/**
* @dataProvider provideOnConfig
*/
public function testOnConfig( array $config, array $expected ) {
$configSink = new ArrayConfigBuilder();
$configSink->setMulti( $config );
$settings = new SettingsBuilder(
__DIR__,
$this->createNoOpMock( ExtensionRegistry::class ),
$configSink,
$this->createNoOpMock( PhpIniSink::class )
);
Hooks::onConfig( [], $settings );
$actual = $settings->getConfig();
foreach ( $expected as $name => $value ) {
$this->assertSame( $value, $actual->get( $name ) );
}
}
}