mediawiki-extensions-Visual.../tests/phpunit/integration/HooksTest.php
daniel adc017f73f Pick ParsoidClient implementation based on etag.
When receiving HTML from a VE session, process it with the same kind of
ParsoidClient that was originally used to generate the HTML. If we were
to use a different implementation, the ETag wouldn't match, so we would
fail to find the stashed data-parsoid map, and the edit would fail.

Bug: T320704
Change-Id: I3b73431fccacecb4ad88b82f8f5675b1042e03ce
2022-10-20 08:52:20 +00:00

93 lines
2.4 KiB
PHP

<?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!
yield 'restbaseUrl: No VRS modules, DefaultParsoidClient=vrs' => [
[
'VirtualRestConfig' => [ 'modules' => [] ],
'VisualEditorRestbaseURL' => 'parsoid-url',
'VisualEditorFullRestbaseURL' => 'full-parsoid-url',
'VisualEditorDefaultParsoidClient' => 'vrs',
],
[
'restbaseUrl' => false,
'fullRestbaseUrl' => false,
]
];
yield 'restbaseUrl: VRS modules available, DefaultParsoidClient=vrs' => [
[
'VirtualRestConfig' => [ 'modules' => [
'parsoid' => true,
] ],
'VisualEditorRestbaseURL' => 'parsoid-url',
'VisualEditorFullRestbaseURL' => 'full-parsoid-url',
'VisualEditorDefaultParsoidClient' => 'vrs',
],
[
'restbaseUrl' => 'parsoid-url',
'fullRestbaseUrl' => 'full-parsoid-url',
]
];
yield 'restbaseUrl: VRS modules available, but no direct access URLs. DefaultParsoidClient=vrs' => [
[
'VirtualRestConfig' => [ 'modules' => [
'parsoid' => true,
] ],
'VisualEditorRestbaseURL' => 'parsoid-url',
'VisualEditorFullRestbaseURL' => 'full-parsoid-url',
'VisualEditorDefaultParsoidClient' => 'vrs',
],
[
'restbaseUrl' => 'parsoid-url',
'fullRestbaseUrl' => 'full-parsoid-url',
]
];
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,
]
];
}
}