2019-11-12 15:08:44 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Cite\Tests\Unit;
|
|
|
|
|
2021-11-10 20:36:35 +00:00
|
|
|
use Cite\ResourceLoader\CiteVisualEditorModule;
|
2019-11-12 15:08:44 +00:00
|
|
|
use Message;
|
|
|
|
use ResourceLoaderContext;
|
|
|
|
|
|
|
|
/**
|
2021-11-10 20:36:35 +00:00
|
|
|
* @covers \Cite\ResourceLoader\CiteVisualEditorModule
|
2019-11-19 10:31:08 +00:00
|
|
|
*
|
|
|
|
* @license GPL-2.0-or-later
|
2019-11-12 15:08:44 +00:00
|
|
|
*/
|
|
|
|
class CiteDataModuleTest extends \MediaWikiUnitTestCase {
|
|
|
|
|
|
|
|
public function testGetScript() {
|
2021-11-10 20:36:35 +00:00
|
|
|
$module = new CiteVisualEditorModule();
|
2019-11-12 15:08:44 +00:00
|
|
|
$context = $this->createResourceLoaderContext();
|
|
|
|
|
|
|
|
$this->assertSame(
|
2021-11-10 20:56:35 +00:00
|
|
|
've.ui.mwCitationTools = [{"name":"n","title":"t"}];',
|
2021-11-10 20:36:35 +00:00
|
|
|
$module->makePrependedScript( $context )
|
2019-11-12 15:08:44 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetDefinitionSummary() {
|
2021-11-10 20:36:35 +00:00
|
|
|
$module = new CiteVisualEditorModule();
|
2019-11-12 15:08:44 +00:00
|
|
|
$context = $this->createResourceLoaderContext();
|
2021-11-10 20:36:35 +00:00
|
|
|
$summary = $module->getDefinitionSummary( $context );
|
2019-11-12 15:08:44 +00:00
|
|
|
|
2021-11-10 20:36:35 +00:00
|
|
|
$this->assertStringContainsString(
|
2021-11-10 20:56:35 +00:00
|
|
|
'{"name":"n","title":"t"}',
|
2021-11-10 20:36:35 +00:00
|
|
|
array_pop( $summary )['script']
|
2019-11-12 15:08:44 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-07-22 05:44:15 +00:00
|
|
|
private function createResourceLoaderContext(): ResourceLoaderContext {
|
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
|
|
|
|
2021-11-10 20:36:35 +00:00
|
|
|
$context = $this->createStub( ResourceLoaderContext::class );
|
2019-11-12 15:08:44 +00:00
|
|
|
$context->method( 'msg' )
|
2019-12-11 11:19:18 +00:00
|
|
|
->withConsecutive(
|
|
|
|
[ 'cite-tool-definition.json' ],
|
|
|
|
[ 'visualeditor-cite-tool-definition.json' ],
|
2021-11-10 20:36:35 +00:00
|
|
|
[ 'visualeditor-cite-tool-name-n' ]
|
2019-12-11 11:19:18 +00:00
|
|
|
)
|
2019-11-12 15:08:44 +00:00
|
|
|
->willReturn( $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;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|