Merge "Combine ext.cite.visualEditor.data into ext.cite.visualEditor"

This commit is contained in:
jenkins-bot 2021-11-23 03:41:01 +00:00 committed by Gerrit Code Review
commit 962f84728c
3 changed files with 30 additions and 50 deletions

View file

@ -97,10 +97,8 @@
"mobile"
]
},
"ext.cite.visualEditor.data": {
"class": "Cite\\ResourceLoader\\CiteDataModule"
},
"ext.cite.visualEditor": {
"class": "Cite\\ResourceLoader\\CiteVisualEditorModule",
"localBasePath": "modules/ve-cite",
"remoteExtPath": "Cite/modules/ve-cite",
"scripts": [
@ -133,10 +131,10 @@
"oojs-ui.styles.icons-editing-citation",
"oojs-ui.styles.icons-interactions",
"ext.cite.visualEditor.core",
"ext.cite.visualEditor.data",
"ext.cite.style",
"ext.cite.styles",
"ext.visualEditor.mwtransclusion",
"ext.visualEditor.base",
"ext.visualEditor.mediawiki"
],
"messages": [

View file

@ -2,25 +2,29 @@
namespace Cite\ResourceLoader;
use FormatJson;
use ResourceLoader;
use ResourceLoaderContext;
/**
* Resource loader module providing extra data from the server to Cite.
* File module with extra data generated by the server.
*
* Temporary hack for T93800
* Temporary hack since 2015 for T93800.
*
* @copyright 2011-2018 VisualEditor Team's Cite sub-team and others; see AUTHORS.txt
* @license MIT
*/
class CiteDataModule extends \ResourceLoaderModule {
/** @inheritDoc */
protected $targets = [ 'desktop', 'mobile' ];
class CiteVisualEditorModule extends \ResourceLoaderFileModule {
/** @inheritDoc */
public function getScript( ResourceLoaderContext $context ) {
return $this->makePrependedScript( $context ) . parent::getScript( $context );
}
/**
* @internal
* @param ResourceLoaderContext $context
* @return string JavaScript code
*/
public function makePrependedScript( ResourceLoaderContext $context ) {
$citationDefinition = json_decode(
$context->msg( 'cite-tool-definition.json' )
->inContentLanguage()
@ -46,27 +50,18 @@ class CiteDataModule extends \ResourceLoaderModule {
}
}
return 've.init.platform.addMessages(' . FormatJson::encode(
return 've.init.platform.addMessages(' . $context->encodeJson(
[
'cite-tool-definition.json' => json_encode( $citationTools )
],
(bool)ResourceLoader::inDebugMode()
]
) . ');';
}
/** @inheritDoc */
public function getDependencies( ResourceLoaderContext $context = null ) {
return [
'ext.visualEditor.base',
'ext.visualEditor.mediawiki',
];
}
/** @inheritDoc */
public function getDefinitionSummary( ResourceLoaderContext $context ) {
$summary = parent::getDefinitionSummary( $context );
$summary[] = [
'script' => $this->getScript( $context ),
'script' => $this->makePrependedScript( $context ),
];
return $summary;
}

View file

@ -2,49 +2,36 @@
namespace Cite\Tests\Unit;
use Cite\ResourceLoader\CiteDataModule;
use Cite\ResourceLoader\CiteVisualEditorModule;
use Message;
use ResourceLoaderContext;
use WebRequest;
/**
* @covers \Cite\ResourceLoader\CiteDataModule
* @covers \Cite\ResourceLoader\CiteVisualEditorModule
*
* @license GPL-2.0-or-later
*/
class CiteDataModuleTest extends \MediaWikiUnitTestCase {
protected function setUp(): void {
global $wgRequest;
parent::setUp();
$wgRequest = $this->createMock( WebRequest::class );
}
public function testGetScript() {
$module = new CiteDataModule();
$module = new CiteVisualEditorModule();
$context = $this->createResourceLoaderContext();
$this->assertSame(
've.init.platform.addMessages({"cite-tool-definition.json":' .
'"[{\"name\":\"n\",\"title\":\"t\"}]"});',
$module->getScript( $context )
$module->makePrependedScript( $context )
);
}
public function testGetDependencies() {
$module = new CiteDataModule();
$this->assertContainsOnly( 'string', $module->getDependencies() );
}
public function testGetDefinitionSummary() {
$module = new CiteDataModule();
$module = new CiteVisualEditorModule();
$context = $this->createResourceLoaderContext();
$summary = $module->getDefinitionSummary( $context );
$this->assertSame(
$module->getScript( $context ),
$module->getDefinitionSummary( $context )[0]['script']
$this->assertStringContainsString(
'{\"name\":\"n\",\"title\":\"t\"}]"}',
array_pop( $summary )['script']
);
}
@ -53,19 +40,19 @@ class CiteDataModuleTest extends \MediaWikiUnitTestCase {
$msg->method( 'inContentLanguage' )
->willReturnSelf();
$msg->method( 'plain' )
->willReturnOnConsecutiveCalls( '', '[{"name":"n"}]', '[{"name":"n","title":"t"}]' );
->willReturnOnConsecutiveCalls( '', '[{"name":"n"}]' );
$msg->method( 'text' )
->willReturn( 't' );
$context = $this->createMock( ResourceLoaderContext::class );
$context = $this->createStub( ResourceLoaderContext::class );
$context->method( 'msg' )
->withConsecutive(
[ 'cite-tool-definition.json' ],
[ 'visualeditor-cite-tool-definition.json' ],
[ 'visualeditor-cite-tool-name-n' ],
[ 'cite-tool-definition.json' ]
[ 'visualeditor-cite-tool-name-n' ]
)
->willReturn( $msg );
$context->method( 'encodeJson' )->willReturnCallback( 'json_encode' );
return $context;
}