mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Cite
synced 2024-11-28 08:50:07 +00:00
ae01d35bf2
This also updates an existing test to cover all trim() in the code. Change-Id: I0f0b4f8154004f941f4eaa5a9b2c3be0598fb137
80 lines
1.9 KiB
PHP
80 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace Cite\Test;
|
|
|
|
use ApiQuerySiteinfo;
|
|
use CiteHooks;
|
|
use HashBagOStuff;
|
|
use LinksUpdate;
|
|
use Title;
|
|
use WANObjectCache;
|
|
|
|
/**
|
|
* @coversDefaultClass \CiteHooks
|
|
*/
|
|
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 );
|
|
}
|
|
|
|
}
|