mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Cite
synced 2024-11-28 00:40:12 +00:00
bb72bc65f5
Extensions using Phan need to be updated simultaneously with core due to T308443. Bug: T308718 Depends-On: Id08a220e1d6085e2b33f3f6c9d0e3935a4204659 Change-Id: Iebc5768a3125ce2b173e9b55fc3ea20616553824
59 lines
1.5 KiB
PHP
59 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace Cite\Tests\Unit;
|
|
|
|
use Cite\ResourceLoader\CiteVisualEditorModule;
|
|
use MediaWiki\ResourceLoader\Context;
|
|
use Message;
|
|
|
|
/**
|
|
* @covers \Cite\ResourceLoader\CiteVisualEditorModule
|
|
*
|
|
* @license GPL-2.0-or-later
|
|
*/
|
|
class CiteDataModuleTest extends \MediaWikiUnitTestCase {
|
|
|
|
public function testGetScript() {
|
|
$module = new CiteVisualEditorModule();
|
|
$context = $this->createResourceLoaderContext();
|
|
|
|
$this->assertSame(
|
|
've.ui.mwCitationTools = [{"name":"n","title":"t"}];',
|
|
$module->makePrependedScript( $context )
|
|
);
|
|
}
|
|
|
|
public function testGetDefinitionSummary() {
|
|
$module = new CiteVisualEditorModule();
|
|
$context = $this->createResourceLoaderContext();
|
|
$summary = $module->getDefinitionSummary( $context );
|
|
|
|
$this->assertStringContainsString(
|
|
'{"name":"n","title":"t"}',
|
|
array_pop( $summary )['script']
|
|
);
|
|
}
|
|
|
|
private function createResourceLoaderContext(): Context {
|
|
$msg = $this->createMock( Message::class );
|
|
$msg->method( 'inContentLanguage' )
|
|
->willReturnSelf();
|
|
$msg->method( 'plain' )
|
|
->willReturnOnConsecutiveCalls( '', '[{"name":"n"}]' );
|
|
$msg->method( 'text' )
|
|
->willReturn( 't' );
|
|
|
|
$context = $this->createStub( Context::class );
|
|
$context->method( 'msg' )
|
|
->withConsecutive(
|
|
[ 'cite-tool-definition.json' ],
|
|
[ 'visualeditor-cite-tool-definition.json' ],
|
|
[ 'visualeditor-cite-tool-name-n' ]
|
|
)
|
|
->willReturn( $msg );
|
|
$context->method( 'encodeJson' )->willReturnCallback( 'json_encode' );
|
|
return $context;
|
|
}
|
|
|
|
}
|