mediawiki-extensions-Cite/tests/phpunit/CiteIntegrationTest.php
Thiemo Kreuz 8fdce945bd Show "Preview" headline in user instead of content language
This partly reverts Id7a4036e64920acdeccb4dfcf6bef31d0e5657ab.

The message "cite_section_preview_references" says "Preview of references".
This line is not meant to be part of the content, but an interface message.
It should use the users (interface) language, not the content language.

Change-Id: I1b1b5106266606eb0dfaa31f4abd3cee9ba92e8c
2019-12-09 10:53:07 +01:00

120 lines
2.8 KiB
PHP

<?php
namespace Cite\Tests;
use Cite\Cite;
use Cite\CiteErrorReporter;
use Cite\FootnoteBodyFormatter;
use Cite\ReferenceStack;
use Wikimedia\TestingAccessWrapper;
/**
* @coversDefaultClass \Cite\Cite
*
* @license GPL-2.0-or-later
*/
class CiteIntegrationTest extends \MediaWikiIntegrationTestCase {
protected function setUp() : void {
parent::setUp();
$this->setMwGlobals( [
'wgLanguageCode' => 'qqx',
] );
}
/**
* @covers ::checkRefsNoReferences
* @dataProvider provideCheckRefsNoReferences
*/
public function testCheckRefsNoReferences(
array $initialRefs, bool $isSectionPreview, string $expectedOutput
) {
global $wgCiteResponsiveReferences;
$wgCiteResponsiveReferences = true;
$mockReferenceStack = $this->createMock( ReferenceStack::class );
$mockReferenceStack->method( 'getGroups' )->willReturn( array_keys( $initialRefs ) );
$mockReferenceStack->method( 'getGroupRefs' )->willReturnCallback( function ( $group ) use (
$initialRefs
) {
return $initialRefs[$group];
} );
$mockErrorReporter = $this->createMock( CiteErrorReporter::class );
$mockErrorReporter->method( 'halfParsed' )->willReturnCallback(
function ( ...$args ) {
return '(' . implode( '|', $args ) . ')';
}
);
$mockFootnoteBodyFormatter = $this->createMock( FootnoteBodyFormatter::class );
$mockFootnoteBodyFormatter->method( 'referencesFormat' )->willReturn( '<references />' );
$cite = new Cite();
/** @var Cite $spy */
$spy = TestingAccessWrapper::newFromObject( $cite );
$spy->referenceStack = $mockReferenceStack;
$spy->errorReporter = $mockErrorReporter;
$spy->footnoteBodyFormatter = $mockFootnoteBodyFormatter;
$spy->isSectionPreview = $isSectionPreview;
$output = $cite->checkRefsNoReferences( $isSectionPreview );
$this->assertSame( $expectedOutput, $output );
}
public function provideCheckRefsNoReferences() {
return [
'Default group' => [
[
'' => [
[
'name' => 'a',
]
]
],
false,
'<references />'
],
'Default group in preview' => [
[
'' => [
[
'name' => 'a',
]
]
],
true,
"\n" . '<div class="mw-ext-cite-cite_section_preview_references" >' .
'<h2 id="mw-ext-cite-cite_section_preview_references_header" >' .
'(cite_section_preview_references)</h2><references /></div>'
],
'Named group' => [
[
'foo' => [
[
'name' => 'a',
]
]
],
false,
"\n" . '<br />(cite_error_group_refs_without_references|foo)'
],
'Named group in preview' => [
[
'foo' => [
[
'name' => 'a',
]
]
],
true,
"\n" . '<div class="mw-ext-cite-cite_section_preview_references" >' .
'<h2 id="mw-ext-cite-cite_section_preview_references_header" >' .
'(cite_section_preview_references)</h2><references /></div>'
]
];
}
}