mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Cite
synced 2024-12-04 03:18:19 +00:00
d0cb639e03
We are *so* close to 90%. This patch should raise the coverage for the CiteDataModule to 100%. I'm also adding a pure unit test for the clone() behavior. Note the later is already covered by the CiteDbTest. Question: Do we want the CiteDbTest to @cover anything? Change-Id: I40763d01e18991f509bc30b6655aa57b23412fd9
76 lines
1.8 KiB
PHP
76 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace Cite\Tests\Unit;
|
|
|
|
use Cite\ResourceLoader\CiteDataModule;
|
|
use Message;
|
|
use ResourceLoaderContext;
|
|
use WebRequest;
|
|
|
|
/**
|
|
* @covers \Cite\ResourceLoader\CiteDataModule
|
|
*
|
|
* @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();
|
|
$context = $this->createResourceLoaderContext();
|
|
|
|
$this->assertSame(
|
|
've.init.platform.addMessages({"cite-tool-definition.json":' .
|
|
'"[{\"name\":\"n\",\"title\":\"t\"}]"});',
|
|
$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' )
|
|
->willReturnOnConsecutiveCalls( '', '[{"name":"n"}]', '[{"name":"n","title":"t"}]' );
|
|
$msg->method( 'text' )
|
|
->willReturn( 't' );
|
|
|
|
$context = $this->createMock( ResourceLoaderContext::class );
|
|
$context->method( 'msg' )
|
|
->withConsecutive(
|
|
[ 'cite-tool-definition.json' ],
|
|
[ 'visualeditor-cite-tool-definition.json' ],
|
|
[ 'visualeditor-cite-tool-name-n' ],
|
|
[ 'cite-tool-definition.json' ]
|
|
)
|
|
->willReturn( $msg );
|
|
return $context;
|
|
}
|
|
|
|
}
|