2019-11-12 15:08:44 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Cite\Tests\Unit;
|
|
|
|
|
2019-11-19 14:12:11 +00:00
|
|
|
use Cite\ResourceLoader\CiteDataModule;
|
2019-11-12 15:08:44 +00:00
|
|
|
use Message;
|
|
|
|
use ResourceLoaderContext;
|
|
|
|
use WebRequest;
|
|
|
|
|
|
|
|
/**
|
2019-11-19 14:12:11 +00:00
|
|
|
* @covers \Cite\ResourceLoader\CiteDataModule
|
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 {
|
|
|
|
|
|
|
|
protected function setUp() : void {
|
|
|
|
global $wgRequest;
|
|
|
|
|
|
|
|
parent::setUp();
|
|
|
|
$wgRequest = $this->createMock( WebRequest::class );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetScript() {
|
|
|
|
$module = new CiteDataModule();
|
|
|
|
$context = $this->createResourceLoaderContext();
|
|
|
|
|
|
|
|
$this->assertSame(
|
2019-12-11 11:19:18 +00:00
|
|
|
've.init.platform.addMessages({"cite-tool-definition.json":' .
|
|
|
|
'"[{\"name\":\"n\",\"title\":\"t\"}]"});',
|
2019-11-12 15:08:44 +00:00
|
|
|
$module->getScript( $context )
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetDependencies() {
|
|
|
|
$module = new CiteDataModule();
|
|
|
|
|
|
|
|
$this->assertContainsOnly( 'string', $module->getDependencies() );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetDefinitionSummary() {
|
|
|
|
$module = new CiteDataModule();
|
|
|
|
$context = $this->createResourceLoaderContext();
|
|
|
|
|
|
|
|
$this->assertSame(
|
|
|
|
$module->getScript( $context ),
|
|
|
|
$module->getDefinitionSummary( $context )[0]['script']
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return ResourceLoaderContext
|
|
|
|
*/
|
|
|
|
private function createResourceLoaderContext() {
|
|
|
|
$msg = $this->createMock( Message::class );
|
|
|
|
$msg->method( 'inContentLanguage' )
|
|
|
|
->willReturnSelf();
|
|
|
|
$msg->method( 'plain' )
|
2019-12-11 11:19:18 +00:00
|
|
|
->willReturnOnConsecutiveCalls( '', '[{"name":"n"}]', '[{"name":"n","title":"t"}]' );
|
|
|
|
$msg->method( 'text' )
|
|
|
|
->willReturn( 't' );
|
2019-11-12 15:08:44 +00:00
|
|
|
|
|
|
|
$context = $this->createMock( ResourceLoaderContext::class );
|
|
|
|
$context->method( 'msg' )
|
2019-12-11 11:19:18 +00:00
|
|
|
->withConsecutive(
|
|
|
|
[ 'cite-tool-definition.json' ],
|
|
|
|
[ 'visualeditor-cite-tool-definition.json' ],
|
|
|
|
[ 'visualeditor-cite-tool-name-n' ],
|
|
|
|
[ 'cite-tool-definition.json' ]
|
|
|
|
)
|
2019-11-12 15:08:44 +00:00
|
|
|
->willReturn( $msg );
|
|
|
|
return $context;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|