2019-12-03 23:53:55 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Cite\Tests\Unit;
|
|
|
|
|
|
|
|
use Cite\CiteErrorReporter;
|
|
|
|
use Cite\CiteKeyFormatter;
|
|
|
|
use Cite\ReferenceMessageLocalizer;
|
2019-12-09 15:36:34 +00:00
|
|
|
use Cite\ReferencesFormatter;
|
2019-12-03 23:53:55 +00:00
|
|
|
use MediaWikiUnitTestCase;
|
|
|
|
use Message;
|
|
|
|
use Parser;
|
|
|
|
use Wikimedia\TestingAccessWrapper;
|
|
|
|
|
|
|
|
/**
|
2019-12-09 15:36:34 +00:00
|
|
|
* @coversDefaultClass \Cite\ReferencesFormatter
|
2019-12-03 23:53:55 +00:00
|
|
|
*
|
|
|
|
* @license GPL-2.0-or-later
|
|
|
|
*/
|
2019-12-09 15:36:34 +00:00
|
|
|
class ReferencesFormatterTest extends MediaWikiUnitTestCase {
|
2019-12-04 06:54:04 +00:00
|
|
|
/**
|
|
|
|
* @covers ::__construct
|
2019-12-09 15:36:34 +00:00
|
|
|
* @covers ::formatReferences
|
|
|
|
* @dataProvider provideFormatReferences
|
2019-12-04 06:54:04 +00:00
|
|
|
*/
|
2019-12-09 15:36:34 +00:00
|
|
|
public function testFormatReferences( array $refs, string $expectedOutput ) {
|
2019-12-04 06:54:04 +00:00
|
|
|
$mockParser = $this->createMock( Parser::class );
|
|
|
|
$mockParser->method( 'recursiveTagParse' )->willReturnArgument( 0 );
|
|
|
|
/** @var Parser $mockParser */
|
2019-12-04 10:59:56 +00:00
|
|
|
$mockErrorReporter = $this->createMock( CiteErrorReporter::class );
|
|
|
|
$mockErrorReporter->method( 'plain' )->willReturnCallback(
|
|
|
|
function ( ...$args ) {
|
|
|
|
return json_encode( $args );
|
|
|
|
}
|
|
|
|
);
|
2019-12-04 06:54:04 +00:00
|
|
|
$mockMessageLocalizer = $this->createMock( ReferenceMessageLocalizer::class );
|
|
|
|
$mockMessageLocalizer->method( 'msg' )->willReturnCallback(
|
|
|
|
function ( ...$args ) {
|
|
|
|
$mockMessage = $this->createMock( Message::class );
|
|
|
|
$mockMessage->method( 'plain' )->willReturn(
|
|
|
|
'<li>(' . implode( '|', $args ) . ')</li>' );
|
|
|
|
return $mockMessage;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2019-12-09 15:01:13 +00:00
|
|
|
/** @var CiteErrorReporter $mockErrorReporter */
|
|
|
|
/** @var ReferenceMessageLocalizer $mockMessageLocalizer */
|
2019-12-09 15:36:34 +00:00
|
|
|
/** @var ReferencesFormatter $formatter */
|
|
|
|
$formatter = TestingAccessWrapper::newFromObject( new ReferencesFormatter(
|
2019-12-04 06:54:04 +00:00
|
|
|
$mockParser,
|
2019-12-04 10:59:56 +00:00
|
|
|
$mockErrorReporter,
|
2019-12-04 06:54:04 +00:00
|
|
|
$this->createMock( CiteKeyFormatter::class ),
|
2019-12-09 15:01:13 +00:00
|
|
|
$mockMessageLocalizer
|
|
|
|
) );
|
2019-12-04 06:54:04 +00:00
|
|
|
|
2019-12-09 15:36:34 +00:00
|
|
|
$output = $formatter->formatReferences( $refs, true, false );
|
2019-12-04 06:54:04 +00:00
|
|
|
$this->assertSame( $expectedOutput, $output );
|
|
|
|
}
|
|
|
|
|
2019-12-09 15:36:34 +00:00
|
|
|
public function provideFormatReferences() {
|
2019-12-04 06:54:04 +00:00
|
|
|
return [
|
|
|
|
'Empty' => [
|
|
|
|
[],
|
|
|
|
''
|
|
|
|
],
|
|
|
|
'Minimal ref' => [
|
|
|
|
[
|
|
|
|
0 => [
|
|
|
|
'key' => 1,
|
|
|
|
'text' => 't',
|
|
|
|
]
|
|
|
|
],
|
|
|
|
'<div class="mw-references-wrap"><ol class="references">' . "\n" .
|
|
|
|
'<li>(cite_references_link_many|||<span class="reference-text">t</span>' .
|
|
|
|
"\n|)</li>\n</ol></div>"
|
|
|
|
],
|
|
|
|
'Ref with extends' => [
|
|
|
|
[
|
|
|
|
0 => [
|
|
|
|
'extends' => 'a',
|
|
|
|
'extendsIndex' => 1,
|
|
|
|
'key' => 2,
|
|
|
|
'number' => 10,
|
|
|
|
'text' => 't2',
|
|
|
|
],
|
|
|
|
1 => [
|
|
|
|
'number' => 11,
|
|
|
|
'text' => 't3',
|
|
|
|
],
|
|
|
|
'a' => [
|
|
|
|
'key' => 1,
|
|
|
|
'number' => 9,
|
|
|
|
'text' => 't1',
|
|
|
|
],
|
|
|
|
],
|
|
|
|
'<div class="mw-references-wrap"><ol class="references">' . "\n" .
|
|
|
|
'<li>(cite_references_link_many|||<span class="reference-text">t1</span>' . "\n" .
|
|
|
|
'|)<ol class="mw-extended-references"><li>(cite_references_link_many|||' .
|
|
|
|
'<span class="reference-text">t2</span>' . "\n|)</li>\n" .
|
|
|
|
"</ol></li>\n" .
|
|
|
|
'<li>(cite_references_link_many|||<span class="reference-text">t3</span>' .
|
|
|
|
"\n|)</li>\n" .
|
|
|
|
'</ol></div>'
|
|
|
|
],
|
2019-12-04 10:59:56 +00:00
|
|
|
'Subref of subref' => [
|
|
|
|
[
|
|
|
|
0 => [
|
|
|
|
'extends' => 'a',
|
|
|
|
'extendsIndex' => 1,
|
|
|
|
'key' => 1,
|
|
|
|
'number' => 1,
|
|
|
|
'text' => 't1',
|
|
|
|
],
|
|
|
|
'a' => [
|
|
|
|
'extends' => 'b',
|
|
|
|
'extendsIndex' => 1,
|
|
|
|
'key' => 2,
|
|
|
|
'number' => 1,
|
|
|
|
'text' => 't2',
|
|
|
|
],
|
|
|
|
'b' => [
|
|
|
|
'key' => 3,
|
|
|
|
'number' => 1,
|
|
|
|
'text' => 't3',
|
|
|
|
],
|
|
|
|
],
|
|
|
|
'<div class="mw-references-wrap"><ol class="references">' . "\n" .
|
|
|
|
'<li>(cite_references_link_many|||<span class="reference-text">t3</span>' . "\n" .
|
2019-12-09 08:37:38 +00:00
|
|
|
'|)<ol class="mw-extended-references"><li>(cite_references_link_many|||' .
|
|
|
|
'<span class="reference-text">t1 ["cite_error_ref_too_many_keys"]</span>' .
|
|
|
|
"\n|)</li>\n" .
|
2019-12-04 10:59:56 +00:00
|
|
|
'<li>(cite_references_link_many|||<span class="reference-text">t2</span>' .
|
|
|
|
"\n|)</li>\n</ol></li>\n" .
|
|
|
|
'</ol></div>'
|
|
|
|
],
|
2019-12-04 06:54:04 +00:00
|
|
|
'Use columns' => [
|
2019-12-04 16:55:52 +00:00
|
|
|
array_map(
|
|
|
|
function ( $i ) {
|
|
|
|
return [ 'key' => $i, 'text' => 't' ];
|
|
|
|
},
|
|
|
|
range( 0, 10 )
|
|
|
|
),
|
2019-12-04 06:54:04 +00:00
|
|
|
'<div class="mw-references-wrap mw-references-columns"><ol class="references">' .
|
|
|
|
"\n" . '<li>(cite_references_link_many|||<span class="reference-text">t</span>' .
|
|
|
|
"\n|)</li>\n" .
|
|
|
|
'<li>(cite_references_link_many|||<span class="reference-text">t</span>' .
|
|
|
|
"\n|)</li>\n" .
|
|
|
|
'<li>(cite_references_link_many|||<span class="reference-text">t</span>' .
|
|
|
|
"\n|)</li>\n" .
|
|
|
|
'<li>(cite_references_link_many|||<span class="reference-text">t</span>' .
|
|
|
|
"\n|)</li>\n" .
|
|
|
|
'<li>(cite_references_link_many|||<span class="reference-text">t</span>' .
|
|
|
|
"\n|)</li>\n" .
|
|
|
|
'<li>(cite_references_link_many|||<span class="reference-text">t</span>' .
|
|
|
|
"\n|)</li>\n" .
|
|
|
|
'<li>(cite_references_link_many|||<span class="reference-text">t</span>' .
|
|
|
|
"\n|)</li>\n" .
|
|
|
|
'<li>(cite_references_link_many|||<span class="reference-text">t</span>' .
|
|
|
|
"\n|)</li>\n" .
|
|
|
|
'<li>(cite_references_link_many|||<span class="reference-text">t</span>' .
|
|
|
|
"\n|)</li>\n" .
|
|
|
|
'<li>(cite_references_link_many|||<span class="reference-text">t</span>' .
|
|
|
|
"\n|)</li>\n" .
|
|
|
|
'<li>(cite_references_link_many|||<span class="reference-text">t</span>' .
|
|
|
|
"\n|)</li>\n</ol></div>"
|
|
|
|
],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers ::closeIndention
|
|
|
|
* @dataProvider provideCloseIndention
|
|
|
|
*/
|
|
|
|
public function testCloseIndention( $closingLi, $expectedOutput ) {
|
2019-12-09 15:36:34 +00:00
|
|
|
$formatter = TestingAccessWrapper::newFromObject( new ReferencesFormatter(
|
2019-12-04 06:54:04 +00:00
|
|
|
$this->createMock( Parser::class ),
|
|
|
|
$this->createMock( CiteErrorReporter::class ),
|
|
|
|
$this->createMock( CiteKeyFormatter::class ),
|
2019-12-09 15:01:13 +00:00
|
|
|
$this->createMock( ReferenceMessageLocalizer::class )
|
|
|
|
) );
|
2019-12-04 06:54:04 +00:00
|
|
|
|
|
|
|
$output = $formatter->closeIndention( $closingLi );
|
|
|
|
$this->assertSame( $expectedOutput, $output );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function provideCloseIndention() {
|
|
|
|
return [
|
|
|
|
'No indention' => [ false, '' ],
|
|
|
|
'Indention string' => [ "</li>\n", "</ol></li>\n" ],
|
|
|
|
'Indention without string' => [ true, '</ol>' ],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-12-09 15:36:34 +00:00
|
|
|
* @covers ::formatListItem
|
|
|
|
* @dataProvider provideFormatListItem
|
2019-12-04 06:54:04 +00:00
|
|
|
*/
|
2019-12-09 15:36:34 +00:00
|
|
|
public function testFormatListItem(
|
2019-12-04 06:54:04 +00:00
|
|
|
$key,
|
|
|
|
array $val,
|
|
|
|
string $expectedOutput
|
|
|
|
) {
|
|
|
|
$mockErrorReporter = $this->createMock( CiteErrorReporter::class );
|
|
|
|
$mockErrorReporter->method( 'plain' )->willReturnCallback(
|
|
|
|
function ( ...$args ) {
|
|
|
|
return '(' . implode( '|', $args ) . ')';
|
|
|
|
}
|
|
|
|
);
|
|
|
|
$mockCiteKeyFormatter = $this->createMock( CiteKeyFormatter::class );
|
|
|
|
$mockCiteKeyFormatter->method( 'refKey' )->willReturnCallback(
|
|
|
|
function ( $key, $num = null ) {
|
|
|
|
return $key . '+' . ( $num ?? 'null' );
|
|
|
|
}
|
|
|
|
);
|
|
|
|
$mockMessageLocalizer = $this->createMock( ReferenceMessageLocalizer::class );
|
2019-12-06 09:12:25 +00:00
|
|
|
$mockMessageLocalizer->method( 'formatNum' )->willReturnArgument( 0 );
|
2019-12-10 15:21:12 +00:00
|
|
|
$mockMessageLocalizer->method( 'localizeDigits' )->willReturnArgument( 0 );
|
2019-12-04 06:54:04 +00:00
|
|
|
$mockMessageLocalizer->method( 'msg' )->willReturnCallback(
|
|
|
|
function ( ...$args ) {
|
|
|
|
$mockMessage = $this->createMock( Message::class );
|
|
|
|
$mockMessage->method( 'plain' )->willReturn(
|
|
|
|
'(' . implode( '|', $args ) . ')' );
|
|
|
|
return $mockMessage;
|
|
|
|
}
|
|
|
|
);
|
2019-12-09 15:01:13 +00:00
|
|
|
|
|
|
|
/** @var CiteErrorReporter $mockErrorReporter */
|
|
|
|
/** @var ReferenceMessageLocalizer $mockMessageLocalizer */
|
2019-12-09 15:36:34 +00:00
|
|
|
/** @var ReferencesFormatter $formatter */
|
|
|
|
$formatter = TestingAccessWrapper::newFromObject( new ReferencesFormatter(
|
2019-12-04 06:54:04 +00:00
|
|
|
$this->createMock( Parser::class ),
|
|
|
|
$mockErrorReporter,
|
|
|
|
$mockCiteKeyFormatter,
|
2019-12-09 15:01:13 +00:00
|
|
|
$mockMessageLocalizer
|
|
|
|
) );
|
2019-12-04 06:54:04 +00:00
|
|
|
|
2019-12-09 15:36:34 +00:00
|
|
|
$output = $formatter->formatListItem( $key, $val, false );
|
2019-12-04 06:54:04 +00:00
|
|
|
$this->assertSame( $expectedOutput, $output );
|
|
|
|
}
|
|
|
|
|
2019-12-09 15:36:34 +00:00
|
|
|
public function provideFormatListItem() {
|
2019-12-04 06:54:04 +00:00
|
|
|
return [
|
|
|
|
'Success' => [
|
|
|
|
1,
|
|
|
|
[
|
|
|
|
'text' => 't',
|
|
|
|
],
|
|
|
|
'(cite_references_link_many|||<span class="reference-text">t</span>' . "\n" . '|)'
|
|
|
|
],
|
|
|
|
'Good dir' => [
|
|
|
|
1,
|
|
|
|
[
|
|
|
|
'dir' => 'rtl',
|
|
|
|
'text' => 't',
|
|
|
|
],
|
|
|
|
'(cite_references_link_many|||<span class="reference-text">t</span>' .
|
|
|
|
"\n" . '| class="mw-cite-dir-rtl")'
|
|
|
|
],
|
|
|
|
'Invalid dir' => [
|
|
|
|
1,
|
|
|
|
[
|
|
|
|
'dir' => 'not',
|
|
|
|
'text' => 't',
|
|
|
|
],
|
|
|
|
'(cite_references_link_many|||<span class="reference-text">t</span>' .
|
|
|
|
"\n" . '(cite_error_ref_invalid_dir|not)' . "\n|)"
|
|
|
|
],
|
|
|
|
'Broken follow' => [
|
|
|
|
1,
|
|
|
|
[
|
|
|
|
'follow' => 'f',
|
|
|
|
'text' => 't',
|
|
|
|
],
|
|
|
|
'(cite_references_no_link||<span class="reference-text">t</span>' . "\n)"
|
|
|
|
],
|
|
|
|
'Count zero' => [
|
|
|
|
1,
|
|
|
|
[
|
|
|
|
'count' => 0,
|
|
|
|
'key' => 5,
|
|
|
|
'text' => 't',
|
|
|
|
],
|
|
|
|
'(cite_references_link_one||1+5-0|<span class="reference-text">t</span>' . "\n|)"
|
|
|
|
],
|
|
|
|
'Count negative' => [
|
|
|
|
1,
|
|
|
|
[
|
|
|
|
'count' => -1,
|
|
|
|
'key' => 5,
|
|
|
|
'number' => 3,
|
|
|
|
'text' => 't',
|
|
|
|
],
|
|
|
|
'(cite_references_link_one||5+null|<span class="reference-text">t</span>' . "\n|)"
|
|
|
|
],
|
|
|
|
'Count positive' => [
|
|
|
|
1,
|
|
|
|
[
|
|
|
|
'count' => 2,
|
|
|
|
'key' => 5,
|
|
|
|
'number' => 3,
|
|
|
|
'text' => 't',
|
|
|
|
],
|
|
|
|
'(cite_references_link_many||(cite_references_link_many_format|1+5-0|3.0|' .
|
|
|
|
'(cite_references_link_many_format_backlink_labels))' .
|
|
|
|
'(cite_references_link_many_sep)(cite_references_link_many_format|1+5-1|3.1|' .
|
|
|
|
'(cite_error_references_no_backlink_label))(cite_references_link_many_and)' .
|
|
|
|
'(cite_references_link_many_format|1+5-2|3.2|(cite_error_references_no_backlink_label' .
|
|
|
|
'))|<span class="reference-text">t</span>' . "\n|)"
|
|
|
|
],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers ::referenceText
|
|
|
|
* @dataProvider provideReferenceText
|
|
|
|
*/
|
|
|
|
public function testReferenceText(
|
|
|
|
$key,
|
|
|
|
?string $text,
|
|
|
|
bool $isSectionPreview,
|
|
|
|
string $expectedOutput
|
|
|
|
) {
|
|
|
|
$mockErrorReporter = $this->createMock( CiteErrorReporter::class );
|
|
|
|
$mockErrorReporter->method( 'plain' )->willReturnCallback(
|
|
|
|
function ( ...$args ) {
|
|
|
|
return json_encode( $args );
|
|
|
|
}
|
|
|
|
);
|
2019-12-09 15:01:13 +00:00
|
|
|
|
2019-12-09 15:36:34 +00:00
|
|
|
/** @var ReferencesFormatter $formatter */
|
|
|
|
$formatter = TestingAccessWrapper::newFromObject( new ReferencesFormatter(
|
2019-12-04 06:54:04 +00:00
|
|
|
$this->createMock( Parser::class ),
|
|
|
|
$mockErrorReporter,
|
|
|
|
$this->createMock( CiteKeyFormatter::class ),
|
2019-12-09 15:01:13 +00:00
|
|
|
$this->createMock( ReferenceMessageLocalizer::class )
|
|
|
|
) );
|
2019-12-04 06:54:04 +00:00
|
|
|
|
|
|
|
$output = $formatter->referenceText( $key, $text, $isSectionPreview );
|
|
|
|
$this->assertSame( $expectedOutput, $output );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function provideReferenceText() {
|
|
|
|
return [
|
|
|
|
'No text, not preview' => [
|
|
|
|
1,
|
|
|
|
null,
|
|
|
|
false,
|
|
|
|
'["cite_error_references_no_text",1]'
|
|
|
|
],
|
|
|
|
'No text, is preview' => [
|
|
|
|
1,
|
|
|
|
null,
|
|
|
|
true,
|
|
|
|
'["cite_warning_sectionpreview_no_text",1]'
|
|
|
|
],
|
|
|
|
'Has text' => [
|
|
|
|
1,
|
|
|
|
'text',
|
|
|
|
true,
|
|
|
|
'<span class="reference-text">text</span>' . "\n"
|
|
|
|
],
|
|
|
|
'Trims text' => [
|
|
|
|
1,
|
|
|
|
"text\n\n",
|
|
|
|
true,
|
|
|
|
'<span class="reference-text">text</span>' . "\n"
|
|
|
|
],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2019-12-03 23:53:55 +00:00
|
|
|
/**
|
|
|
|
* @covers ::referencesFormatEntryAlternateBacklinkLabel
|
|
|
|
* @dataProvider provideReferencesFormatEntryAlternateBacklinkLabel
|
|
|
|
*/
|
|
|
|
public function testReferencesFormatEntryAlternateBacklinkLabel(
|
|
|
|
?string $expectedLabel, ?string $labelList, int $offset
|
|
|
|
) {
|
|
|
|
$mockMessage = $this->createMock( Message::class );
|
|
|
|
$mockMessage->method( 'exists' )->willReturn( (bool)$labelList );
|
|
|
|
$mockMessage->method( 'plain' )->willReturn( $labelList ?? '<missing-junk>' );
|
|
|
|
/** @var ReferenceMessageLocalizer $mockMessageLocalizer */
|
|
|
|
$mockMessageLocalizer = $this->createMock( ReferenceMessageLocalizer::class );
|
|
|
|
$mockMessageLocalizer->method( 'msg' )
|
|
|
|
->willReturn( $mockMessage );
|
|
|
|
/** @var CiteErrorReporter $mockErrorReporter */
|
|
|
|
$mockErrorReporter = $this->createMock( CiteErrorReporter::class );
|
|
|
|
if ( $expectedLabel === null ) {
|
|
|
|
$mockErrorReporter->expects( $this->once() )->method( 'plain' );
|
|
|
|
} else {
|
|
|
|
$mockErrorReporter->expects( $this->never() )->method( 'plain' );
|
|
|
|
}
|
2019-12-09 15:01:13 +00:00
|
|
|
|
2019-12-09 15:36:34 +00:00
|
|
|
/** @var ReferencesFormatter $formatter */
|
|
|
|
$formatter = TestingAccessWrapper::newFromObject( new ReferencesFormatter(
|
2019-12-03 23:53:55 +00:00
|
|
|
$this->createMock( Parser::class ),
|
|
|
|
$mockErrorReporter,
|
|
|
|
$this->createMock( CiteKeyFormatter::class ),
|
2019-12-09 15:01:13 +00:00
|
|
|
$mockMessageLocalizer
|
|
|
|
) );
|
2019-12-03 23:53:55 +00:00
|
|
|
|
|
|
|
$label = $formatter->referencesFormatEntryAlternateBacklinkLabel( $offset );
|
|
|
|
if ( $expectedLabel !== null ) {
|
|
|
|
$this->assertSame( $expectedLabel, $label );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function provideReferencesFormatEntryAlternateBacklinkLabel() {
|
|
|
|
yield [ 'aa', 'aa ab ac', 0 ];
|
|
|
|
yield [ 'ab', 'aa ab ac', 1 ];
|
|
|
|
yield [ 'å', 'å b c', 0 ];
|
|
|
|
yield [ null, 'a b c', 10 ];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers ::referencesFormatEntryNumericBacklinkLabel
|
|
|
|
* @dataProvider provideReferencesFormatEntryNumericBacklinkLabel
|
|
|
|
*/
|
|
|
|
public function testReferencesFormatEntryNumericBacklinkLabel(
|
|
|
|
string $expectedLabel, int $base, int $offset, int $max
|
|
|
|
) {
|
|
|
|
$mockMessageLocalizer = $this->createMock( ReferenceMessageLocalizer::class );
|
2019-12-06 09:12:25 +00:00
|
|
|
$mockMessageLocalizer->method( 'formatNum' )->willReturnArgument( 0 );
|
2019-12-10 15:21:12 +00:00
|
|
|
$mockMessageLocalizer->method( 'localizeDigits' )->willReturnArgument( 0 );
|
2019-12-09 15:01:13 +00:00
|
|
|
|
|
|
|
/** @var ReferenceMessageLocalizer $mockMessageLocalizer */
|
2019-12-09 15:36:34 +00:00
|
|
|
/** @var ReferencesFormatter $formatter */
|
|
|
|
$formatter = TestingAccessWrapper::newFromObject( new ReferencesFormatter(
|
2019-12-03 23:53:55 +00:00
|
|
|
$this->createMock( Parser::class ),
|
|
|
|
$this->createMock( CiteErrorReporter::class ),
|
|
|
|
$this->createMock( CiteKeyFormatter::class ),
|
2019-12-09 15:01:13 +00:00
|
|
|
$mockMessageLocalizer
|
|
|
|
) );
|
2019-12-03 23:53:55 +00:00
|
|
|
|
|
|
|
$label = $formatter->referencesFormatEntryNumericBacklinkLabel( $base, $offset, $max );
|
|
|
|
$this->assertSame( $expectedLabel, $label );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function provideReferencesFormatEntryNumericBacklinkLabel() {
|
|
|
|
yield [ '1.2', 1, 2, 9 ];
|
|
|
|
yield [ '1.02', 1, 2, 99 ];
|
|
|
|
yield [ '1.002', 1, 2, 100 ];
|
|
|
|
yield [ '2.1', 2, 1, 1 ];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers ::listToText
|
|
|
|
* @dataProvider provideLists
|
|
|
|
*/
|
|
|
|
public function testListToText( array $list, $expected ) {
|
|
|
|
$mockMessageLocalizer = $this->createMock( ReferenceMessageLocalizer::class );
|
|
|
|
$mockMessageLocalizer->method( 'msg' )->willReturnCallback(
|
|
|
|
function ( $msg ) {
|
|
|
|
$mockMessage = $this->createMock( Message::class );
|
|
|
|
$mockMessage->method( 'plain' )->willReturn( "({$msg})" );
|
|
|
|
return $mockMessage;
|
|
|
|
}
|
|
|
|
);
|
2019-12-09 15:01:13 +00:00
|
|
|
|
2019-12-09 15:36:34 +00:00
|
|
|
/** @var ReferencesFormatter $formatter */
|
|
|
|
$formatter = TestingAccessWrapper::newFromObject( new ReferencesFormatter(
|
2019-12-03 23:53:55 +00:00
|
|
|
$this->createMock( Parser::class ),
|
|
|
|
$this->createMock( CiteErrorReporter::class ),
|
|
|
|
$this->createMock( CiteKeyFormatter::class ),
|
2019-12-09 15:01:13 +00:00
|
|
|
$mockMessageLocalizer
|
|
|
|
) );
|
2019-12-03 23:53:55 +00:00
|
|
|
$this->assertSame( $expected, $formatter->listToText( $list ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function provideLists() {
|
|
|
|
return [
|
|
|
|
[
|
|
|
|
[],
|
|
|
|
''
|
|
|
|
],
|
|
|
|
[
|
|
|
|
// This is intentionally using numbers to test the to-string cast
|
|
|
|
[ 1 ],
|
|
|
|
'1'
|
|
|
|
],
|
|
|
|
[
|
|
|
|
[ 1, 2 ],
|
|
|
|
'1(cite_references_link_many_and)2'
|
|
|
|
],
|
|
|
|
[
|
|
|
|
[ 1, 2, 3 ],
|
|
|
|
'1(cite_references_link_many_sep)2(cite_references_link_many_and)3'
|
|
|
|
],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|