mediawiki-extensions-Cite/tests/phpunit/unit/CiteDataModuleTest.php
Thiemo Kreuz d0cb639e03 Minor improvements to the test coverage
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
2019-12-11 12:22:59 +01:00

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;
}
}