Debian Codegraph @

tests/phpunit/includes/content/TextContentHandlerIntegrationTest.php

raw symbols SCIP
1 <?php
2
3 use MediaWiki\Content\ContentHandler;
4 use MediaWiki\Parser\ParserOptions;
5 use MediaWiki\Title\Title;
6 use Wikimedia\Parsoid\ParserTests\TestUtils;
7
8 /**
9 * @group ContentHandler
10 * @group Database
11 * ^--- needed, because we do need the database to test link updates
12 * @covers \MediaWiki\Content\TextContentHandler
13 */
14 class TextContentHandlerIntegrationTest extends MediaWikiLangTestCase {
15
16 public static function provideGetParserOutput() {
17 yield 'Basic render' => [
18 'title' => 'TextContentTest_testGetParserOutput',
19 'model' => CONTENT_MODEL_TEXT,
20 'text' => "hello ''world'' & [[stuff]]\n",
21 'expectedHtml' => "<pre>hello ''world'' &amp; [[stuff]]\n</pre>",
22 'expectedFields' => [ 'Links' => [] ]
23 ];
24 yield 'Multi line render' => [
25 'title' => 'TextContentTest_testGetParserOutput',
26 'model' => CONTENT_MODEL_TEXT,
27 'text' => "Test 1\nTest 2\n\nTest 3\n",
28 'expectedHtml' => "<pre>Test 1\nTest 2\n\nTest 3\n</pre>",
29 'expectedFields' => [ 'Links' => [] ]
30 ];
31 }
32
33 /**
34 * @dataProvider provideGetParserOutput
35 */
36 public function testGetParserOutput( $title, $model, $text, $expectedHtml,
37 $expectedFields = null, $parserOptions = null
38 ) {
39 $title = Title::newFromText( $title );
40 $content = ContentHandler::makeContent( $text, $title, $model );
41 $contentRenderer = $this->getServiceContainer()->getContentRenderer();
42 if ( $parserOptions === null ) {
43 $parserOptions = ParserOptions::newFromAnon();
44 }
45 $po = $contentRenderer->getParserOutput( $content, $title, null, $parserOptions );
46
47 // TODO T371004
48 $processedPo = $po->runOutputPipeline( $parserOptions, [] );
49 $html = $processedPo->getContentHolderText();
50 $html = preg_replace( '#<!--.*?-->#sm', '', $html ); // strip comments
51 $html = TestUtils::stripParsoidIds( $html );
52
53 if ( $expectedHtml !== null ) {
54 $this->assertEquals( TestUtils::stripParsoidIds( $expectedHtml ), trim( $html ) );
55 }
56
57 if ( $expectedFields ) {
58 foreach ( $expectedFields as $field => $exp ) {
59 $getter = 'get' . ucfirst( $field );
60 $v = $processedPo->$getter();
61
62 if ( is_array( $exp ) ) {
63 $this->assertArrayEquals( $exp, $v );
64 } else {
65 $this->assertEquals( $exp, $v );
66 }
67 }
68 }
69 }
70 }