2019-08-21 15:51:10 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
/**
|
2021-03-15 23:20:08 +00:00
|
|
|
* See also unit tests at \MediaWiki\Tests\Unit\FallbackContentHandlerTest
|
|
|
|
|
*
|
2019-08-21 15:51:10 +00:00
|
|
|
* @group ContentHandler
|
|
|
|
|
*/
|
2020-07-19 19:50:37 +00:00
|
|
|
class FallbackContentHandlerTest extends MediaWikiLangTestCase {
|
2019-08-21 15:51:10 +00:00
|
|
|
|
2021-10-14 14:01:58 +00:00
|
|
|
private const CONTENT_MODEL = 'xyzzy';
|
|
|
|
|
|
|
|
|
|
protected function setUp(): void {
|
|
|
|
|
parent::setUp();
|
|
|
|
|
$this->mergeMwGlobalArrayValue(
|
|
|
|
|
'wgContentHandlers',
|
|
|
|
|
[ self::CONTENT_MODEL => FallbackContentHandler::class ]
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param string $data
|
|
|
|
|
* @param string $type
|
|
|
|
|
*
|
|
|
|
|
* @return FallbackContent
|
|
|
|
|
*/
|
|
|
|
|
public function newContent( $data, $type = self::CONTENT_MODEL ) {
|
|
|
|
|
return new FallbackContent( $data, $type );
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-21 15:51:10 +00:00
|
|
|
/**
|
2021-03-15 23:20:08 +00:00
|
|
|
* @covers ContentHandler::getSlotDiffRenderer
|
2019-08-21 15:51:10 +00:00
|
|
|
*/
|
|
|
|
|
public function testGetSlotDiffRenderer() {
|
|
|
|
|
$context = new RequestContext();
|
|
|
|
|
$context->setRequest( new FauxRequest() );
|
|
|
|
|
|
2020-07-19 19:50:37 +00:00
|
|
|
$handler = new FallbackContentHandler( 'horkyporky' );
|
2019-08-21 15:51:10 +00:00
|
|
|
$slotDiffRenderer = $handler->getSlotDiffRenderer( $context );
|
|
|
|
|
|
|
|
|
|
$oldContent = $handler->unserializeContent( 'Foo' );
|
|
|
|
|
$newContent = $handler->unserializeContent( 'Foo bar' );
|
|
|
|
|
|
|
|
|
|
$diff = $slotDiffRenderer->getDiff( $oldContent, $newContent );
|
|
|
|
|
$this->assertNotEmpty( $diff );
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-14 14:01:58 +00:00
|
|
|
/**
|
|
|
|
|
* @covers FallbackContentHandler::fillParserOutput
|
|
|
|
|
*/
|
|
|
|
|
public function testGetParserOutput() {
|
|
|
|
|
$this->setUserLang( 'en' );
|
|
|
|
|
$this->setContentLang( 'qqx' );
|
|
|
|
|
|
|
|
|
|
$title = Title::newFromText( 'Test' );
|
|
|
|
|
$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 );
|
|
|
|
|
}
|
2019-08-21 15:51:10 +00:00
|
|
|
}
|