mediawiki-extensions-Cite/tests/phpunit/unit/CiteDataModuleTest.php
Thiemo Kreuz e68b96f75c Add more basic tests for API and RL modules
Change-Id: I5e54fae041ec8431c170be468c12f0622e355b9b
2019-11-12 16:32:15 +01:00

65 lines
1.4 KiB
PHP

<?php
namespace Cite\Tests\Unit;
use CiteDataModule;
use Message;
use ResourceLoaderContext;
use WebRequest;
/**
* @covers \CiteDataModule
*/
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":"[{\"title\":\"\"}]"});',
$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' )
->willReturn( '[{"title":""}]' );
$context = $this->createMock( ResourceLoaderContext::class );
$context->method( 'msg' )
->willReturn( $msg );
return $context;
}
}