mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Cite
synced 2024-12-04 19:38:16 +00:00
3de8f65114
Changes to the use statements done automatically via script Change-Id: I4b49c4ab87f1fcd5cdf29d5f882dec3c3902e146
64 lines
1.7 KiB
PHP
64 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace Cite\Tests\Unit;
|
|
|
|
use Cite\ResourceLoader\CitationToolDefinition;
|
|
use MediaWiki\Message\Message;
|
|
use MediaWiki\ResourceLoader\Context;
|
|
|
|
/**
|
|
* @covers \Cite\ResourceLoader\CitationToolDefinition
|
|
* @license GPL-2.0-or-later
|
|
*/
|
|
class CitationToolDefinitionTest extends \MediaWikiUnitTestCase {
|
|
|
|
public function testGetScript() {
|
|
$context = $this->createResourceLoaderContext();
|
|
|
|
$expected = [
|
|
[ 'name' => 'no-message', 'title' => 'Hard-coded title' ],
|
|
[ 'name' => 'missing-message', 'title' => 'missing-message' ],
|
|
[ 'name' => 'n', 'title' => 't' ],
|
|
];
|
|
$this->assertSame(
|
|
've.ui.mwCitationTools = ' . json_encode( $expected ) . ';',
|
|
CitationToolDefinition::makeScript( $context )
|
|
);
|
|
}
|
|
|
|
private function createResourceLoaderContext(): Context {
|
|
$definition = [
|
|
// We expect broken and incomplete entries to be skipped
|
|
[],
|
|
[ 'name' => '' ],
|
|
|
|
[ 'name' => 'no-message', 'title' => 'Hard-coded title' ],
|
|
[ 'name' => 'missing-message' ],
|
|
[ 'name' => 'n' ],
|
|
];
|
|
|
|
$msg = $this->createMock( Message::class );
|
|
$msg->method( 'inContentLanguage' )
|
|
->willReturnSelf();
|
|
$msg->method( 'plain' )
|
|
->willReturn( json_encode( $definition ) );
|
|
$msg->method( 'text' )
|
|
->willReturn( 't' );
|
|
|
|
$disabled = $this->createMock( Message::class );
|
|
$disabled->method( 'isDisabled' )->willReturn( true );
|
|
|
|
$context = $this->createStub( Context::class );
|
|
$context->method( 'msg' )
|
|
->willReturnMap( [
|
|
[ 'cite-tool-definition.json', $msg ],
|
|
[ 'visualeditor-cite-tool-definition.json', $msg ],
|
|
[ 'visualeditor-cite-tool-name-missing-message', $disabled ],
|
|
[ 'visualeditor-cite-tool-name-n', $msg ]
|
|
] );
|
|
$context->method( 'encodeJson' )->willReturnCallback( 'json_encode' );
|
|
return $context;
|
|
}
|
|
|
|
}
|