mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Cite
synced 2024-11-28 00:40:12 +00:00
Merge "Show "Preview" headline in user instead of content language"
This commit is contained in:
commit
a8e882e39f
15
src/Cite.php
15
src/Cite.php
|
@ -99,11 +99,6 @@ class Cite {
|
|||
*/
|
||||
private $referenceStack;
|
||||
|
||||
/**
|
||||
* @var ReferenceMessageLocalizer $messageLocalizer
|
||||
*/
|
||||
private $messageLocalizer;
|
||||
|
||||
/**
|
||||
* @param Parser $parser
|
||||
*/
|
||||
|
@ -117,12 +112,12 @@ class Cite {
|
|||
$parser
|
||||
);
|
||||
$this->referenceStack = new ReferenceStack( $this->errorReporter );
|
||||
$this->messageLocalizer = new ReferenceMessageLocalizer( $parser->getContentLanguage() );
|
||||
$citeKeyFormatter = new CiteKeyFormatter( $this->messageLocalizer );
|
||||
$messageLocalizer = new ReferenceMessageLocalizer( $parser->getContentLanguage() );
|
||||
$citeKeyFormatter = new CiteKeyFormatter( $messageLocalizer );
|
||||
$this->footnoteMarkFormatter = new FootnoteMarkFormatter(
|
||||
$this->mParser, $this->errorReporter, $citeKeyFormatter, $this->messageLocalizer );
|
||||
$this->mParser, $this->errorReporter, $citeKeyFormatter, $messageLocalizer );
|
||||
$this->footnoteBodyFormatter = new FootnoteBodyFormatter(
|
||||
$this->mParser, $this->errorReporter, $citeKeyFormatter, $this->messageLocalizer );
|
||||
$this->mParser, $this->errorReporter, $citeKeyFormatter, $messageLocalizer );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -556,7 +551,7 @@ class Cite {
|
|||
}
|
||||
}
|
||||
if ( $isSectionPreview && $s !== '' ) {
|
||||
$headerMsg = $this->messageLocalizer->msg( 'cite_section_preview_references' );
|
||||
$headerMsg = wfMessage( 'cite_section_preview_references' );
|
||||
if ( !$headerMsg->isDisabled() ) {
|
||||
$s = '<h2 id="mw-ext-cite-cite_section_preview_references_header" >'
|
||||
. $headerMsg->escaped()
|
||||
|
|
119
tests/phpunit/CiteIntegrationTest.php
Normal file
119
tests/phpunit/CiteIntegrationTest.php
Normal file
|
@ -0,0 +1,119 @@
|
|||
<?php
|
||||
|
||||
namespace Cite\Tests;
|
||||
|
||||
use Cite\Cite;
|
||||
use Cite\CiteErrorReporter;
|
||||
use Cite\FootnoteBodyFormatter;
|
||||
use Cite\ReferenceStack;
|
||||
use Wikimedia\TestingAccessWrapper;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Cite\Cite
|
||||
*
|
||||
* @license GPL-2.0-or-later
|
||||
*/
|
||||
class CiteIntegrationTest extends \MediaWikiIntegrationTestCase {
|
||||
|
||||
protected function setUp() : void {
|
||||
parent::setUp();
|
||||
|
||||
$this->setMwGlobals( [
|
||||
'wgLanguageCode' => 'qqx',
|
||||
] );
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::checkRefsNoReferences
|
||||
* @dataProvider provideCheckRefsNoReferences
|
||||
*/
|
||||
public function testCheckRefsNoReferences(
|
||||
array $initialRefs, bool $isSectionPreview, string $expectedOutput
|
||||
) {
|
||||
global $wgCiteResponsiveReferences;
|
||||
$wgCiteResponsiveReferences = true;
|
||||
|
||||
$mockReferenceStack = $this->createMock( ReferenceStack::class );
|
||||
$mockReferenceStack->method( 'getGroups' )->willReturn( array_keys( $initialRefs ) );
|
||||
$mockReferenceStack->method( 'getGroupRefs' )->willReturnCallback( function ( $group ) use (
|
||||
$initialRefs
|
||||
) {
|
||||
return $initialRefs[$group];
|
||||
} );
|
||||
|
||||
$mockErrorReporter = $this->createMock( CiteErrorReporter::class );
|
||||
$mockErrorReporter->method( 'halfParsed' )->willReturnCallback(
|
||||
function ( ...$args ) {
|
||||
return '(' . implode( '|', $args ) . ')';
|
||||
}
|
||||
);
|
||||
|
||||
$mockFootnoteBodyFormatter = $this->createMock( FootnoteBodyFormatter::class );
|
||||
$mockFootnoteBodyFormatter->method( 'referencesFormat' )->willReturn( '<references />' );
|
||||
|
||||
$cite = new Cite();
|
||||
/** @var Cite $spy */
|
||||
$spy = TestingAccessWrapper::newFromObject( $cite );
|
||||
$spy->referenceStack = $mockReferenceStack;
|
||||
$spy->errorReporter = $mockErrorReporter;
|
||||
$spy->footnoteBodyFormatter = $mockFootnoteBodyFormatter;
|
||||
$spy->isSectionPreview = $isSectionPreview;
|
||||
|
||||
$output = $cite->checkRefsNoReferences( $isSectionPreview );
|
||||
$this->assertSame( $expectedOutput, $output );
|
||||
}
|
||||
|
||||
public function provideCheckRefsNoReferences() {
|
||||
return [
|
||||
'Default group' => [
|
||||
[
|
||||
'' => [
|
||||
[
|
||||
'name' => 'a',
|
||||
]
|
||||
]
|
||||
],
|
||||
false,
|
||||
'<references />'
|
||||
],
|
||||
'Default group in preview' => [
|
||||
[
|
||||
'' => [
|
||||
[
|
||||
'name' => 'a',
|
||||
]
|
||||
]
|
||||
],
|
||||
true,
|
||||
"\n" . '<div class="mw-ext-cite-cite_section_preview_references" >' .
|
||||
'<h2 id="mw-ext-cite-cite_section_preview_references_header" >' .
|
||||
'(cite_section_preview_references)</h2><references /></div>'
|
||||
],
|
||||
'Named group' => [
|
||||
[
|
||||
'foo' => [
|
||||
[
|
||||
'name' => 'a',
|
||||
]
|
||||
]
|
||||
],
|
||||
false,
|
||||
"\n" . '<br />(cite_error_group_refs_without_references|foo)'
|
||||
],
|
||||
'Named group in preview' => [
|
||||
[
|
||||
'foo' => [
|
||||
[
|
||||
'name' => 'a',
|
||||
]
|
||||
]
|
||||
],
|
||||
true,
|
||||
"\n" . '<div class="mw-ext-cite-cite_section_preview_references" >' .
|
||||
'<h2 id="mw-ext-cite-cite_section_preview_references_header" >' .
|
||||
'(cite_section_preview_references)</h2><references /></div>'
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
}
|
|
@ -6,9 +6,8 @@ use Cite\Cite;
|
|||
use Cite\CiteErrorReporter;
|
||||
use Cite\FootnoteBodyFormatter;
|
||||
use Cite\FootnoteMarkFormatter;
|
||||
use Cite\ReferenceMessageLocalizer;
|
||||
use Cite\ReferenceStack;
|
||||
use Message;
|
||||
use MediaWikiUnitTestCase;
|
||||
use Parser;
|
||||
use ParserOutput;
|
||||
use StripState;
|
||||
|
@ -19,116 +18,7 @@ use Wikimedia\TestingAccessWrapper;
|
|||
*
|
||||
* @license GPL-2.0-or-later
|
||||
*/
|
||||
class CiteUnitTest extends \MediaWikiUnitTestCase {
|
||||
|
||||
protected function setUp() : void {
|
||||
global $wgCiteBookReferencing;
|
||||
|
||||
parent::setUp();
|
||||
$wgCiteBookReferencing = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::checkRefsNoReferences
|
||||
* @dataProvider provideCheckRefsNoReferences
|
||||
*/
|
||||
public function testCheckRefsNoReferences(
|
||||
array $initialRefs, bool $isSectionPreview, string $expectedOutput
|
||||
) {
|
||||
global $wgCiteResponsiveReferences;
|
||||
$wgCiteResponsiveReferences = true;
|
||||
|
||||
$cite = new Cite();
|
||||
$spy = TestingAccessWrapper::newFromObject( $cite );
|
||||
$mockReferenceStack = $this->createMock( ReferenceStack::class );
|
||||
$mockReferenceStack->method( 'getGroups' )->willReturn( array_keys( $initialRefs ) );
|
||||
$mockReferenceStack->method( 'getGroupRefs' )->willReturnCallback( function ( $group ) use (
|
||||
$initialRefs
|
||||
) {
|
||||
return $initialRefs[$group];
|
||||
} );
|
||||
$spy->referenceStack = $mockReferenceStack;
|
||||
$mockErrorReporter = $this->createMock( CiteErrorReporter::class );
|
||||
$mockErrorReporter->method( 'halfParsed' )->willReturnCallback(
|
||||
function ( ...$args ) {
|
||||
return '(' . implode( '|', $args ) . ')';
|
||||
}
|
||||
);
|
||||
/** @var CiteErrorReporter $mockErrorReporter */
|
||||
$spy->errorReporter = $mockErrorReporter;
|
||||
$mockFootnoteBodyFormatter = $this->createMock( FootnoteBodyFormatter::class );
|
||||
$mockFootnoteBodyFormatter->method( 'referencesFormat' )->willReturn( '<references />' );
|
||||
$spy->footnoteBodyFormatter = $mockFootnoteBodyFormatter;
|
||||
$spy->isSectionPreview = $isSectionPreview;
|
||||
$spy->messageLocalizer = $this->createMock( ReferenceMessageLocalizer::class );
|
||||
$spy->messageLocalizer->method( 'msg' )->willReturnCallback(
|
||||
function ( ...$args ) {
|
||||
$mockMessage = $this->createMock( Message::class );
|
||||
$mockMessage->method( 'escaped' )->willReturnCallback(
|
||||
function () use ( $args ) {
|
||||
return '(' . implode( '|', $args ) . ')';
|
||||
}
|
||||
);
|
||||
return $mockMessage;
|
||||
}
|
||||
);
|
||||
|
||||
$output = $cite->checkRefsNoReferences( $isSectionPreview );
|
||||
$this->assertSame( $expectedOutput, $output );
|
||||
}
|
||||
|
||||
public function provideCheckRefsNoReferences() {
|
||||
return [
|
||||
'Default group' => [
|
||||
[
|
||||
'' => [
|
||||
[
|
||||
'name' => 'a',
|
||||
]
|
||||
]
|
||||
],
|
||||
false,
|
||||
'<references />'
|
||||
],
|
||||
'Default group in preview' => [
|
||||
[
|
||||
'' => [
|
||||
[
|
||||
'name' => 'a',
|
||||
]
|
||||
]
|
||||
],
|
||||
true,
|
||||
"\n" . '<div class="mw-ext-cite-cite_section_preview_references" >' .
|
||||
'<h2 id="mw-ext-cite-cite_section_preview_references_header" >' .
|
||||
'(cite_section_preview_references)</h2><references /></div>'
|
||||
],
|
||||
'Named group' => [
|
||||
[
|
||||
'foo' => [
|
||||
[
|
||||
'name' => 'a',
|
||||
]
|
||||
]
|
||||
],
|
||||
false,
|
||||
"\n" . '<br />(cite_error_group_refs_without_references|foo)'
|
||||
],
|
||||
'Named group in preview' => [
|
||||
[
|
||||
'foo' => [
|
||||
[
|
||||
'name' => 'a',
|
||||
]
|
||||
]
|
||||
],
|
||||
true,
|
||||
"\n" . '<div class="mw-ext-cite-cite_section_preview_references" >' .
|
||||
'<h2 id="mw-ext-cite-cite_section_preview_references_header" >' .
|
||||
'(cite_section_preview_references)</h2><references /></div>'
|
||||
]
|
||||
];
|
||||
}
|
||||
class CiteUnitTest extends MediaWikiUnitTestCase {
|
||||
|
||||
/**
|
||||
* @covers ::validateRef
|
||||
|
@ -531,8 +421,7 @@ class CiteUnitTest extends \MediaWikiUnitTestCase {
|
|||
$mockParser = $this->createMock( Parser::class );
|
||||
$mockParser->method( 'getStripState' )
|
||||
->willReturn( $this->createMock( StripState::class ) );
|
||||
$cite = new Cite();
|
||||
$spy = TestingAccessWrapper::newFromObject( $cite );
|
||||
|
||||
$mockErrorReporter = $this->createMock( CiteErrorReporter::class );
|
||||
$mockErrorReporter->method( 'halfParsed' )->willReturnCallback(
|
||||
function ( ...$args ) {
|
||||
|
@ -544,10 +433,14 @@ class CiteUnitTest extends \MediaWikiUnitTestCase {
|
|||
return json_encode( $args );
|
||||
}
|
||||
);
|
||||
/** @var CiteErrorReporter $mockErrorReporter */
|
||||
$spy->errorReporter = $mockErrorReporter;
|
||||
|
||||
$mockFootnoteMarkFormatter = $this->createMock( FootnoteMarkFormatter::class );
|
||||
$mockFootnoteMarkFormatter->method( 'linkRef' )->willReturn( '<foot />' );
|
||||
|
||||
$cite = new Cite();
|
||||
/** @var Cite $spy */
|
||||
$spy = TestingAccessWrapper::newFromObject( $cite );
|
||||
$spy->errorReporter = $mockErrorReporter;
|
||||
$spy->footnoteMarkFormatter = $mockFootnoteMarkFormatter;
|
||||
$spy->inReferencesGroup = $inReferencesGroup;
|
||||
$spy->referenceStack = $this->createMock( ReferenceStack::class );
|
||||
|
@ -705,7 +598,9 @@ class CiteUnitTest extends \MediaWikiUnitTestCase {
|
|||
/** @var Parser $mockParser */
|
||||
|
||||
$cite = new Cite();
|
||||
/** @var Cite $spy */
|
||||
$spy = TestingAccessWrapper::newFromObject( $cite );
|
||||
$spy->errorReporter = $this->createMock( CiteErrorReporter::class );
|
||||
$spy->referenceStack = $this->createMock( ReferenceStack::class );
|
||||
|
||||
$spy->guardedRef( 'text', [ Cite::BOOK_REF_ATTRIBUTE => 'a' ], $mockParser );
|
||||
|
|
Loading…
Reference in a new issue