mediawiki-extensions-Cite/tests/phpunit/CiteHooksTest.php
Thiemo Kreuz ab3063fee5 Move all code to PSR-4 compatible namespaces
This patch does intentionally not touch any file name. Some of the
file names are a little weird now, e.g. \Cite\Cite. These can more
easily be renamed in later patches.

I used https://codesearch.wmflabs.org/search/?q=new%20Cite%5C( and it
looks like this code is not used anywhere else.

Change-Id: I5f93a224e9cacf45b7a0d68c216a78723364dd96
2019-11-20 17:00:13 +01:00

82 lines
2 KiB
PHP

<?php
namespace Cite\Tests;
use ApiQuerySiteinfo;
use Cite\Hooks\CiteHooks;
use HashBagOStuff;
use LinksUpdate;
use Title;
use WANObjectCache;
/**
* @coversDefaultClass \Cite\Hooks\CiteHooks
*
* @license GPL-2.0-or-later
*/
class CiteHooksTest extends \MediaWikiIntegrationTestCase {
protected function setUp() : void {
parent::setUp();
$this->setMwGlobals( [
'wgCiteStoreReferencesData' => true,
] );
}
/**
* @covers ::onLinksUpdateComplete
*/
public function testOnLinksUpdateComplete() {
$cache = $this->getMockBuilder( WANObjectCache::class )
->setConstructorArgs( [ [ 'cache' => new HashBagOStuff() ] ] )
->setMethods( [ 'makeKey', 'relayPurge' ] )
->getMock();
$cache->method( 'makeKey' )
->willReturn( '<KEY>' );
// What we actually want to check here is if WANObjectCache::delete() is called, but it's
// final and can't be mocked.
$cache->expects( $this->once() )
->method( 'relayPurge' )
->with(
'WANCache:v:<KEY>',
WANObjectCache::MAX_COMMIT_DELAY,
WANObjectCache::HOLDOFF_TTL_NONE
);
$this->setService( 'MainWANObjectCache', $cache );
$linksUpdate = $this->createMock( LinksUpdate::class );
$linksUpdate->method( 'getAddedProperties' )
->willReturn( [ 'references-1' => true ] );
$linksUpdate->method( 'getTitle' )
->willReturn( $this->createMock( Title::class ) );
CiteHooks::onLinksUpdateComplete( $linksUpdate );
}
/**
* @covers ::onResourceLoaderGetConfigVars
*/
public function testOnResourceLoaderGetConfigVars() {
$vars = [];
CiteHooks::onResourceLoaderGetConfigVars( $vars );
$this->assertArrayHasKey( 'wgCiteVisualEditorOtherGroup', $vars );
$this->assertArrayHasKey( 'wgCiteResponsiveReferences', $vars );
}
/**
* @covers ::onAPIQuerySiteInfoGeneralInfo
*/
public function testOnAPIQuerySiteInfoGeneralInfo() {
$api = $this->createMock( ApiQuerySiteinfo::class );
$data = [];
CiteHooks::onAPIQuerySiteInfoGeneralInfo( $api, $data );
$this->assertArrayHasKey( 'citeresponsivereferences', $data );
}
}