overrideConfigValue( MainConfigNames::LanguageCode, 'qqx' );
}
/**
* @dataProvider provideCheckRefsNoReferences
*/
public function testCheckRefsNoReferences(
array $initialRefs, bool $isSectionPreview, string $expectedOutput
) {
$this->overrideConfigValue( 'CiteResponsiveReferences', true );
$mockErrorReporter = $this->createMock( ErrorReporter::class );
$mockErrorReporter->method( 'halfParsed' )->willReturnCallback(
static fn ( $parser, ...$args ) => '(' . implode( '|', $args ) . ')'
);
$referenceStack = new ReferenceStack();
TestingAccessWrapper::newFromObject( $referenceStack )->refs = $initialRefs;
$formatter = $this->createMock( ReferenceListFormatter::class );
$formatter->method( 'formatReferences' )->willReturn( '' );
$cite = $this->newCite();
/** @var Cite $spy */
$spy = TestingAccessWrapper::newFromObject( $cite );
$spy->referenceStack = $referenceStack;
$spy->errorReporter = $mockErrorReporter;
$spy->referenceListFormatter = $formatter;
$spy->isSectionPreview = $isSectionPreview;
$parser = $this->createNoOpMock( Parser::class );
$output = $cite->checkRefsNoReferences( $parser, $isSectionPreview );
$this->assertSame( $expectedOutput, $output );
}
public static function provideCheckRefsNoReferences() {
return [
'Default group' => [
[ '' => [ [ 'name' => 'a' ] ] ],
false,
"\n"
],
'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 {
$language = $this->createNoOpMock( Language::class );
$mockOptions = $this->createMock( ParserOptions::class );
$mockOptions->method( 'getIsPreview' )->willReturn( false );
$mockOptions->method( 'getIsSectionPreview' )->willReturn( false );
$mockParser = $this->createNoOpMock( Parser::class, [ 'getOptions', 'getContentLanguage' ] );
$mockParser->method( 'getOptions' )->willReturn( $mockOptions );
$mockParser->method( 'getContentLanguage' )->willReturn( $language );
return new Cite( $mockParser );
}
}