X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2Fparser%2FParserOutputTest.php;h=441d60df7bea4ac85d6488904fb53b3eaf093681;hp=e660e0964320ab1988fc6803a9b0ff7bba586ff6;hb=92cf49df5ca0c5dea25f5ae651996d79a2ce25af;hpb=c6f49906d901c4421c51542ff8e6640218aa8df9 diff --git a/tests/phpunit/includes/parser/ParserOutputTest.php b/tests/phpunit/includes/parser/ParserOutputTest.php index e660e09643..441d60df7b 100644 --- a/tests/phpunit/includes/parser/ParserOutputTest.php +++ b/tests/phpunit/includes/parser/ParserOutputTest.php @@ -1,5 +1,7 @@ assertArrayNotHasKey( 'foo', $properties ); } + /** + * @covers ParserOutput::getText + * @dataProvider provideGetText + * @param array $options Options to getText() + * @param array $poState ParserOptions state fields to set + * @param string $text Parser text + * @param string $expect Expected output + */ + public function testGetText( $options, $poState, $text, $expect ) { + $this->setMwGlobals( [ + 'wgArticlePath' => '/wiki/$1', + 'wgScriptPath' => '/w', + 'wgScript' => '/w/index.php', + ] ); + + $po = new ParserOutput( $text ); + + // Emulate Parser + $po->setEditSectionTokens( true ); + + if ( $poState ) { + $wrap = TestingAccessWrapper::newFromObject( $po ); + foreach ( $poState as $key => $value ) { + $wrap->$key = $value; + } + } + + $actual = $po->getText( $options ); + $this->assertSame( $expect, $actual ); + } + + public static function provideGetText() { + // @codingStandardsIgnoreStart Generic.Files.LineLength + $text = <<Test document. +

+ + +

Section 1Section 1

+

One +

+

Section 2Section 2

+

Two +

+

Section 2.1Section 2.1

+

Two point one +

+

Section 3Section 3

+

Three +

+EOF; + + return [ + 'No stateless options, default state' => [ + [], [], $text, <<Test document. +

+ + +

Section 1[edit]

+

One +

+

Section 2[edit]

+

Two +

+

Section 2.1[edit]

+

Two point one +

+

Section 3[edit]

+

Three +

+EOF + ], + 'No stateless options, TOC statefully disabled' => [ + [], [ 'mTOCEnabled' => false ], $text, <<Test document. +

+ +

Section 1[edit]

+

One +

+

Section 2[edit]

+

Two +

+

Section 2.1[edit]

+

Two point one +

+

Section 3[edit]

+

Three +

+EOF + ], + 'No stateless options, section edits statefully disabled' => [ + [], [ 'mEditSectionTokens' => false ], $text, <<Test document. +

+ + +

Section 1

+

One +

+

Section 2

+

Two +

+

Section 2.1

+

Two point one +

+

Section 3

+

Three +

+EOF + ], + 'Stateless options override stateful settings' => [ + [ 'allowTOC' => true, 'enableSectionEditLinks' => true ], + [ 'mTOCEnabled' => false, 'mEditSectionTokens' => false ], + $text, <<Test document. +

+ + +

Section 1[edit]

+

One +

+

Section 2[edit]

+

Two +

+

Section 2.1[edit]

+

Two point one +

+

Section 3[edit]

+

Three +

+EOF + ], + 'Statelessly disable section edit links' => [ + [ 'enableSectionEditLinks' => false ], [], $text, <<Test document. +

+ + +

Section 1

+

One +

+

Section 2

+

Two +

+

Section 2.1

+

Two point one +

+

Section 3

+

Three +

+EOF + ], + 'Statelessly disable TOC' => [ + [ 'allowTOC' => false ], [], $text, <<Test document. +

+ +

Section 1[edit]

+

One +

+

Section 2[edit]

+

Two +

+

Section 2.1[edit]

+

Two point one +

+

Section 3[edit]

+

Three +

+EOF + ], + ]; + // @codingStandardsIgnoreEnd + } + }