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 );