2019-12-05 08:37:17 +00:00
|
|
|
<?php
|
|
|
|
|
2022-07-13 08:09:31 +00:00
|
|
|
namespace Cite\Tests\Integration;
|
2019-12-05 08:37:17 +00:00
|
|
|
|
2019-12-10 15:24:49 +00:00
|
|
|
use Cite\AnchorFormatter;
|
|
|
|
use Cite\FootnoteMarkFormatter;
|
2024-10-23 16:39:59 +00:00
|
|
|
use Cite\MarkSymbolRenderer;
|
2019-12-10 15:24:49 +00:00
|
|
|
use Cite\ReferenceMessageLocalizer;
|
2023-12-22 22:46:54 +00:00
|
|
|
use Cite\Tests\TestUtils;
|
2024-06-08 21:31:42 +00:00
|
|
|
use MediaWiki\Message\Message;
|
|
|
|
use MediaWiki\Parser\Parser;
|
2019-12-05 08:37:17 +00:00
|
|
|
|
|
|
|
/**
|
2023-12-15 11:12:16 +00:00
|
|
|
* @covers \Cite\FootnoteMarkFormatter
|
|
|
|
* @license GPL-2.0-or-later
|
2019-12-05 08:37:17 +00:00
|
|
|
*/
|
2022-07-13 08:09:31 +00:00
|
|
|
class FootnoteMarkFormatterTest extends \MediaWikiIntegrationTestCase {
|
2019-12-10 15:24:49 +00:00
|
|
|
|
2019-12-05 08:37:17 +00:00
|
|
|
/**
|
|
|
|
* @dataProvider provideLinkRef
|
|
|
|
*/
|
2024-06-21 19:18:25 +00:00
|
|
|
public function testLinkRef( array $ref, string $expectedOutput ) {
|
2019-12-09 16:08:57 +00:00
|
|
|
$anchorFormatter = $this->createMock( AnchorFormatter::class );
|
2023-12-04 07:28:22 +00:00
|
|
|
$anchorFormatter->method( 'jumpLink' )->willReturnArgument( 0 );
|
|
|
|
$anchorFormatter->method( 'backLinkTarget' )->willReturnCallback(
|
2023-12-14 07:58:49 +00:00
|
|
|
static fn ( ...$args ) => implode( '+', $args )
|
2019-12-05 08:37:17 +00:00
|
|
|
);
|
2023-12-15 11:43:49 +00:00
|
|
|
$messageLocalizer = $this->createMock( ReferenceMessageLocalizer::class );
|
|
|
|
$messageLocalizer->method( 'localizeSeparators' )->willReturnArgument( 0 );
|
|
|
|
$messageLocalizer->method( 'localizeDigits' )->willReturnArgument( 0 );
|
|
|
|
$messageLocalizer->method( 'msg' )->willReturnCallback(
|
|
|
|
function ( $key, ...$params ) {
|
|
|
|
$customizedGroup = $key === 'cite_link_label_group-foo';
|
2019-12-09 16:08:57 +00:00
|
|
|
$msg = $this->createMock( Message::class );
|
2023-12-15 11:43:49 +00:00
|
|
|
$msg->method( 'isDisabled' )->willReturn( !$customizedGroup );
|
|
|
|
$msg->method( 'plain' )->willReturn( $customizedGroup
|
|
|
|
? 'a b c'
|
|
|
|
: "($key|" . implode( '|', $params ) . ')'
|
|
|
|
);
|
2019-12-09 16:08:57 +00:00
|
|
|
return $msg;
|
2019-12-05 08:37:17 +00:00
|
|
|
}
|
|
|
|
);
|
2024-10-23 16:39:59 +00:00
|
|
|
$markSymbolRenderer = new MarkSymbolRenderer( $messageLocalizer );
|
2023-07-27 09:39:46 +00:00
|
|
|
$mockParser = $this->createNoOpMock( Parser::class, [ 'recursiveTagParse' ] );
|
2019-12-05 08:37:17 +00:00
|
|
|
$mockParser->method( 'recursiveTagParse' )->willReturnArgument( 0 );
|
2019-12-09 14:07:37 +00:00
|
|
|
$formatter = new FootnoteMarkFormatter(
|
2019-12-09 16:08:57 +00:00
|
|
|
$anchorFormatter,
|
2024-10-23 16:39:59 +00:00
|
|
|
$markSymbolRenderer,
|
2023-12-15 11:43:49 +00:00
|
|
|
$messageLocalizer
|
2019-12-09 14:07:37 +00:00
|
|
|
);
|
2019-12-05 08:37:17 +00:00
|
|
|
|
2023-12-22 22:46:54 +00:00
|
|
|
$ref = TestUtils::refFromArray( $ref );
|
2024-06-21 19:18:25 +00:00
|
|
|
$output = $formatter->linkRef( $mockParser, $ref );
|
2019-12-05 08:37:17 +00:00
|
|
|
$this->assertSame( $expectedOutput, $output );
|
|
|
|
}
|
|
|
|
|
2023-05-20 10:03:41 +00:00
|
|
|
public static function provideLinkRef() {
|
2019-12-05 08:37:17 +00:00
|
|
|
return [
|
|
|
|
'Default label' => [
|
|
|
|
[
|
|
|
|
'name' => null,
|
2024-06-21 19:18:25 +00:00
|
|
|
'group' => '',
|
2023-07-25 13:34:09 +00:00
|
|
|
'number' => 50003,
|
|
|
|
'key' => 50004,
|
2019-12-05 08:37:17 +00:00
|
|
|
],
|
2023-07-25 13:34:09 +00:00
|
|
|
'(cite_reference_link|50004+|50004|50003)'
|
2019-12-05 08:37:17 +00:00
|
|
|
],
|
|
|
|
'Default label, named group' => [
|
|
|
|
[
|
|
|
|
'name' => null,
|
2024-06-21 19:18:25 +00:00
|
|
|
'group' => 'bar',
|
2019-12-05 08:37:17 +00:00
|
|
|
'number' => 3,
|
|
|
|
'key' => 4,
|
|
|
|
],
|
|
|
|
'(cite_reference_link|4+|4|bar 3)'
|
|
|
|
],
|
|
|
|
'Custom label' => [
|
|
|
|
[
|
|
|
|
'name' => null,
|
2024-06-21 19:18:25 +00:00
|
|
|
'group' => 'foo',
|
2019-12-05 08:37:17 +00:00
|
|
|
'number' => 3,
|
|
|
|
'key' => 4,
|
|
|
|
],
|
|
|
|
'(cite_reference_link|4+|4|c)'
|
|
|
|
],
|
|
|
|
'Custom label overrun' => [
|
|
|
|
[
|
|
|
|
'name' => null,
|
2024-06-21 19:18:25 +00:00
|
|
|
'group' => 'foo',
|
2019-12-05 08:37:17 +00:00
|
|
|
'number' => 10,
|
|
|
|
'key' => 4,
|
|
|
|
],
|
2024-10-23 09:29:14 +00:00
|
|
|
'(cite_reference_link|4+|4|foo 10)'
|
2019-12-05 08:37:17 +00:00
|
|
|
],
|
|
|
|
'Named ref' => [
|
|
|
|
[
|
|
|
|
'name' => 'a',
|
2024-06-21 19:18:25 +00:00
|
|
|
'group' => '',
|
2019-12-05 08:37:17 +00:00
|
|
|
'number' => 3,
|
|
|
|
'key' => 4,
|
2024-01-06 01:18:51 +00:00
|
|
|
'count' => 1,
|
2019-12-05 08:37:17 +00:00
|
|
|
],
|
|
|
|
'(cite_reference_link|a+4-0|a-4|3)'
|
|
|
|
],
|
|
|
|
'Named ref reused' => [
|
|
|
|
[
|
|
|
|
'name' => 'a',
|
2024-06-21 19:18:25 +00:00
|
|
|
'group' => '',
|
2019-12-05 08:37:17 +00:00
|
|
|
'number' => 3,
|
|
|
|
'key' => 4,
|
2023-07-25 13:34:09 +00:00
|
|
|
'count' => 50002,
|
2019-12-05 08:37:17 +00:00
|
|
|
],
|
2024-01-06 01:18:51 +00:00
|
|
|
'(cite_reference_link|a+4-50001|a-4|3)'
|
2019-12-05 08:37:17 +00:00
|
|
|
],
|
|
|
|
'Subreference' => [
|
|
|
|
[
|
|
|
|
'name' => null,
|
2024-06-21 19:18:25 +00:00
|
|
|
'group' => '',
|
2019-12-05 08:37:17 +00:00
|
|
|
'number' => 3,
|
|
|
|
'key' => 4,
|
|
|
|
'extends' => 'b',
|
2023-07-25 13:34:09 +00:00
|
|
|
'extendsIndex' => 50002,
|
2019-12-05 08:37:17 +00:00
|
|
|
],
|
2023-07-25 13:34:09 +00:00
|
|
|
'(cite_reference_link|4+|4|3.50002)'
|
2019-12-05 08:37:17 +00:00
|
|
|
],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|