From 41149d80725947a2f5d23a7faf7ab8c15a38c010 Mon Sep 17 00:00:00 2001 From: Thiemo Kreuz Date: Tue, 21 Jul 2020 13:19:38 +0200 Subject: [PATCH] Restore preview of a section alone We broke this feature in December 2019 because it was never covered by any tests. Full explanation in T245376. All the features we care about are covered by tests. If all existing tests succeed, that should be proof enough that this patch does not introduce any new regression. Bug: T245376 Change-Id: I1a447884bdc507ac762d212466496b4591c18090 --- src/Cite.php | 3 +-- tests/phpunit/unit/CiteUnitTest.php | 23 +++++++++++++++++++---- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/Cite.php b/src/Cite.php index 7ad3d62e1..55f1f528c 100644 --- a/src/Cite.php +++ b/src/Cite.php @@ -339,8 +339,7 @@ class Cite { if ( $this->inReferencesGroup !== null ) { $groupRefs = $this->referenceStack->getGroupRefs( $group ); - // In preview mode, it's possible to reach this with the ref *not* being known - if ( $text === null || !isset( $groupRefs[$name] ) ) { + if ( $text === null ) { return ''; } diff --git a/tests/phpunit/unit/CiteUnitTest.php b/tests/phpunit/unit/CiteUnitTest.php index 15bdd3658..3f07410b4 100644 --- a/tests/phpunit/unit/CiteUnitTest.php +++ b/tests/phpunit/unit/CiteUnitTest.php @@ -479,7 +479,8 @@ class CiteUnitTest extends \MediaWikiUnitTestCase { array $initialRefs, string $expectOutput, array $expectedErrors, - array $expectedRefs + array $expectedRefs, + bool $isSectionPreview = false ) { $mockParser = $this->createMock( Parser::class ); $mockParser->method( 'getStripState' ) @@ -504,7 +505,7 @@ class CiteUnitTest extends \MediaWikiUnitTestCase { $mockFootnoteMarkFormatter = $this->createMock( FootnoteMarkFormatter::class ); $mockFootnoteMarkFormatter->method( 'linkRef' )->willReturn( '' ); - $cite = $this->newCite(); + $cite = $this->newCite( $isSectionPreview ); /** @var Cite $spy */ $spy = TestingAccessWrapper::newFromObject( $cite ); $spy->errorReporter = $mockErrorReporter; @@ -623,6 +624,20 @@ class CiteUnitTest extends \MediaWikiUnitTestCase { ], ] ], + 'T245376: Preview a list-defined ref that was never used' => [ + 'text' => 'T245376', + 'argv' => [ 'name' => 'a' ], + 'inReferencesGroup' => '', + 'initialRefs' => [], + 'expectOutput' => '', + 'expectedErrors' => [], + 'expectedRefs' => [ + '' => [ + 'a' => [ 'text' => 'T245376' ], + ], + ], + 'isSectionPreview' => true, + ], 'Mismatched text in references' => [ 'text-2', [ @@ -702,10 +717,10 @@ class CiteUnitTest extends \MediaWikiUnitTestCase { clone $cite; } - private function newCite() : Cite { + private function newCite( bool $isSectionPreview = false ) : Cite { $mockOptions = $this->createMock( ParserOptions::class ); $mockOptions->method( 'getIsPreview' )->willReturn( false ); - $mockOptions->method( 'getIsSectionPreview' )->willReturn( false ); + $mockOptions->method( 'getIsSectionPreview' )->willReturn( $isSectionPreview ); $mockOptions->method( 'getUserLangObj' )->willReturn( $this->createMock( Language::class ) ); $mockParser = $this->createMock( Parser::class );