mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Cite
synced 2024-12-11 06:36:17 +00:00
7157c7f494
Note this codebase appears to be dual-licensed. Some files mention MIT, but extension.json and some other files mention GPL. Since WMDE typically uses GPL, I will continue to mark the files we created as such. Change-Id: I126da10f7fb13a6d4c99e96e72d024b2e5ecee06
90 lines
2.2 KiB
PHP
90 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace Cite\Tests\Unit;
|
|
|
|
use Cite;
|
|
use CiteHooks;
|
|
use HashConfig;
|
|
use LinksUpdate;
|
|
use ParserOutput;
|
|
use ResourceLoader;
|
|
use Title;
|
|
|
|
/**
|
|
* @coversDefaultClass \CiteHooks
|
|
*
|
|
* @license GPL-2.0-or-later
|
|
*/
|
|
class CiteHooksTest extends \MediaWikiUnitTestCase {
|
|
|
|
protected function setUp() : void {
|
|
global $wgCiteStoreReferencesData;
|
|
|
|
parent::setUp();
|
|
$wgCiteStoreReferencesData = true;
|
|
}
|
|
|
|
/**
|
|
* @covers ::onContentHandlerDefaultModelFor
|
|
*/
|
|
public function testOnContentHandlerDefaultModelFor() {
|
|
$title = $this->createMock( Title::class );
|
|
$title->method( 'inNamespace' )
|
|
->willReturn( true );
|
|
$title->method( 'getText' )
|
|
->willReturn( 'Cite-tool-definition.json' );
|
|
|
|
CiteHooks::onContentHandlerDefaultModelFor( $title, $model );
|
|
|
|
$this->assertSame( CONTENT_MODEL_JSON, $model );
|
|
}
|
|
|
|
/**
|
|
* @covers ::onResourceLoaderTestModules
|
|
*/
|
|
public function testOnResourceLoaderTestModules() {
|
|
$testModules = [];
|
|
$resourceLoader = $this->createMock( ResourceLoader::class );
|
|
$resourceLoader->method( 'getConfig' )
|
|
->willReturn( new HashConfig( [
|
|
'ResourceModules' => [ 'ext.visualEditor.mediawiki' => true ],
|
|
] ) );
|
|
|
|
CiteHooks::onResourceLoaderTestModules( $testModules, $resourceLoader );
|
|
|
|
$this->assertArrayHasKey( 'ext.cite.visualEditor.test', $testModules['qunit'] );
|
|
}
|
|
|
|
/**
|
|
* @covers ::onResourceLoaderRegisterModules
|
|
*/
|
|
public function testOnResourceLoaderRegisterModules() {
|
|
$resourceLoader = $this->createMock( ResourceLoader::class );
|
|
$resourceLoader->expects( $this->atLeastOnce() )
|
|
->method( 'register' );
|
|
|
|
CiteHooks::onResourceLoaderRegisterModules( $resourceLoader );
|
|
}
|
|
|
|
/**
|
|
* @covers ::onLinksUpdate
|
|
*/
|
|
public function testOnLinksUpdate() {
|
|
$parserOutput = $this->createMock( ParserOutput::class );
|
|
$parserOutput->method( 'getExtensionData' )
|
|
->willReturn( true );
|
|
$parserOutput->expects( $this->once() )
|
|
->method( 'setExtensionData' )
|
|
->with( Cite::EXT_DATA_KEY, null );
|
|
|
|
$linksUpdate = $this->createMock( LinksUpdate::class );
|
|
$linksUpdate->method( 'getParserOutput' )
|
|
->willReturn( $parserOutput );
|
|
|
|
CiteHooks::onLinksUpdate( $linksUpdate );
|
|
|
|
$this->assertArrayHasKey( 'references-1', $linksUpdate->mProperties );
|
|
}
|
|
|
|
}
|