HtmlOutputRendererHelper should not crash hard if the ParserOutput has no language set. ParserOutput may come from a variety of places, we should be lenient about it not having a language. However, we should try harder to actually set a language on ParserOutput if we have one available. So this also updates PageBundleParserOutputConverter to keep the ParserOutput's language in sync wit the language header in the PageBundle. Bug: T349868 Bug: T353689 Bug: T359426 Change-Id: I2edf20dc3b199e22cda2f32bc858c21ca7d8f4bd
74 lines
2.1 KiB
PHP
74 lines
2.1 KiB
PHP
<?php
|
|
|
|
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
|
|
*/
|
|
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 ) );
|
|
}
|
|
|
|
/**
|
|
* @param string $data
|
|
* @param string $type
|
|
*
|
|
* @return FallbackContent
|
|
*/
|
|
public function newContent( $data, $type = self::CONTENT_MODEL ) {
|
|
return new FallbackContent( $data, $type );
|
|
}
|
|
|
|
/**
|
|
* @covers \ContentHandler::getSlotDiffRenderer
|
|
*/
|
|
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 );
|
|
}
|
|
|
|
/**
|
|
* @covers \FallbackContentHandler::fillParserOutput
|
|
*/
|
|
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();
|
|
$po = $contentRenderer->getParserOutput( $content, $title );
|
|
$html = $po->getText();
|
|
$html = preg_replace( '#<!--.*?-->#sm', '', $html ); // strip comments
|
|
|
|
$this->assertStringNotContainsString( 'Horkyporky', $html );
|
|
$this->assertStringNotContainsString( '(unsupported-content-model)', $html );
|
|
}
|
|
}
|