mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Cite
synced 2025-01-06 02:34:14 +00:00
fb2c7c37db
Rather than depending on a separate module with one line of generated JS code, generate it as a prepended statement to the same module. Should be a no-op. Depends-On: I809951d34feb2dbd01b7ae0f4bd98dac7c3f6fe2 Change-Id: I5886bf9f82025048976b7750e8cb751681021fb4
60 lines
1.6 KiB
PHP
60 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace Cite\Tests\Unit;
|
|
|
|
use Cite\ResourceLoader\CiteVisualEditorModule;
|
|
use Message;
|
|
use ResourceLoaderContext;
|
|
|
|
/**
|
|
* @covers \Cite\ResourceLoader\CiteVisualEditorModule
|
|
*
|
|
* @license GPL-2.0-or-later
|
|
*/
|
|
class CiteDataModuleTest extends \MediaWikiUnitTestCase {
|
|
|
|
public function testGetScript() {
|
|
$module = new CiteVisualEditorModule();
|
|
$context = $this->createResourceLoaderContext();
|
|
|
|
$this->assertSame(
|
|
've.init.platform.addMessages({"cite-tool-definition.json":' .
|
|
'"[{\"name\":\"n\",\"title\":\"t\"}]"});',
|
|
$module->makePrependedScript( $context )
|
|
);
|
|
}
|
|
|
|
public function testGetDefinitionSummary() {
|
|
$module = new CiteVisualEditorModule();
|
|
$context = $this->createResourceLoaderContext();
|
|
$summary = $module->getDefinitionSummary( $context );
|
|
|
|
$this->assertStringContainsString(
|
|
'{\"name\":\"n\",\"title\":\"t\"}]"}',
|
|
array_pop( $summary )['script']
|
|
);
|
|
}
|
|
|
|
private function createResourceLoaderContext(): ResourceLoaderContext {
|
|
$msg = $this->createMock( Message::class );
|
|
$msg->method( 'inContentLanguage' )
|
|
->willReturnSelf();
|
|
$msg->method( 'plain' )
|
|
->willReturnOnConsecutiveCalls( '', '[{"name":"n"}]' );
|
|
$msg->method( 'text' )
|
|
->willReturn( 't' );
|
|
|
|
$context = $this->createStub( ResourceLoaderContext::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;
|
|
}
|
|
|
|
}
|