2022-10-13 15:24:07 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace MediaWiki\Extension\VisualEditor\Tests;
|
|
|
|
|
|
|
|
use MediaWiki\Extension\VisualEditor\Hooks;
|
|
|
|
use MediaWikiIntegrationTestCase;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers \MediaWiki\Extension\VisualEditor\Hooks
|
|
|
|
* @group Database
|
|
|
|
*/
|
|
|
|
class HooksTest extends MediaWikiIntegrationTestCase {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider provideOnResourceLoaderGetConfigVars
|
|
|
|
*/
|
|
|
|
public function testOnResourceLoaderGetConfigVars( array $config, array $expected ) {
|
|
|
|
$this->overrideConfigValues( $config );
|
|
|
|
|
|
|
|
$vars = [];
|
|
|
|
Hooks::onResourceLoaderGetConfigVars( $vars );
|
|
|
|
|
|
|
|
$this->assertArrayHasKey( 'wgVisualEditorConfig', $vars );
|
|
|
|
$veConfig = $vars['wgVisualEditorConfig'];
|
|
|
|
|
|
|
|
foreach ( $expected as $name => $value ) {
|
|
|
|
$this->assertArrayHasKey( $name, $veConfig );
|
|
|
|
$this->assertSame( $value, $veConfig[$name] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function provideOnResourceLoaderGetConfigVars() {
|
|
|
|
// TODO: test a lot more config!
|
|
|
|
|
2022-10-19 12:43:26 +00:00
|
|
|
yield 'restbaseUrl: No VRS modules, DefaultParsoidClient=vrs' => [
|
2022-10-13 15:24:07 +00:00
|
|
|
[
|
|
|
|
'VirtualRestConfig' => [ 'modules' => [] ],
|
|
|
|
'VisualEditorRestbaseURL' => 'parsoid-url',
|
|
|
|
'VisualEditorFullRestbaseURL' => 'full-parsoid-url',
|
2022-10-19 12:43:26 +00:00
|
|
|
'VisualEditorDefaultParsoidClient' => 'vrs',
|
2022-10-13 15:24:07 +00:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'restbaseUrl' => false,
|
|
|
|
'fullRestbaseUrl' => false,
|
|
|
|
]
|
|
|
|
];
|
2022-10-19 12:43:26 +00:00
|
|
|
yield 'restbaseUrl: VRS modules available, DefaultParsoidClient=vrs' => [
|
2022-10-13 15:24:07 +00:00
|
|
|
[
|
|
|
|
'VirtualRestConfig' => [ 'modules' => [
|
|
|
|
'parsoid' => true,
|
|
|
|
] ],
|
|
|
|
'VisualEditorRestbaseURL' => 'parsoid-url',
|
|
|
|
'VisualEditorFullRestbaseURL' => 'full-parsoid-url',
|
2022-10-19 12:43:26 +00:00
|
|
|
'VisualEditorDefaultParsoidClient' => 'vrs',
|
2022-10-13 15:24:07 +00:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'restbaseUrl' => 'parsoid-url',
|
|
|
|
'fullRestbaseUrl' => 'full-parsoid-url',
|
|
|
|
]
|
|
|
|
];
|
2022-10-19 12:43:26 +00:00
|
|
|
yield 'restbaseUrl: VRS modules available, but no direct access URLs. DefaultParsoidClient=vrs' => [
|
2022-10-13 15:24:07 +00:00
|
|
|
[
|
|
|
|
'VirtualRestConfig' => [ 'modules' => [
|
|
|
|
'parsoid' => true,
|
|
|
|
] ],
|
|
|
|
'VisualEditorRestbaseURL' => 'parsoid-url',
|
|
|
|
'VisualEditorFullRestbaseURL' => 'full-parsoid-url',
|
2022-10-19 12:43:26 +00:00
|
|
|
'VisualEditorDefaultParsoidClient' => 'vrs',
|
2022-10-13 15:24:07 +00:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'restbaseUrl' => 'parsoid-url',
|
|
|
|
'fullRestbaseUrl' => 'full-parsoid-url',
|
|
|
|
]
|
|
|
|
];
|
2022-10-19 12:43:26 +00:00
|
|
|
|
|
|
|
yield 'restbaseUrl: VRS modules available, but DefaultParsoidClient=direct' => [
|
|
|
|
[
|
|
|
|
'VirtualRestConfig' => [ 'modules' => [
|
|
|
|
'parsoid' => true,
|
|
|
|
] ],
|
|
|
|
'VisualEditorRestbaseURL' => 'parsoid-url',
|
|
|
|
'VisualEditorFullRestbaseURL' => 'full-parsoid-url',
|
|
|
|
'VisualEditorDefaultParsoidClient' => 'direct',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'restbaseUrl' => false,
|
|
|
|
'fullRestbaseUrl' => false,
|
|
|
|
]
|
|
|
|
];
|
2022-10-13 15:24:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|