setMwGlobals( [
'wgLanguageCode' => 'qqx',
] );
}
/**
* @covers ::checkRefsNoReferences
* @dataProvider provideCheckRefsNoReferences
*/
public function testCheckRefsNoReferences(
array $initialRefs, bool $isSectionPreview, string $expectedOutput
) {
global $wgCiteResponsiveReferences;
$wgCiteResponsiveReferences = true;
$mockErrorReporter = $this->createMock( ErrorReporter::class );
$mockErrorReporter->method( 'halfParsed' )->willReturnCallback(
function ( $parser, ...$args ) {
return '(' . implode( '|', $args ) . ')';
}
);
/** @var ReferenceStack $referenceStack */
$referenceStack = TestingAccessWrapper::newFromObject( new ReferenceStack( $mockErrorReporter ) );
$referenceStack->refs = $initialRefs;
$referencesFormatter = $this->createMock( ReferencesFormatter::class );
$referencesFormatter->method( 'formatReferences' )->willReturn( '' );
$cite = $this->newCite();
/** @var Cite $spy */
$spy = TestingAccessWrapper::newFromObject( $cite );
$spy->referenceStack = $referenceStack;
$spy->errorReporter = $mockErrorReporter;
$spy->referencesFormatter = $referencesFormatter;
$spy->isSectionPreview = $isSectionPreview;
$output = $cite->checkRefsNoReferences(
$this->createMock( Parser::class ), $isSectionPreview );
$this->assertSame( $expectedOutput, $output );
}
public function provideCheckRefsNoReferences() {
return [
'Default group' => [
[
'' => [
[
'name' => 'a',
]
]
],
false,
''
],
'Default group in preview' => [
[
'' => [
[
'name' => 'a',
]
]
],
true,
"\n" . '
' .
'
'
],
'Named group' => [
[
'foo' => [
[
'name' => 'a',
]
]
],
false,
"\n" . '
(cite_error_group_refs_without_references|foo)'
],
'Named group in preview' => [
[
'foo' => [
[
'name' => 'a',
]
]
],
true,
"\n" . '' .
'
'
]
];
}
private function newCite() : Cite {
$mockOptions = $this->createMock( ParserOptions::class );
$mockOptions->method( 'getIsPreview' )->willReturn( false );
$mockOptions->method( 'getIsSectionPreview' )->willReturn( false );
$mockOptions->method( 'getUserLangObj' )->willReturn(
$this->createMock( Language::class ) );
$mockParser = $this->createMock( Parser::class );
$mockParser->method( 'getOptions' )->willReturn( $mockOptions );
$mockParser->method( 'getContentLanguage' )->willReturn(
$this->createMock( Language::class ) );
/** @var Parser $mockParser */
return new Cite( $mockParser );
}
}