createReporter( $expectedCategories );
$this->assertSame(
$expectedHtml,
$reporter->plain( $key, 'first param' ) );
}
/**
* @covers ::halfParsed
*/
public function testHalfParsed() {
$reporter = $this->createReporter( [] );
$expectedHtml = '';
$this->assertSame(
'[(cite_warning|(cite_warning_example|first param))]',
$reporter->halfParsed( 'cite_warning_example', 'first param' ) );
}
public function provideErrors() {
return [
'Example error' => [
'cite_error_example',
'' .
'(cite_error|(cite_error_example|first param))',
[ 'cite-tracking-category-cite-error' ]
],
'Warning error' => [
'cite_warning_example',
'(cite_warning|(cite_warning_example|first param))',
[]
],
];
}
private function createReporter( array $expectedCategories ) : CiteErrorReporter {
$mockParser = $this->createMock( Parser::class );
foreach ( $expectedCategories as $category ) {
$mockParser->method( 'addTrackingCategory' )->with( $category );
}
$mockParser->method( 'getOptions' )->willReturnCallback(
function () {
$mockLanguage = $this->createMock( Language::class );
$mockLanguage->method( 'getCode' )->willReturn( 'ui' );
$mockLanguage->method( 'getDir' )->willReturn( 'rtl' );
$mockLanguage->method( 'getHtmlCode' )->willReturn( 'qqx' );
$mockOptions = $this->createMock( ParserOptions::class );
$mockOptions->method( 'getUserLangObj' )->willReturn( $mockLanguage );
return $mockOptions;
}
);
$mockParser->method( 'recursiveTagParse' )->willReturnCallback(
function ( $content ) {
return '[' . $content . ']';
}
);
$mockMessageLocalizer = $this->createMock( ReferenceMessageLocalizer::class );
$mockMessageLocalizer->method( 'msg' )->willReturnCallback(
function ( ...$args ) {
$rendered = '(' . implode( '|', $args ) . ')';
$mockMessage = $this->createMock( Message::class );
$mockMessage->method( 'getKey' )->willReturn( $args[0] );
$mockMessage->method( 'plain' )->willReturn( $rendered );
// FIXME: Doesn't prove that we've set the language correctly.
$mockMessage->method( 'inLanguage' )->willReturnSelf();
return $mockMessage;
}
);
/** @var Parser $mockParser */
/** @var ReferenceMessageLocalizer $mockMessageLocalizer */
return new CiteErrorReporter( $mockParser, $mockMessageLocalizer );
}
}