This is the fourth patch of a series of patches to remove ParserOutput::getText() calls from core. This series of patches should be functionally equivalent to I2b4bcddb234f10fd8592570cb0496adf3271328e. Here we replace calls to getText where a ContentRenderer is available close by by temporary ParserOutput::runOutputPipeline that will eventually be replaced by a call to (probably) ContentRenderer (T371004). Doing this work in stages allows us to separate the work of "bring ParserOptions to the call site" from the work of "bringing ContentRenderer(ish) to the call site", since both need to be done for to make ParserOutput a value object (T293512). Change-Id: Ib4f9357293dc230df6e0ca2379a1e2a4cc1b91b7 Bug: T293512
68 lines
2.1 KiB
PHP
68 lines
2.1 KiB
PHP
<?php
|
|
|
|
use MediaWiki\Title\Title;
|
|
use Wikimedia\Parsoid\ParserTests\TestUtils;
|
|
|
|
/**
|
|
* @group ContentHandler
|
|
* @group Database
|
|
* ^--- needed, because we do need the database to test link updates
|
|
* @covers \MediaWiki\Content\TextContentHandler
|
|
*/
|
|
class TextContentHandlerIntegrationTest extends MediaWikiLangTestCase {
|
|
|
|
public static function provideGetParserOutput() {
|
|
yield 'Basic render' => [
|
|
'title' => 'TextContentTest_testGetParserOutput',
|
|
'model' => CONTENT_MODEL_TEXT,
|
|
'text' => "hello ''world'' & [[stuff]]\n",
|
|
'expectedHtml' => "<pre>hello ''world'' & [[stuff]]\n</pre>",
|
|
'expectedFields' => [ 'Links' => [] ]
|
|
];
|
|
yield 'Multi line render' => [
|
|
'title' => 'TextContentTest_testGetParserOutput',
|
|
'model' => CONTENT_MODEL_TEXT,
|
|
'text' => "Test 1\nTest 2\n\nTest 3\n",
|
|
'expectedHtml' => "<pre>Test 1\nTest 2\n\nTest 3\n</pre>",
|
|
'expectedFields' => [ 'Links' => [] ]
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @dataProvider provideGetParserOutput
|
|
*/
|
|
public function testGetParserOutput( $title, $model, $text, $expectedHtml,
|
|
$expectedFields = null, $parserOptions = null
|
|
) {
|
|
$title = Title::newFromText( $title );
|
|
$content = ContentHandler::makeContent( $text, $title, $model );
|
|
$contentRenderer = $this->getServiceContainer()->getContentRenderer();
|
|
if ( $parserOptions === null ) {
|
|
$parserOptions = ParserOptions::newFromAnon();
|
|
}
|
|
$po = $contentRenderer->getParserOutput( $content, $title, null, $parserOptions );
|
|
|
|
// TODO T371004
|
|
$processedPo = $po->runOutputPipeline( $parserOptions, [] );
|
|
$html = $processedPo->getContentHolderText();
|
|
$html = preg_replace( '#<!--.*?-->#sm', '', $html ); // strip comments
|
|
$html = TestUtils::stripParsoidIds( $html );
|
|
|
|
if ( $expectedHtml !== null ) {
|
|
$this->assertEquals( TestUtils::stripParsoidIds( $expectedHtml ), trim( $html ) );
|
|
}
|
|
|
|
if ( $expectedFields ) {
|
|
foreach ( $expectedFields as $field => $exp ) {
|
|
$getter = 'get' . ucfirst( $field );
|
|
$v = $processedPo->$getter();
|
|
|
|
if ( is_array( $exp ) ) {
|
|
$this->assertArrayEquals( $exp, $v );
|
|
} else {
|
|
$this->assertEquals( $exp, $v );
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|