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=fe46f2cc632337786989323618aff8959b360eaa;hb=92cf49df5ca0c5dea25f5ae651996d79a2ce25af;hpb=4d22e6ff4e13ebf34f45de935cc181fbd24e523f diff --git a/tests/phpunit/includes/parser/ParserOutputTest.php b/tests/phpunit/includes/parser/ParserOutputTest.php index fe46f2cc63..441d60df7b 100644 --- a/tests/phpunit/includes/parser/ParserOutputTest.php +++ b/tests/phpunit/includes/parser/ParserOutputTest.php @@ -1,5 +1,7 @@ assertFalse( $po->hasCustomDataUpdates() ); + public function testGetText( $options, $poState, $text, $expect ) { + $this->setMwGlobals( [ + 'wgArticlePath' => '/wiki/$1', + 'wgScriptPath' => '/w', + 'wgScript' => '/w/index.php', + ] ); - $dataUpdate = $this->getMock( 'DataUpdate' ); - $po->addSecondaryDataUpdate( $dataUpdate ); - $this->assertTrue( $po->hasCustomDataUpdates() ); - } + $po = new ParserOutput( $text ); - /** - * @covers ParserOutput::getSecondaryDataUpdates - * @covers ParserOutput::addSecondaryDataUpdate - */ - public function testGetSecondaryDataUpdates() { - // NOTE: getSecondaryDataUpdates always returns a LinksUpdate object - // in addition to the DataUpdates registered via addSecondaryDataUpdate(). + // Emulate Parser + $po->setEditSectionTokens( true ); - $title = Title::makeTitle( NS_MAIN, 'Dummy' ); - $title->resetArticleID( 7777777 ); + if ( $poState ) { + $wrap = TestingAccessWrapper::newFromObject( $po ); + foreach ( $poState as $key => $value ) { + $wrap->$key = $value; + } + } - $po = new ParserOutput(); - $this->assertCount( 1, $po->getSecondaryDataUpdates( $title ) ); + $actual = $po->getText( $options ); + $this->assertSame( $expect, $actual ); + } - $dataUpdate = $this->getMock( 'DataUpdate' ); - $po->addSecondaryDataUpdate( $dataUpdate ); - $this->assertCount( 2, $po->getSecondaryDataUpdates( $title ) ); + 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; - // Test Fallback to getTitleText - $this->insertPage( 'Project:ParserOutputTestDummyPage' ); - $po->setTitleText( 'Project:ParserOutputTestDummyPage' ); - $this->assertCount( 2, $po->getSecondaryDataUpdates() ); - } + return [ + 'No stateless options, default state' => [ + [], [], $text, <<Test document. +

+ - /** - * @covers ParserOutput::getSecondaryDataUpdates - * @covers ParserOutput::__sleep - */ - public function testGetSecondaryDataUpdates_serialization() { - $title = Title::makeTitle( NS_MAIN, 'Dummy' ); - $title->resetArticleID( 7777777 ); +

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. +

- $po = new ParserOutput(); +

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. +

+ - // Serializing is fine with no custom DataUpdates. - $po = unserialize( serialize( $po ) ); - $this->assertCount( 1, $po->getSecondaryDataUpdates( $title ) ); +

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. +

+ - // If there are custom DataUpdates, getSecondaryDataUpdates - // should fail after serialization. - $dataUpdate = $this->getMock( 'DataUpdate' ); - $po->addSecondaryDataUpdate( $dataUpdate ); - $po = unserialize( serialize( $po ) ); +

Section 1

+

One +

+

Section 2

+

Two +

+

Section 2.1

+

Two point one +

+

Section 3

+

Three +

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

- $this->setExpectedException( 'MWException' ); - $po->getSecondaryDataUpdates( $title ); +

Section 1[edit]

+

One +

+

Section 2[edit]

+

Two +

+

Section 2.1[edit]

+

Two point one +

+

Section 3[edit]

+

Three +

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