Debian Codegraph @

tests/phpunit/integration/includes/parser/Parsoid/ParsoidParserTest.php

raw symbols SCIP
1 <?php
2
3 namespace MediaWiki\Tests\Parser\Parsoid;
4
5 use MediaWiki\MediaWikiServices;
6 use MediaWiki\Parser\ParserOptions;
7 use MediaWiki\Parser\Parsoid\ParsoidParser;
8 use MediaWiki\Title\Title;
9 use MediaWikiIntegrationTestCase;
10
11 /**
12 * @covers \MediaWiki\Parser\Parsoid\ParsoidParser::parse
13 * @group Database
14 */
15 class ParsoidParserTest extends MediaWikiIntegrationTestCase {
16
17 /** @dataProvider provideParsoidParserHtml */
18 public function testParsoidParserHtml( $args, $expected, $getTextOpts = [] ) {
19 $parsoidParser = $this->getServiceContainer()
20 ->getParsoidParserFactory()->create();
21 if ( is_string( $args[1] ?? '' ) ) {
22 // Make a PageReference from a string
23 $args[1] = Title::newFromText( $args[1] ?? 'Main Page' );
24 }
25 if ( ( $args[2] ?? null ) === null ) {
26 // Make default ParserOptions if none are provided
27 $args[2] = ParserOptions::newFromAnon();
28 }
29 $output = $parsoidParser->parse( ...$args );
30 $html = $output->getRawText();
31 $this->assertStringContainsString( $expected, $html );
32 $this->assertSame(
33 $args[1]->getPrefixedDBkey(),
34 $output->getExtensionData( ParsoidParser::PARSOID_TITLE_KEY )
35 );
36 $usedOptions = [
37 'collapsibleSections',
38 'disableContentConversion',
39 'interfaceMessage',
40 'isPreview',
41 'maxIncludeSize',
42 'suppressSectionEditLinks',
43 'wrapclass',
44 ];
45 $this->assertEqualsCanonicalizing( $usedOptions, $output->getUsedOptions() );
46
47 $pipeline = MediaWikiServices::getInstance()->getDefaultOutputPipeline();
48 $pipeline->run( $output, $args[2], [] );
49 $this->assertArrayEquals( $usedOptions, $output->getUsedOptions() );
50 }
51
52 public static function provideParsoidParserHtml() {
53 return [
54 [ [ 'Hello, World' ], 'Hello, World' ],
55 [ [ '__NOTOC__' ], '<meta property="mw:PageProp/notoc"' ],
56 // Once we support $linestart and other parser options we
57 // can extend these tests.
58 ];
59 }
60
61 public function testParsoidParseRevisions() {
62 $helloWorld = 'Hello, World';
63
64 $page = $this->getNonexistingTestPage( 'Test' );
65 $this->editPage( $page, $helloWorld );
66 $pageTitle = $page->getTitle();
67
68 $parsoidParser = $this->getServiceContainer()
69 ->getParsoidParserFactory()->create();
70 $opts = ParserOptions::newFromAnon();
71 $output = $parsoidParser->parse(
72 $helloWorld,
73 $pageTitle,
74 $opts,
75 true,
76 true,
77 $page->getRevisionRecord()->getId()
78 );
79 $html = $output->getRawText();
80 $this->assertStringContainsString( $helloWorld, $html );
81 $this->assertSame(
82 $pageTitle->getPrefixedDBkey(),
83 $output->getExtensionData( ParsoidParser::PARSOID_TITLE_KEY )
84 );
85 $usedOptions = [
86 'collapsibleSections',
87 'disableContentConversion',
88 'interfaceMessage',
89 'isPreview',
90 'maxIncludeSize',
91 'suppressSectionEditLinks',
92 'wrapclass',
93 ];
94 $this->assertArrayEquals( $usedOptions, $output->getUsedOptions() );
95
96 $pipeline = MediaWikiServices::getInstance()->getDefaultOutputPipeline();
97 $pipeline->run( $output, $opts, [] );
98 $this->assertArrayEquals( $usedOptions, $output->getUsedOptions() );
99 }
100 }