This is an initial quick-and-dirty implementation. The ParsoidParser class will eventually inherit from \Parser, but this is an initial placeholder to unblock other Parsoid read views work. Currently Parsoid does not fully implement all the ParserOutput metadata set by the legacy parser, but we're working on it. This patch also addresses T300325 by ensuring the the Page HTML APIs use ParserOutput::getRawText(), which will return the entire Parsoid HTML document without post-processing. This is what the Parsoid team refers to as "edit mode" HTML. The ParserOutput::getText() method returns only the <body> contents of the HTML, and applies several transformations, including inserting Table of Contents and style deduplication; this is the "read views" flavor of the Parsoid HTML. We need to be careful of the interaction of the `useParsoid` flag with the ParserCacheMetadata. Effectively `useParsoid` should *always* be marked as "used" or else the ParserCache will assume its value doesn't matter and will serve legacy content for parsoid requests and vice-versa. T330677 is a follow up to address this more thoroughly by splitting the parser cache in ParserOutputAccess; the stop gap in this patch is fragile and, because it doesn't fork the ParserCacheMetadata cache, may corrupt the ParserCacheMetadata in the case when Parsoid and the legacy parser consult different sets of options to render a page. Bug: T300191 Bug: T330677 Bug: T300325 Change-Id: Ica09a4284c00d7917f8b6249e946232b2fb38011
91 lines
2.3 KiB
PHP
91 lines
2.3 KiB
PHP
<?php
|
|
|
|
use MediaWiki\MainConfigNames;
|
|
|
|
/**
|
|
* @group ContentHandlerFactory
|
|
*/
|
|
class RegistrationContentHandlerFactoryToMediaWikiServicesTest extends MediaWikiIntegrationTestCase {
|
|
|
|
protected function setUp(): void {
|
|
parent::setUp();
|
|
|
|
$this->overrideConfigValue(
|
|
MainConfigNames::ContentHandlers,
|
|
[
|
|
CONTENT_MODEL_WIKITEXT => [
|
|
'class' => WikitextContentHandler::class,
|
|
'services' => [
|
|
'TitleFactory',
|
|
'ParserFactory',
|
|
'GlobalIdGenerator',
|
|
'LanguageNameUtils',
|
|
'MagicWordFactory',
|
|
'ParsoidParserFactory',
|
|
],
|
|
],
|
|
CONTENT_MODEL_JAVASCRIPT => JavaScriptContentHandler::class,
|
|
CONTENT_MODEL_JSON => JsonContentHandler::class,
|
|
CONTENT_MODEL_CSS => CssContentHandler::class,
|
|
CONTENT_MODEL_TEXT => TextContentHandler::class,
|
|
'testing' => DummyContentHandlerForTesting::class,
|
|
'testing-callbacks' => static function ( $modelId ) {
|
|
return new DummyContentHandlerForTesting( $modelId );
|
|
},
|
|
]
|
|
);
|
|
}
|
|
|
|
/**
|
|
* @covers \MediaWiki\MediaWikiServices::getContentHandlerFactory
|
|
*/
|
|
public function testCallFromService_get_ok(): void {
|
|
$this->assertInstanceOf(
|
|
\MediaWiki\Content\IContentHandlerFactory::class,
|
|
$this->getServiceContainer()->getContentHandlerFactory()
|
|
);
|
|
|
|
$this->assertSame(
|
|
[
|
|
'wikitext',
|
|
'javascript',
|
|
'json',
|
|
'css',
|
|
'text',
|
|
'testing',
|
|
'testing-callbacks',
|
|
],
|
|
$this->getServiceContainer()->getContentHandlerFactory()->getContentModels()
|
|
);
|
|
}
|
|
|
|
/**
|
|
* @covers \MediaWiki\MediaWikiServices::getContentHandlerFactory
|
|
*/
|
|
public function testCallFromService_second_same(): void {
|
|
$this->assertSame(
|
|
$this->getServiceContainer()->getContentHandlerFactory(),
|
|
$this->getServiceContainer()->getContentHandlerFactory()
|
|
);
|
|
}
|
|
|
|
/**
|
|
* @covers \MediaWiki\MediaWikiServices::getContentHandlerFactory
|
|
*/
|
|
public function testCallFromService_afterCustomDefine_same(): void {
|
|
$factory = $this->getServiceContainer()->getContentHandlerFactory();
|
|
$factory->defineContentHandler(
|
|
'model name',
|
|
DummyContentHandlerForTesting::class
|
|
);
|
|
$this->assertTrue(
|
|
$this->getServiceContainer()
|
|
->getContentHandlerFactory()
|
|
->isDefinedModel( 'model name' )
|
|
);
|
|
$this->assertSame(
|
|
$factory,
|
|
$this->getServiceContainer()->getContentHandlerFactory()
|
|
);
|
|
}
|
|
}
|