2019-11-12 15:08:44 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Cite\Tests\Unit;
|
|
|
|
|
2023-05-05 05:50:22 +00:00
|
|
|
use Cite\ResourceLoader\CitationToolDefinition;
|
2022-05-20 02:11:31 +00:00
|
|
|
use MediaWiki\ResourceLoader\Context;
|
2019-11-12 15:08:44 +00:00
|
|
|
use Message;
|
|
|
|
|
|
|
|
/**
|
2023-05-05 05:50:22 +00:00
|
|
|
* @covers \Cite\ResourceLoader\CitationToolDefinition
|
2019-11-19 10:31:08 +00:00
|
|
|
*
|
|
|
|
* @license GPL-2.0-or-later
|
2019-11-12 15:08:44 +00:00
|
|
|
*/
|
2023-05-05 05:50:22 +00:00
|
|
|
class CitationToolDefinitionTest extends \MediaWikiUnitTestCase {
|
2019-11-12 15:08:44 +00:00
|
|
|
|
|
|
|
public function testGetScript() {
|
|
|
|
$context = $this->createResourceLoaderContext();
|
|
|
|
|
|
|
|
$this->assertSame(
|
2021-11-10 20:56:35 +00:00
|
|
|
've.ui.mwCitationTools = [{"name":"n","title":"t"}];',
|
2023-05-05 05:50:22 +00:00
|
|
|
CitationToolDefinition::makeScript( $context )
|
2019-11-12 15:08:44 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-05-20 02:11:31 +00:00
|
|
|
private function createResourceLoaderContext(): Context {
|
2019-11-12 15:08:44 +00:00
|
|
|
$msg = $this->createMock( Message::class );
|
|
|
|
$msg->method( 'inContentLanguage' )
|
|
|
|
->willReturnSelf();
|
|
|
|
$msg->method( 'plain' )
|
2021-11-10 20:36:35 +00:00
|
|
|
->willReturnOnConsecutiveCalls( '', '[{"name":"n"}]' );
|
2019-12-11 11:19:18 +00:00
|
|
|
$msg->method( 'text' )
|
|
|
|
->willReturn( 't' );
|
2019-11-12 15:08:44 +00:00
|
|
|
|
2022-05-20 02:11:31 +00:00
|
|
|
$context = $this->createStub( Context::class );
|
2019-11-12 15:08:44 +00:00
|
|
|
$context->method( 'msg' )
|
2023-11-21 23:15:20 +00:00
|
|
|
->willReturnMap( [
|
|
|
|
[ 'cite-tool-definition.json', $msg ],
|
|
|
|
[ 'visualeditor-cite-tool-definition.json', $msg ],
|
|
|
|
[ 'visualeditor-cite-tool-name-n', $msg ]
|
|
|
|
] );
|
2021-11-10 20:36:35 +00:00
|
|
|
$context->method( 'encodeJson' )->willReturnCallback( 'json_encode' );
|
2019-11-12 15:08:44 +00:00
|
|
|
return $context;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|