mediawiki-extensions-Cite/tests/phpunit/unit/CitationToolDefinitionTest.php
Tim Starling 5315297f38 Migrate CiteVisualEditorModule to a virtual file callback
Depends-On: I97d61b5793159cea365740e0563f7b733e0f16de
Bug: T47514
Change-Id: Iabfbb6751707813b7ec68f49b35441ab5dbb5622
2023-05-05 16:25:14 +10:00

47 lines
1.2 KiB
PHP

<?php
namespace Cite\Tests\Unit;
use Cite\ResourceLoader\CitationToolDefinition;
use MediaWiki\ResourceLoader\Context;
use Message;
/**
* @covers \Cite\ResourceLoader\CitationToolDefinition
*
* @license GPL-2.0-or-later
*/
class CitationToolDefinitionTest extends \MediaWikiUnitTestCase {
public function testGetScript() {
$context = $this->createResourceLoaderContext();
$this->assertSame(
've.ui.mwCitationTools = [{"name":"n","title":"t"}];',
CitationToolDefinition::makeScript( $context )
);
}
private function createResourceLoaderContext(): Context {
$msg = $this->createMock( Message::class );
$msg->method( 'inContentLanguage' )
->willReturnSelf();
$msg->method( 'plain' )
->willReturnOnConsecutiveCalls( '', '[{"name":"n"}]' );
$msg->method( 'text' )
->willReturn( 't' );
$context = $this->createStub( Context::class );
$context->method( 'msg' )
->withConsecutive(
[ 'cite-tool-definition.json' ],
[ 'visualeditor-cite-tool-definition.json' ],
[ 'visualeditor-cite-tool-name-n' ]
)
->willReturn( $msg );
$context->method( 'encodeJson' )->willReturnCallback( 'json_encode' );
return $context;
}
}