mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Cite
synced 2024-11-27 16:30:12 +00:00
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:
parent
f347863eab
commit
41149d8072
|
@ -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 '';
|
||||
}
|
||||
|
||||
|
|
|
@ -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( '<foot />' );
|
||||
|
||||
$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 );
|
||||
|
|
Loading…
Reference in a new issue