2019-11-12 15:08:44 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Cite\Tests\Unit;
|
|
|
|
|
2023-05-05 05:50:22 +00:00
|
|
|
use Cite\ResourceLoader\CitationToolDefinition;
|
2022-05-20 02:11:31 +00:00
|
|
|
use MediaWiki\ResourceLoader\Context;
|
2019-11-12 15:08:44 +00:00
|
|
|
use Message;
|
|
|
|
|
|
|
|
/**
|
2023-05-05 05:50:22 +00:00
|
|
|
* @covers \Cite\ResourceLoader\CitationToolDefinition
|
2019-11-19 10:31:08 +00:00
|
|
|
* @license GPL-2.0-or-later
|
2019-11-12 15:08:44 +00:00
|
|
|
*/
|
2023-05-05 05:50:22 +00:00
|
|
|
class CitationToolDefinitionTest extends \MediaWikiUnitTestCase {
|
2019-11-12 15:08:44 +00:00
|
|
|
|
|
|
|
public function testGetScript() {
|
|
|
|
$context = $this->createResourceLoaderContext();
|
|
|
|
|
2024-03-06 12:59:51 +00:00
|
|
|
$expected = [
|
|
|
|
[ 'name' => 'no-message', 'title' => 'Hard-coded title' ],
|
|
|
|
[ 'name' => 'missing-message', 'title' => 'missing-message' ],
|
|
|
|
[ 'name' => 'n', 'title' => 't' ],
|
|
|
|
];
|
2019-11-12 15:08:44 +00:00
|
|
|
$this->assertSame(
|
2024-03-06 12:59:51 +00:00
|
|
|
've.ui.mwCitationTools = ' . json_encode( $expected ) . ';',
|
2023-05-05 05:50:22 +00:00
|
|
|
CitationToolDefinition::makeScript( $context )
|
2019-11-12 15:08:44 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-05-20 02:11:31 +00:00
|
|
|
private function createResourceLoaderContext(): Context {
|
2024-03-06 12:59:51 +00:00
|
|
|
$definition = [
|
|
|
|
// We expect broken and incomplete entries to be skipped
|
|
|
|
[],
|
|
|
|
[ 'name' => '' ],
|
|
|
|
|
|
|
|
[ 'name' => 'no-message', 'title' => 'Hard-coded title' ],
|
|
|
|
[ 'name' => 'missing-message' ],
|
|
|
|
[ 'name' => 'n' ],
|
|
|
|
];
|
|
|
|
|
2019-11-12 15:08:44 +00:00
|
|
|
$msg = $this->createMock( Message::class );
|
|
|
|
$msg->method( 'inContentLanguage' )
|
|
|
|
->willReturnSelf();
|
|
|
|
$msg->method( 'plain' )
|
2024-03-06 12:59:51 +00:00
|
|
|
->willReturn( json_encode( $definition ) );
|
2019-12-11 11:19:18 +00:00
|
|
|
$msg->method( 'text' )
|
|
|
|
->willReturn( 't' );
|
2019-11-12 15:08:44 +00:00
|
|
|
|
2024-03-06 12:59:51 +00:00
|
|
|
$disabled = $this->createMock( Message::class );
|
|
|
|
$disabled->method( 'isDisabled' )->willReturn( true );
|
|
|
|
|
2022-05-20 02:11:31 +00:00
|
|
|
$context = $this->createStub( Context::class );
|
2019-11-12 15:08:44 +00:00
|
|
|
$context->method( 'msg' )
|
2023-11-21 23:15:20 +00:00
|
|
|
->willReturnMap( [
|
|
|
|
[ 'cite-tool-definition.json', $msg ],
|
|
|
|
[ 'visualeditor-cite-tool-definition.json', $msg ],
|
2024-03-06 12:59:51 +00:00
|
|
|
[ 'visualeditor-cite-tool-name-missing-message', $disabled ],
|
2023-11-21 23:15:20 +00:00
|
|
|
[ 'visualeditor-cite-tool-name-n', $msg ]
|
|
|
|
] );
|
2021-11-10 20:36:35 +00:00
|
|
|
$context->method( 'encodeJson' )->willReturnCallback( 'json_encode' );
|
2019-11-12 15:08:44 +00:00
|
|
|
return $context;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|