2019-11-08 14:46:52 +00:00
|
|
|
<?php
|
|
|
|
|
2022-07-13 08:09:31 +00:00
|
|
|
namespace Cite\Tests\Integration;
|
2019-11-08 14:46:52 +00:00
|
|
|
|
2019-11-19 14:12:11 +00:00
|
|
|
use Cite\Cite;
|
2019-12-09 16:08:57 +00:00
|
|
|
use Cite\ErrorReporter;
|
2019-12-04 16:53:05 +00:00
|
|
|
use Cite\FootnoteMarkFormatter;
|
2019-12-11 11:19:18 +00:00
|
|
|
use Cite\ReferencesFormatter;
|
2019-11-27 11:09:31 +00:00
|
|
|
use Cite\ReferenceStack;
|
2019-12-11 13:58:25 +00:00
|
|
|
use Language;
|
2019-12-20 18:31:54 +00:00
|
|
|
use LogicException;
|
2019-12-03 12:39:02 +00:00
|
|
|
use Parser;
|
2019-12-11 13:58:25 +00:00
|
|
|
use ParserOptions;
|
2019-12-03 12:39:02 +00:00
|
|
|
use ParserOutput;
|
|
|
|
use StripState;
|
2019-11-08 14:46:52 +00:00
|
|
|
use Wikimedia\TestingAccessWrapper;
|
|
|
|
|
|
|
|
/**
|
2019-11-19 14:12:11 +00:00
|
|
|
* @coversDefaultClass \Cite\Cite
|
2019-11-19 10:31:08 +00:00
|
|
|
*
|
|
|
|
* @license GPL-2.0-or-later
|
2019-11-08 14:46:52 +00:00
|
|
|
*/
|
2022-07-13 08:09:31 +00:00
|
|
|
class CiteTest extends \MediaWikiIntegrationTestCase {
|
2019-12-04 16:53:05 +00:00
|
|
|
|
2019-11-08 14:46:52 +00:00
|
|
|
/**
|
2019-11-27 12:50:05 +00:00
|
|
|
* @covers ::parseArguments
|
2019-12-03 22:23:49 +00:00
|
|
|
* @dataProvider provideParseArguments
|
2019-11-08 14:46:52 +00:00
|
|
|
*/
|
2019-12-03 22:23:49 +00:00
|
|
|
public function testParseArguments(
|
2019-11-26 11:05:51 +00:00
|
|
|
array $attributes,
|
|
|
|
array $expectedValue,
|
|
|
|
string $expectedError = null
|
|
|
|
) {
|
2019-11-08 14:46:52 +00:00
|
|
|
/** @var Cite $cite */
|
2019-12-11 13:58:25 +00:00
|
|
|
$cite = TestingAccessWrapper::newFromObject( $this->newCite() );
|
2019-11-26 11:05:51 +00:00
|
|
|
$status = $cite->parseArguments(
|
2019-11-27 12:50:05 +00:00
|
|
|
$attributes,
|
|
|
|
[ 'dir', 'extends', 'follow', 'group', 'name' ]
|
|
|
|
);
|
2019-11-26 11:05:51 +00:00
|
|
|
$this->assertSame( $expectedValue, array_values( $status->getValue() ) );
|
|
|
|
if ( $expectedError ) {
|
2023-12-12 18:16:50 +00:00
|
|
|
$this->assertStatusError( $expectedError, $status );
|
|
|
|
} else {
|
|
|
|
$this->assertStatusGood( $status );
|
2019-11-26 11:05:51 +00:00
|
|
|
}
|
2019-11-08 14:46:52 +00:00
|
|
|
}
|
|
|
|
|
2023-05-20 10:03:41 +00:00
|
|
|
public static function provideParseArguments() {
|
2019-11-27 11:44:25 +00:00
|
|
|
// Note: Values are guaranteed to be trimmed by the parser, see
|
|
|
|
// Sanitizer::decodeTagAttributes()
|
2019-11-08 14:46:52 +00:00
|
|
|
return [
|
2019-11-22 08:49:27 +00:00
|
|
|
[ [], [ null, null, null, null, null ] ],
|
2019-11-08 14:46:52 +00:00
|
|
|
|
|
|
|
// One attribute only
|
2019-11-26 11:18:55 +00:00
|
|
|
[ [ 'dir' => 'invalid' ], [ 'invalid', null, null, null, null ] ],
|
2019-11-27 11:44:25 +00:00
|
|
|
[ [ 'dir' => 'rtl' ], [ 'rtl', null, null, null, null ] ],
|
|
|
|
[ [ 'follow' => 'f' ], [ null, null, 'f', null, null ] ],
|
|
|
|
[ [ 'group' => 'g' ], [ null, null, null, 'g', null ] ],
|
2019-11-26 11:05:51 +00:00
|
|
|
[
|
|
|
|
[ 'invalid' => 'i' ],
|
|
|
|
[ null, null, null, null, null ],
|
|
|
|
'cite_error_ref_too_many_keys'
|
|
|
|
],
|
|
|
|
[
|
|
|
|
[ 'invalid' => null ],
|
|
|
|
[ null, null, null, null, null ],
|
|
|
|
'cite_error_ref_too_many_keys'
|
|
|
|
],
|
2019-11-27 11:44:25 +00:00
|
|
|
[ [ 'name' => 'n' ], [ null, null, null, null, 'n' ] ],
|
2019-11-27 12:50:05 +00:00
|
|
|
[ [ 'name' => null ], [ null, null, null, null, null ] ],
|
2019-11-27 11:44:25 +00:00
|
|
|
[ [ 'extends' => 'e' ], [ null, 'e', null, null, null ] ],
|
2019-11-08 14:46:52 +00:00
|
|
|
|
|
|
|
// Pairs
|
2019-11-26 11:18:55 +00:00
|
|
|
[ [ 'follow' => 'f', 'name' => 'n' ], [ null, null, 'f', null, 'n' ] ],
|
2019-11-27 12:50:05 +00:00
|
|
|
[ [ 'follow' => null, 'name' => null ], [ null, null, null, null, null ] ],
|
2019-11-26 11:18:55 +00:00
|
|
|
[ [ 'follow' => 'f', 'extends' => 'e' ], [ null, 'e', 'f', null, null ] ],
|
|
|
|
[ [ 'group' => 'g', 'name' => 'n' ], [ null, null, null, 'g', 'n' ] ],
|
2019-11-08 14:46:52 +00:00
|
|
|
|
|
|
|
// Combinations of 3 or more attributes
|
|
|
|
[
|
|
|
|
[ 'group' => 'g', 'name' => 'n', 'extends' => 'e', 'dir' => 'rtl' ],
|
2019-11-26 11:18:55 +00:00
|
|
|
[ 'rtl', 'e', null, 'g', 'n' ]
|
2019-11-08 14:46:52 +00:00
|
|
|
],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2019-12-03 22:39:52 +00:00
|
|
|
/**
|
2023-12-12 11:03:45 +00:00
|
|
|
* @covers ::references
|
2019-12-03 22:39:52 +00:00
|
|
|
* @dataProvider provideGuardedReferences
|
|
|
|
*/
|
|
|
|
public function testGuardedReferences(
|
|
|
|
?string $text,
|
|
|
|
array $argv,
|
|
|
|
int $expectedRollbackCount,
|
|
|
|
string $expectedInReferencesGroup,
|
|
|
|
bool $expectedResponsive,
|
|
|
|
string $expectedOutput
|
|
|
|
) {
|
2023-12-11 11:15:29 +00:00
|
|
|
$this->overrideConfigValue( 'CiteResponsiveReferences', false );
|
2019-12-03 22:39:52 +00:00
|
|
|
|
2023-07-27 09:39:46 +00:00
|
|
|
$parser = $this->createNoOpMock( Parser::class, [ 'recursiveTagParse' ] );
|
2019-12-09 14:07:37 +00:00
|
|
|
|
2019-12-11 13:58:25 +00:00
|
|
|
$cite = $this->newCite();
|
2019-12-03 22:39:52 +00:00
|
|
|
/** @var Cite $spy */
|
|
|
|
$spy = TestingAccessWrapper::newFromObject( $cite );
|
2019-12-09 16:08:57 +00:00
|
|
|
$spy->errorReporter = $this->createMock( ErrorReporter::class );
|
2019-12-03 22:39:52 +00:00
|
|
|
$spy->errorReporter->method( 'halfParsed' )->willReturnCallback(
|
2023-12-14 07:58:49 +00:00
|
|
|
static fn ( $parser, ...$args ) => '(' . implode( '|', $args ) . ')'
|
2019-12-03 22:39:52 +00:00
|
|
|
);
|
2019-12-09 15:36:34 +00:00
|
|
|
$spy->referencesFormatter = $this->createMock( ReferencesFormatter::class );
|
|
|
|
$spy->referencesFormatter->method( 'formatReferences' )
|
2019-12-09 14:07:37 +00:00
|
|
|
->with( $parser, [], $expectedResponsive, false )
|
2019-12-11 15:02:49 +00:00
|
|
|
->willReturn( 'references!' );
|
2019-12-03 22:39:52 +00:00
|
|
|
$spy->isSectionPreview = false;
|
|
|
|
$spy->referenceStack = $this->createMock( ReferenceStack::class );
|
2019-12-09 14:07:37 +00:00
|
|
|
$spy->referenceStack->method( 'popGroup' )
|
2019-12-03 22:39:52 +00:00
|
|
|
->with( $expectedInReferencesGroup )->willReturn( [] );
|
2019-12-19 09:16:14 +00:00
|
|
|
$spy->referenceStack->expects( $expectedRollbackCount ? $this->once() : $this->never() )
|
|
|
|
->method( 'rollbackRefs' )
|
|
|
|
->with( $expectedRollbackCount )
|
|
|
|
->willReturn( [ [ 't', [] ] ] );
|
2019-12-03 22:39:52 +00:00
|
|
|
|
2023-12-12 11:03:45 +00:00
|
|
|
$output = $cite->references( $parser, $text, $argv );
|
2019-12-03 22:39:52 +00:00
|
|
|
$this->assertSame( $expectedOutput, $output );
|
|
|
|
}
|
|
|
|
|
2023-05-20 10:03:41 +00:00
|
|
|
public static function provideGuardedReferences() {
|
2019-12-03 22:39:52 +00:00
|
|
|
return [
|
|
|
|
'Bare references tag' => [
|
|
|
|
null,
|
|
|
|
[],
|
|
|
|
0,
|
|
|
|
'',
|
|
|
|
false,
|
|
|
|
'references!'
|
|
|
|
],
|
|
|
|
'References with group' => [
|
|
|
|
null,
|
|
|
|
[ 'group' => 'g' ],
|
|
|
|
0,
|
|
|
|
'g',
|
|
|
|
false,
|
|
|
|
'references!'
|
|
|
|
],
|
|
|
|
'Empty references tag' => [
|
|
|
|
'',
|
|
|
|
[],
|
|
|
|
0,
|
|
|
|
'',
|
|
|
|
false,
|
|
|
|
'references!'
|
|
|
|
],
|
|
|
|
'Set responsive' => [
|
|
|
|
'',
|
|
|
|
[ 'responsive' => '1' ],
|
|
|
|
0,
|
|
|
|
'',
|
|
|
|
true,
|
|
|
|
'references!'
|
|
|
|
],
|
|
|
|
'Unknown attribute' => [
|
|
|
|
'',
|
|
|
|
[ 'blargh' => '0' ],
|
|
|
|
0,
|
|
|
|
'',
|
|
|
|
false,
|
2019-12-09 16:08:57 +00:00
|
|
|
'(cite_error_references_invalid_parameters)',
|
2019-12-03 22:39:52 +00:00
|
|
|
],
|
|
|
|
'Contains refs (which are broken)' => [
|
|
|
|
Parser::MARKER_PREFIX . '-ref- and ' . Parser::MARKER_PREFIX . '-notref-',
|
|
|
|
[],
|
|
|
|
1,
|
|
|
|
'',
|
|
|
|
false,
|
2023-12-14 07:58:49 +00:00
|
|
|
"references!\n(cite_error_references_no_key)"
|
2019-12-03 22:39:52 +00:00
|
|
|
],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2019-12-03 12:48:03 +00:00
|
|
|
/**
|
|
|
|
* @covers ::guardedRef
|
|
|
|
* @dataProvider provideGuardedRef
|
|
|
|
*/
|
|
|
|
public function testGuardedRef(
|
|
|
|
string $text,
|
|
|
|
array $argv,
|
|
|
|
?string $inReferencesGroup,
|
|
|
|
array $initialRefs,
|
|
|
|
string $expectOutput,
|
|
|
|
array $expectedErrors,
|
2020-07-21 11:19:38 +00:00
|
|
|
array $expectedRefs,
|
|
|
|
bool $isSectionPreview = false
|
2019-12-03 12:48:03 +00:00
|
|
|
) {
|
2023-07-27 09:39:46 +00:00
|
|
|
$mockParser = $this->createNoOpMock( Parser::class, [ 'getStripState' ] );
|
2019-12-03 12:48:03 +00:00
|
|
|
$mockParser->method( 'getStripState' )
|
|
|
|
->willReturn( $this->createMock( StripState::class ) );
|
2019-12-06 12:09:28 +00:00
|
|
|
|
2023-12-14 07:58:49 +00:00
|
|
|
$errorReporter = $this->createMock( ErrorReporter::class );
|
|
|
|
$errorReporter->method( $this->logicalOr( 'halfParsed', 'plain' ) )->willReturnCallback(
|
|
|
|
static fn ( $parser, ...$args ) => '(' . implode( '|', $args ) . ')'
|
2019-12-03 12:48:03 +00:00
|
|
|
);
|
2019-12-06 12:09:28 +00:00
|
|
|
|
2023-12-14 07:58:49 +00:00
|
|
|
$referenceStack = new ReferenceStack( $errorReporter );
|
2023-06-05 14:36:03 +00:00
|
|
|
/** @var ReferenceStack $stackSpy */
|
|
|
|
$stackSpy = TestingAccessWrapper::newFromObject( $referenceStack );
|
|
|
|
$stackSpy->refs = $initialRefs;
|
2020-01-20 15:27:53 +00:00
|
|
|
|
2019-12-03 12:48:03 +00:00
|
|
|
$mockFootnoteMarkFormatter = $this->createMock( FootnoteMarkFormatter::class );
|
|
|
|
$mockFootnoteMarkFormatter->method( 'linkRef' )->willReturn( '<foot />' );
|
2019-12-06 12:09:28 +00:00
|
|
|
|
2020-07-21 11:19:38 +00:00
|
|
|
$cite = $this->newCite( $isSectionPreview );
|
2019-12-06 12:09:28 +00:00
|
|
|
/** @var Cite $spy */
|
|
|
|
$spy = TestingAccessWrapper::newFromObject( $cite );
|
2023-12-14 07:58:49 +00:00
|
|
|
$spy->errorReporter = $errorReporter;
|
2019-12-03 12:48:03 +00:00
|
|
|
$spy->footnoteMarkFormatter = $mockFootnoteMarkFormatter;
|
|
|
|
$spy->inReferencesGroup = $inReferencesGroup;
|
2020-01-20 15:27:53 +00:00
|
|
|
$spy->referenceStack = $referenceStack;
|
2019-12-03 12:48:03 +00:00
|
|
|
|
2019-12-19 09:16:14 +00:00
|
|
|
$result = $spy->guardedRef( $mockParser, $text, $argv );
|
2019-12-03 12:48:03 +00:00
|
|
|
$this->assertSame( $expectOutput, $result );
|
|
|
|
$this->assertSame( $expectedErrors, $spy->mReferencesErrors );
|
2023-06-05 14:36:03 +00:00
|
|
|
$this->assertSame( $expectedRefs, $stackSpy->refs );
|
2019-12-03 12:48:03 +00:00
|
|
|
}
|
|
|
|
|
2023-05-20 10:03:41 +00:00
|
|
|
public static function provideGuardedRef() {
|
2019-12-03 12:48:03 +00:00
|
|
|
return [
|
|
|
|
'Whitespace text' => [
|
|
|
|
' ',
|
2020-10-08 09:07:35 +00:00
|
|
|
[ 'name' => 'a' ],
|
2019-12-03 12:48:03 +00:00
|
|
|
null,
|
|
|
|
[],
|
|
|
|
'<foot />',
|
|
|
|
[],
|
|
|
|
[
|
2020-01-20 15:27:53 +00:00
|
|
|
'' => [
|
|
|
|
'a' => [
|
|
|
|
'count' => 0,
|
|
|
|
'dir' => null,
|
|
|
|
'key' => 1,
|
|
|
|
'name' => 'a',
|
|
|
|
'text' => null,
|
|
|
|
'number' => 1,
|
|
|
|
],
|
|
|
|
],
|
2019-12-03 12:48:03 +00:00
|
|
|
]
|
|
|
|
],
|
|
|
|
'Empty in default references' => [
|
|
|
|
'',
|
|
|
|
[],
|
|
|
|
'',
|
2020-01-13 13:29:23 +00:00
|
|
|
[ '' => [] ],
|
2019-12-03 12:48:03 +00:00
|
|
|
'',
|
2023-12-11 16:53:56 +00:00
|
|
|
'expectedErrors' => [ [ 'cite_error_references_no_key' ] ],
|
2020-01-20 15:27:53 +00:00
|
|
|
[ '' => [] ]
|
2019-12-03 12:48:03 +00:00
|
|
|
],
|
|
|
|
'Fallback to references group' => [
|
|
|
|
'text',
|
2020-10-08 09:07:35 +00:00
|
|
|
[ 'name' => 'a' ],
|
2019-12-03 12:48:03 +00:00
|
|
|
'foo',
|
|
|
|
[
|
|
|
|
'foo' => [
|
|
|
|
'a' => []
|
|
|
|
]
|
|
|
|
],
|
|
|
|
'',
|
|
|
|
[],
|
|
|
|
[
|
2020-01-20 15:27:53 +00:00
|
|
|
'foo' => [
|
|
|
|
'a' => [ 'text' => 'text' ],
|
|
|
|
],
|
2019-12-03 12:48:03 +00:00
|
|
|
]
|
|
|
|
],
|
|
|
|
'Successful ref' => [
|
|
|
|
'text',
|
2020-10-08 09:07:35 +00:00
|
|
|
[ 'name' => 'a' ],
|
2019-12-03 12:48:03 +00:00
|
|
|
null,
|
|
|
|
[],
|
|
|
|
'<foot />',
|
|
|
|
[],
|
|
|
|
[
|
2020-01-20 15:27:53 +00:00
|
|
|
'' => [
|
|
|
|
'a' => [
|
|
|
|
'count' => 0,
|
|
|
|
'dir' => null,
|
|
|
|
'key' => 1,
|
|
|
|
'name' => 'a',
|
|
|
|
'text' => 'text',
|
|
|
|
'number' => 1,
|
|
|
|
],
|
|
|
|
],
|
2019-12-03 12:48:03 +00:00
|
|
|
]
|
|
|
|
],
|
|
|
|
'Invalid ref' => [
|
|
|
|
'text',
|
|
|
|
[
|
|
|
|
'name' => 'a',
|
|
|
|
'badkey' => 'b',
|
|
|
|
],
|
|
|
|
null,
|
|
|
|
[],
|
2019-12-09 16:08:57 +00:00
|
|
|
'(cite_error_ref_too_many_keys)',
|
2019-12-03 12:48:03 +00:00
|
|
|
[],
|
2020-01-20 15:27:53 +00:00
|
|
|
[]
|
2019-12-03 12:48:03 +00:00
|
|
|
],
|
|
|
|
'Successful references ref' => [
|
|
|
|
'text',
|
2020-10-08 09:07:35 +00:00
|
|
|
[ 'name' => 'a' ],
|
2019-12-03 12:48:03 +00:00
|
|
|
'',
|
|
|
|
[
|
|
|
|
'' => [
|
|
|
|
'a' => []
|
|
|
|
]
|
|
|
|
],
|
|
|
|
'',
|
|
|
|
[],
|
|
|
|
[
|
2020-01-20 15:27:53 +00:00
|
|
|
'' => [
|
|
|
|
'a' => [ 'text' => 'text' ],
|
|
|
|
],
|
2019-12-03 12:48:03 +00:00
|
|
|
]
|
|
|
|
],
|
2020-07-21 11:19:38 +00:00
|
|
|
'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,
|
|
|
|
],
|
2019-12-03 12:48:03 +00:00
|
|
|
'Mismatched text in references' => [
|
|
|
|
'text-2',
|
2020-10-08 09:07:35 +00:00
|
|
|
[ 'name' => 'a' ],
|
2019-12-03 12:48:03 +00:00
|
|
|
'',
|
|
|
|
[
|
|
|
|
'' => [
|
2020-10-08 09:07:35 +00:00
|
|
|
'a' => [ 'text' => 'text-1' ],
|
2019-12-03 12:48:03 +00:00
|
|
|
]
|
|
|
|
],
|
|
|
|
'',
|
|
|
|
[],
|
|
|
|
[
|
2020-01-20 15:27:53 +00:00
|
|
|
'' => [
|
|
|
|
'a' => [ 'text' => 'text-1 (cite_error_references_duplicate_key|a)' ],
|
|
|
|
],
|
2019-12-03 12:48:03 +00:00
|
|
|
]
|
|
|
|
],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2019-12-03 12:39:02 +00:00
|
|
|
/**
|
|
|
|
* @covers ::guardedRef
|
|
|
|
*/
|
|
|
|
public function testGuardedRef_extendsProperty() {
|
2023-12-11 11:15:29 +00:00
|
|
|
$this->overrideConfigValue( 'CiteBookReferencing', false );
|
|
|
|
|
2019-12-03 12:39:02 +00:00
|
|
|
$mockOutput = $this->createMock( ParserOutput::class );
|
|
|
|
// This will be our most important assertion.
|
|
|
|
$mockOutput->expects( $this->once() )
|
2021-10-08 14:12:05 +00:00
|
|
|
->method( 'setPageProperty' )
|
2022-03-31 17:35:19 +00:00
|
|
|
->with( Cite::BOOK_REF_PROPERTY, '' );
|
2019-12-03 12:39:02 +00:00
|
|
|
|
2023-07-27 09:39:46 +00:00
|
|
|
$mockParser = $this->createNoOpMock( Parser::class, [ 'getOutput' ] );
|
2019-12-03 12:39:02 +00:00
|
|
|
$mockParser->method( 'getOutput' )->willReturn( $mockOutput );
|
|
|
|
|
2019-12-11 13:58:25 +00:00
|
|
|
$cite = $this->newCite();
|
2019-12-06 12:09:28 +00:00
|
|
|
/** @var Cite $spy */
|
2019-12-03 12:39:02 +00:00
|
|
|
$spy = TestingAccessWrapper::newFromObject( $cite );
|
2019-12-09 16:08:57 +00:00
|
|
|
$spy->errorReporter = $this->createMock( ErrorReporter::class );
|
2019-12-03 12:39:02 +00:00
|
|
|
|
2019-12-19 09:16:14 +00:00
|
|
|
$spy->guardedRef( $mockParser, 'text', [ Cite::BOOK_REF_ATTRIBUTE => 'a' ] );
|
2019-12-03 12:39:02 +00:00
|
|
|
}
|
|
|
|
|
2020-01-13 13:29:23 +00:00
|
|
|
/**
|
|
|
|
* @coversNothing
|
|
|
|
*/
|
|
|
|
public function testReferencesSectionPreview() {
|
2023-07-27 09:39:46 +00:00
|
|
|
$language = $this->createNoOpMock( Language::class );
|
|
|
|
|
2020-01-13 13:29:23 +00:00
|
|
|
$parserOptions = $this->createMock( ParserOptions::class );
|
|
|
|
$parserOptions->method( 'getIsSectionPreview' )->willReturn( true );
|
|
|
|
|
2023-07-27 09:39:46 +00:00
|
|
|
$parser = $this->createNoOpMock( Parser::class, [ 'getOptions', 'getContentLanguage' ] );
|
2020-01-13 13:29:23 +00:00
|
|
|
$parser->method( 'getOptions' )->willReturn( $parserOptions );
|
2023-07-27 09:39:46 +00:00
|
|
|
$parser->method( 'getContentLanguage' )->willReturn( $language );
|
2020-01-13 13:29:23 +00:00
|
|
|
|
|
|
|
/** @var Cite $cite */
|
|
|
|
$cite = TestingAccessWrapper::newFromObject( new Cite( $parser ) );
|
|
|
|
// Assume the currently parsed <ref> is wrapped in <references>
|
|
|
|
$cite->inReferencesGroup = '';
|
|
|
|
|
|
|
|
$html = $cite->guardedRef( $parser, 'a', [ 'name' => 'a' ] );
|
|
|
|
$this->assertSame( '', $html );
|
|
|
|
}
|
|
|
|
|
2019-12-11 11:19:18 +00:00
|
|
|
/**
|
|
|
|
* @covers ::__clone
|
2019-12-18 15:06:53 +00:00
|
|
|
* @covers ::__construct
|
2019-12-11 11:19:18 +00:00
|
|
|
*/
|
|
|
|
public function testClone() {
|
2019-12-20 18:31:54 +00:00
|
|
|
$cite = $this->newCite();
|
2019-12-11 11:19:18 +00:00
|
|
|
|
2019-12-20 18:31:54 +00:00
|
|
|
$this->expectException( LogicException::class );
|
|
|
|
clone $cite;
|
2019-12-11 11:19:18 +00:00
|
|
|
}
|
|
|
|
|
2021-07-22 05:44:15 +00:00
|
|
|
private function newCite( bool $isSectionPreview = false ): Cite {
|
2023-07-27 09:39:46 +00:00
|
|
|
$language = $this->createNoOpMock( Language::class, [ '__debugInfo' ] );
|
|
|
|
|
2019-12-11 13:58:25 +00:00
|
|
|
$mockOptions = $this->createMock( ParserOptions::class );
|
2020-07-21 11:19:38 +00:00
|
|
|
$mockOptions->method( 'getIsSectionPreview' )->willReturn( $isSectionPreview );
|
2023-07-27 09:39:46 +00:00
|
|
|
|
|
|
|
$mockParser = $this->createNoOpMock( Parser::class, [ 'getOptions', 'getContentLanguage' ] );
|
2019-12-11 13:58:25 +00:00
|
|
|
$mockParser->method( 'getOptions' )->willReturn( $mockOptions );
|
2023-07-27 09:39:46 +00:00
|
|
|
$mockParser->method( 'getContentLanguage' )->willReturn( $language );
|
2019-12-11 13:58:25 +00:00
|
|
|
return new Cite( $mockParser );
|
|
|
|
}
|
|
|
|
|
2019-11-08 14:46:52 +00:00
|
|
|
}
|