This is the fourth patch of a series of patches to remove ParserOutput::getText() calls from core. This series of patches should be functionally equivalent to I2b4bcddb234f10fd8592570cb0496adf3271328e. Here we replace calls to getText where a ContentRenderer is available close by by temporary ParserOutput::runOutputPipeline that will eventually be replaced by a call to (probably) ContentRenderer (T371004). Doing this work in stages allows us to separate the work of "bring ParserOptions to the call site" from the work of "bringing ContentRenderer(ish) to the call site", since both need to be done for to make ParserOutput a value object (T293512). Change-Id: Ib4f9357293dc230df6e0ca2379a1e2a4cc1b91b7 Bug: T293512
68 lines
2.2 KiB
PHP
68 lines
2.2 KiB
PHP
<?php
|
|
|
|
use MediaWiki\Content\FallbackContent;
|
|
use MediaWiki\Content\FallbackContentHandler;
|
|
use MediaWiki\Context\RequestContext;
|
|
use MediaWiki\Parser\ParserObserver;
|
|
use MediaWiki\Request\FauxRequest;
|
|
use MediaWiki\Title\Title;
|
|
|
|
/**
|
|
* See also unit tests at \MediaWiki\Tests\Unit\FallbackContentHandlerTest
|
|
*
|
|
* @group ContentHandler
|
|
* @covers \MediaWiki\Content\FallbackContentHandler
|
|
* @covers \ContentHandler
|
|
*/
|
|
class FallbackContentHandlerTest extends MediaWikiLangTestCase {
|
|
|
|
private const CONTENT_MODEL = 'xyzzy';
|
|
|
|
protected function setUp(): void {
|
|
parent::setUp();
|
|
$this->mergeMwGlobalArrayValue(
|
|
'wgContentHandlers',
|
|
[ self::CONTENT_MODEL => FallbackContentHandler::class ]
|
|
);
|
|
$this->setService( '_ParserObserver', $this->createMock( ParserObserver::class ) );
|
|
}
|
|
|
|
private function newContent( string $data, string $type = self::CONTENT_MODEL ) {
|
|
return new FallbackContent( $data, $type );
|
|
}
|
|
|
|
public function testGetSlotDiffRenderer() {
|
|
$context = new RequestContext();
|
|
$context->setRequest( new FauxRequest() );
|
|
|
|
$handler = new FallbackContentHandler( 'horkyporky' );
|
|
$this->hideDeprecated( 'ContentHandler::getSlotDiffRendererInternal' );
|
|
$slotDiffRenderer = $handler->getSlotDiffRenderer( $context );
|
|
|
|
$oldContent = $handler->unserializeContent( 'Foo' );
|
|
$newContent = $handler->unserializeContent( 'Foo bar' );
|
|
|
|
$diff = $slotDiffRenderer->getDiff( $oldContent, $newContent );
|
|
$this->assertNotEmpty( $diff );
|
|
}
|
|
|
|
public function testGetParserOutput() {
|
|
$this->setUserLang( 'en' );
|
|
$this->setContentLang( 'qqx' );
|
|
|
|
$title = $this->createMock( Title::class );
|
|
$title->method( 'getPageLanguage' )
|
|
->willReturn( $this->getServiceContainer()->getContentLanguage() );
|
|
|
|
$content = $this->newContent( 'Horkyporky' );
|
|
$contentRenderer = $this->getServiceContainer()->getContentRenderer();
|
|
$opts = ParserOptions::newFromAnon();
|
|
// TODO T371004
|
|
$po = $contentRenderer->getParserOutput( $content, $title, null, $opts );
|
|
$html = $po->runOutputPipeline( $opts, [] )->getContentHolderText();
|
|
$html = preg_replace( '#<!--.*?-->#sm', '', $html ); // strip comments
|
|
|
|
$this->assertStringNotContainsString( 'Horkyporky', $html );
|
|
$this->assertStringNotContainsString( '(unsupported-content-model)', $html );
|
|
}
|
|
}
|