Restore preview of a <references> 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
This commit is contained in:
Thiemo Kreuz 2020-07-21 13:19:38 +02:00
parent f347863eab
commit 41149d8072
2 changed files with 20 additions and 6 deletions

View file

@ -339,8 +339,7 @@ class Cite {
if ( $this->inReferencesGroup !== null ) { if ( $this->inReferencesGroup !== null ) {
$groupRefs = $this->referenceStack->getGroupRefs( $group ); $groupRefs = $this->referenceStack->getGroupRefs( $group );
// In preview mode, it's possible to reach this with the ref *not* being known if ( $text === null ) {
if ( $text === null || !isset( $groupRefs[$name] ) ) {
return ''; return '';
} }

View file

@ -479,7 +479,8 @@ class CiteUnitTest extends \MediaWikiUnitTestCase {
array $initialRefs, array $initialRefs,
string $expectOutput, string $expectOutput,
array $expectedErrors, array $expectedErrors,
array $expectedRefs array $expectedRefs,
bool $isSectionPreview = false
) { ) {
$mockParser = $this->createMock( Parser::class ); $mockParser = $this->createMock( Parser::class );
$mockParser->method( 'getStripState' ) $mockParser->method( 'getStripState' )
@ -504,7 +505,7 @@ class CiteUnitTest extends \MediaWikiUnitTestCase {
$mockFootnoteMarkFormatter = $this->createMock( FootnoteMarkFormatter::class ); $mockFootnoteMarkFormatter = $this->createMock( FootnoteMarkFormatter::class );
$mockFootnoteMarkFormatter->method( 'linkRef' )->willReturn( '<foot />' ); $mockFootnoteMarkFormatter->method( 'linkRef' )->willReturn( '<foot />' );
$cite = $this->newCite(); $cite = $this->newCite( $isSectionPreview );
/** @var Cite $spy */ /** @var Cite $spy */
$spy = TestingAccessWrapper::newFromObject( $cite ); $spy = TestingAccessWrapper::newFromObject( $cite );
$spy->errorReporter = $mockErrorReporter; $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' => [ 'Mismatched text in references' => [
'text-2', 'text-2',
[ [
@ -702,10 +717,10 @@ class CiteUnitTest extends \MediaWikiUnitTestCase {
clone $cite; clone $cite;
} }
private function newCite() : Cite { private function newCite( bool $isSectionPreview = false ) : Cite {
$mockOptions = $this->createMock( ParserOptions::class ); $mockOptions = $this->createMock( ParserOptions::class );
$mockOptions->method( 'getIsPreview' )->willReturn( false ); $mockOptions->method( 'getIsPreview' )->willReturn( false );
$mockOptions->method( 'getIsSectionPreview' )->willReturn( false ); $mockOptions->method( 'getIsSectionPreview' )->willReturn( $isSectionPreview );
$mockOptions->method( 'getUserLangObj' )->willReturn( $mockOptions->method( 'getUserLangObj' )->willReturn(
$this->createMock( Language::class ) ); $this->createMock( Language::class ) );
$mockParser = $this->createMock( Parser::class ); $mockParser = $this->createMock( Parser::class );