https://gerrit.wikimedia.org/r/q/owner:Krinkle+is:merged+message:Widen > Given all called methods are de-facto and liberally claimed, and > that we keep the coverage limited to the subject class, it maintains > the spirit and intent by listing the class explicitly instead. > > PHPUnit offers a more precise tool when you need it (i.e. when testing > legacy monster/god classes), but for well-written code, the > class-wide tag is exactly what you want. > > We lose useful coverage and waste valuable time on keeping tags > accurate through refactors (or worse, forget to do so). > Tracking tiny per-method details wastes time in realizing (and > fixing) when people inevitably don't keep them in sync, and time > lost in finding uncovered code to write tests to realize it was > already covered but "not yet claimed". While at it, also fix PHPUnit warnings in CssContentHandlerIntegrationTest and JavaScriptContentHandlerIntegrationTest about not having any `@covers` annotations. Change-Id: I5afd9fe0bca0fa86cc096f6e5e79f2ba1cfbfa77
66 lines
2.1 KiB
PHP
66 lines
2.1 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();
|
|
$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 );
|
|
}
|
|
}
|