wiki.techinc.nl/tests/phpunit/includes/content/FallbackContentHandlerTest.php
James D. Forrester ad06527fb4 Reorg: Namespace the Title class
This is moderately messy.

Process was principally:

* xargs rg --files-with-matches '^use Title;' | grep 'php$' | \
  xargs -P 1 -n 1 sed -i -z 's/use Title;/use MediaWiki\\Title\\Title;/1'
* rg --files-without-match 'MediaWiki\\Title\\Title;' . | grep 'php$' | \
  xargs rg --files-with-matches 'Title\b' | \
  xargs -P 1 -n 1 sed -i -z 's/\nuse /\nuse MediaWiki\\Title\\Title;\nuse /1'
* composer fix

Then manual fix-ups for a few files that don't have any use statements.

Bug: T166010
Follows-Up: Ia5d8cb759dc3bc9e9bbe217d0fb109e2f8c4101a
Change-Id: If8fc9d0d95fc1a114021e282a706fc3e7da3524b
2023-03-02 08:46:53 -05:00

67 lines
1.8 KiB
PHP

<?php
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 ]
);
}
/**
* @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 );
}
}