* ParsoidParser hadn't registered a watcher on ParserOptions so far. Because of this, you can see that the current parser cache key (in deployed production code) doesn't have 'useParsoid=1' in it. Ex: View source on enwiki:Hospet shows that the parser cache key there is "enwiki:parsoid-pcache:idhash:2360619-0!canonical". The only reason this doesn't conflict with legacy parser output is because we use "parsoid-pcache", a diferent cache instance than "pcache" used for legacy parser output. But if/when we decide to use the same parser cache instance, this could cause cache corruptions. With FlaggedRevisions, where a single "stable-pcache" parser cache instance is used, in local testing, this was causing Parsoid HTML to be saved without "useParsoid=1", and so Parsoid HTML was being returned for legacy parser cache requests. * In addition, fix the code in PageBundleParserOutputConverter to copy over internal metadata (which includes used options). This ensures that any tracked parser options aren't lost and the right parser cache key is constructed later on. * Added / updated a number of new tests that verifies that usedOptions is tracked correctly in the useParsoid code paths. The tests fail without the code changes in this patch. Bug: T340703 Bug: T335157 Needed-By: I0e954949768044eea6ec275a36d0d6d7ed457e8e Change-Id: I076d5d362bdfd9d4b2ca8886bf6b30c1a746aee7
157 lines
4.3 KiB
PHP
157 lines
4.3 KiB
PHP
<?php
|
|
|
|
use MediaWiki\MainConfigNames;
|
|
|
|
/**
|
|
* @group ContentHandler
|
|
* @group Database
|
|
* ^--- needed, because we do need the database to test link updates
|
|
*/
|
|
class WikitextContentHandlerIntegrationTest extends TextContentHandlerIntegrationTest {
|
|
public static function provideGetParserOutput() {
|
|
yield 'Basic render' => [
|
|
'title' => 'WikitextContentTest_testGetParserOutput',
|
|
'model' => CONTENT_MODEL_WIKITEXT,
|
|
'text' => "hello ''world''\n",
|
|
'expectedHtml' => "<div class=\"mw-parser-output\"><p>hello <i>world</i>\n</p></div>",
|
|
'expectedFields' => [
|
|
'Links' => [
|
|
],
|
|
'Sections' => [
|
|
],
|
|
'UsedOptions' => [
|
|
'useParsoid', 'suppressTOC', 'maxIncludeSize', 'maxPPNodeCount',
|
|
'targetLanguage', 'interfaceMessage', 'maxPPExpandDepth', 'disableTitleConversion',
|
|
'disableContentConversion', 'expensiveParserFunctionLimit', 'wrapclass'
|
|
],
|
|
],
|
|
];
|
|
yield 'Basic Parsoid render' => [
|
|
'title' => 'WikitextContentTest_testGetParserOutput',
|
|
'model' => CONTENT_MODEL_WIKITEXT,
|
|
'text' => "hello ''world''\n",
|
|
'expectedHtml' => "<div class=\"mw-parser-output\"><section data-mw-section-id=\"0\" id=\"mwAQ\"><p id=\"mwAg\">hello <i id=\"mwAw\">world</i></p>\n</section></div>",
|
|
'expectedFields' => [
|
|
'Links' => [
|
|
],
|
|
'Sections' => [
|
|
],
|
|
'UsedOptions' => [
|
|
'useParsoid', 'maxIncludeSize', 'interfaceMessage', 'wrapclass'
|
|
],
|
|
],
|
|
'options' => [ 'useParsoid' => true ]
|
|
];
|
|
yield 'Links' => [
|
|
'title' => 'WikitextContentTest_testGetParserOutput',
|
|
'model' => CONTENT_MODEL_WIKITEXT,
|
|
'text' => "[[title that does not really exist]]",
|
|
'expectedHtml' => null,
|
|
'expectedFields' => [
|
|
'Links' => [
|
|
[ 'Title_that_does_not_really_exist' => 0, ],
|
|
],
|
|
'Sections' => [
|
|
],
|
|
],
|
|
];
|
|
yield 'TOC' => [
|
|
'title' => 'WikitextContentTest_testGetParserOutput',
|
|
'model' => CONTENT_MODEL_WIKITEXT,
|
|
'text' => "==One==\n==Two==\n==Three==\n==Four==\n<h2>Five</h2>\n===Six+Seven %2525===",
|
|
'expectedHtml' => null,
|
|
'expectedFields' => [
|
|
'Links' => [
|
|
],
|
|
'Sections' => [
|
|
[
|
|
'toclevel' => 1,
|
|
'level' => '2',
|
|
'line' => 'One',
|
|
'number' => '1',
|
|
'index' => '1',
|
|
'fromtitle' => 'WikitextContentTest_testGetParserOutput',
|
|
'byteoffset' => 0,
|
|
'anchor' => 'One',
|
|
'linkAnchor' => 'One',
|
|
],
|
|
[
|
|
'toclevel' => 1,
|
|
'level' => '2',
|
|
'line' => 'Two',
|
|
'number' => '2',
|
|
'index' => '2',
|
|
'fromtitle' => 'WikitextContentTest_testGetParserOutput',
|
|
'byteoffset' => 8,
|
|
'anchor' => 'Two',
|
|
'linkAnchor' => 'Two',
|
|
],
|
|
[
|
|
'toclevel' => 1,
|
|
'level' => '2',
|
|
'line' => 'Three',
|
|
'number' => '3',
|
|
'index' => '3',
|
|
'fromtitle' => 'WikitextContentTest_testGetParserOutput',
|
|
'byteoffset' => 16,
|
|
'anchor' => 'Three',
|
|
'linkAnchor' => 'Three',
|
|
],
|
|
[
|
|
'toclevel' => 1,
|
|
'level' => '2',
|
|
'line' => 'Four',
|
|
'number' => '4',
|
|
'index' => '4',
|
|
'fromtitle' => 'WikitextContentTest_testGetParserOutput',
|
|
'byteoffset' => 26,
|
|
'anchor' => 'Four',
|
|
'linkAnchor' => 'Four',
|
|
],
|
|
[
|
|
'toclevel' => 1,
|
|
'level' => '2',
|
|
'line' => 'Five',
|
|
'number' => '5',
|
|
'index' => '',
|
|
'fromtitle' => false,
|
|
'byteoffset' => null,
|
|
'anchor' => 'Five',
|
|
'linkAnchor' => 'Five',
|
|
],
|
|
[
|
|
'toclevel' => 2,
|
|
'level' => '3',
|
|
'line' => 'Six+Seven %2525',
|
|
'number' => '5.1',
|
|
'index' => '5',
|
|
'fromtitle' => 'WikitextContentTest_testGetParserOutput',
|
|
'byteoffset' => 49,
|
|
'anchor' => 'Six+Seven_%2525',
|
|
'linkAnchor' => 'Six+Seven_%252525',
|
|
],
|
|
],
|
|
],
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @dataProvider provideGetParserOutput
|
|
* @covers WikitextContentHandler::fillParserOutput
|
|
*/
|
|
public function testGetParserOutput( $title, $model, $text, $expectedHtml,
|
|
$expectedFields = null, $options = null
|
|
) {
|
|
$parserOptions = null;
|
|
if ( $options ) {
|
|
$parserOptions = ParserOptions::newFromAnon();
|
|
foreach ( $options as $key => $val ) {
|
|
$parserOptions->setOption( $key, $val );
|
|
}
|
|
}
|
|
$this->overrideConfigValue( MainConfigNames::FragmentMode, [ 'html5' ] );
|
|
parent::testGetParserOutput(
|
|
$title, $model, $text, $expectedHtml, $expectedFields, $parserOptions
|
|
);
|
|
}
|
|
}
|