Mock the relevant services that need the DB instead, when possible. When not possible, e.g. because DB access is needed for the test to make sense, add the test to the Database group instead. Change-Id: Iefbfe00bedc243906c6b860572568343268646cc
69 lines
1.9 KiB
PHP
69 lines
1.9 KiB
PHP
<?php
|
|
|
|
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' );
|
|
$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::makeTitle( NS_MAIN, '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 );
|
|
}
|
|
}
|