mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Cite
synced 2024-12-01 10:06:15 +00:00
013e1bfa90
* Always have an empty line between @param and @return to improve readability as well as consistency within this codebase (before, both styles have been used). * Flip parameter order in validateRefInReferences() for consistency with the rest of the code. * In Cite::guardedRef() the Parser was now the 1st parameter. I changed all related functions the same way to make the code less surprising. * Same in CiteUnitTest. This is really just the @dataProvider. But I feel it's still helpful to have the arguments in the same order everywhere, if possible. * Add a few strict type hints. * It seems the preferred style for PHP7 return types is `… ) : string {` with a space before the `:`. There is currently no PHPCS sniff for this. However, I think this codebase should be consistent, one way or the other. Change-Id: I91d232be727afd26ff20526ab4ef63aa5ba6bacf
73 lines
1.8 KiB
PHP
73 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']
|
|
);
|
|
}
|
|
|
|
private function createResourceLoaderContext() : ResourceLoaderContext {
|
|
$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;
|
|
}
|
|
|
|
}
|