overrideConfigValues( [ MainConfigNames::ArticlePath => '/wiki/$1', MainConfigNames::ScriptPath => '/w', MainConfigNames::Script => '/w/index.php', ] ); $po = new ParserOutput( $text ); self::initSections( $po ); $actual = MediaWikiServices::getInstance()->getDefaultOutputTransform()->transform( $po, $options ) ->getTransformedText(); $this->assertSame( $expect, $actual ); } private static function initSections( ParserOutput $po ): void { $po->setTOCData( new TOCData( SectionMetadata::fromLegacy( [ 'index' => "1", 'level' => 1, 'toclevel' => 1, 'number' => "1", 'line' => "Section 1", 'anchor' => "Section_1" ] ), SectionMetadata::fromLegacy( [ 'index' => "2", 'level' => 1, 'toclevel' => 1, 'number' => "2", 'line' => "Section 2", 'anchor' => "Section_2" ] ), SectionMetadata::fromLegacy( [ 'index' => "3", 'level' => 2, 'toclevel' => 2, 'number' => "2.1", 'line' => "Section 2.1", 'anchor' => "Section_2.1" ] ), SectionMetadata::fromLegacy( [ 'index' => "4", 'level' => 1, 'toclevel' => 1, 'number' => "3", 'line' => "Section 3", 'anchor' => "Section_3" ] ), ) ); } public static function provideTransform() { $text = <<Test document.

Section 1Section 1

One

Section 2Section 2

Two

Section 2.1Section 2.1

Two point one

Section 3Section 3

Three

EOF; $dedupText = <<This is a test document.

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

Section 1[edit]

One

Section 2[edit]

Two

Section 2.1

Two point one

Section 3[edit]

Three

EOF ], '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 ], 'Disable TOC, but wrap' => [ [ 'allowTOC' => false, 'wrapperDivClass' => 'mw-parser-output' ], $text, <<

Test document.

Section 1[edit]

One

Section 2[edit]

Two

Section 2.1

Two point one

Section 3[edit]

Three

EOF ], 'Style deduplication' => [ [], $dedupText, <<This is a test document.

EOF ], 'Style deduplication disabled' => [ [ 'deduplicateStyles' => false ], $dedupText, $dedupText ], ]; // phpcs:enable } /** * @covers \Mediawiki\ParserOutputTransform\DefaultOutputTransform::transform */ public function testTransform_failsIfNoText() { $po = new ParserOutput( null ); $this->expectException( LogicException::class ); MediaWikiServices::getInstance()->getDefaultOutputTransform()->transform( $po, [] ); } public static function provideTransform_absoluteURLs() { yield 'empty' => [ 'text' => '', 'expectedText' => '', ]; yield 'no-links' => [ 'text' => '

test

', 'expectedText' => '

test

', ]; yield 'simple link' => [ 'text' => 'test', 'expectedText' => 'test', ]; yield 'already absolute, relative' => [ 'text' => 'test', 'expectedText' => 'test', ]; yield 'already absolute, https' => [ 'text' => 'test', 'expectedText' => 'test', ]; yield 'external' => [ 'text' => 'test', 'expectedText' => 'test', ]; } /** * @covers \Mediawiki\ParserOutputTransform\DefaultOutputTransform::transform * @dataProvider provideTransform_absoluteURLs */ public function testTransform_absoluteURLs( string $text, string $expectedText ) { $this->overrideConfigValue( MainConfigNames::Server, '//TEST_SERVER' ); $po = new ParserOutput( $text ); $actual = MediaWikiServices::getInstance()->getDefaultOutputTransform() ->transform( $po, [ 'absoluteURLs' => true ] )->getTransformedText(); $this->assertSame( $expectedText, $actual ); } }