wiki.techinc.nl/tests/phpunit/includes/content/FallbackContentHandlerTest.php
Amir Sarabadani bbe704b5c1 Reorg: Move some of request related classes to MediaWiki/Request
Redoing I5ea70120d74 but without moving WebRequest that caused issues
with phan-taint-plugin.

Moving:
 - DerivativeRequest
 - FauxRequest
 - FauxRequestUpload
 - PathRouter
 - WebRequestUpload

Bug: T321882
Change-Id: I832b133aaf61ee9f6190b0227d2f3de99bd1717b
2022-10-28 10:15:31 +00:00

66 lines
1.8 KiB
PHP

<?php
use MediaWiki\Request\FauxRequest;
/**
* 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 ]
);
}
/**
* @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' );
$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 = 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 );
}
}