mediawiki-extensions-Cite/tests/phpunit/unit/CiteHooksTest.php

106 lines
2.6 KiB
PHP
Raw Normal View History

<?php
namespace Cite\Test\Unit;
use Cite;
use CiteHooks;
use HashConfig;
use LinksUpdate;
use Parser;
use ParserOutput;
use ResourceLoader;
use Title;
/**
* @coversDefaultClass \CiteHooks
*/
class CiteHooksTest extends \MediaWikiUnitTestCase {
protected function setUp() : void {
global $wgCiteStoreReferencesData;
parent::setUp();
$wgCiteStoreReferencesData = true;
}
/**
* @covers ::onParserFirstCallInit
*/
public function testOnParserFirstCallInit() {
$parser = $this->createMock( Parser::class );
$parser->expects( $this->exactly( 2 ) )
->method( 'setHook' )
->withConsecutive(
[ 'ref', $this->isType( 'callable' ) ],
[ 'references', $this->isType( 'callable' ) ]
);
CiteHooks::onParserFirstCallInit( $parser );
$this->assertInstanceOf( Cite::class, $parser->extCite );
}
/**
* @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 );
}
}