mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Cite
synced 2024-12-03 19:16:09 +00:00
f0d7406811
Includes a test and some improvements to the CiteHooks tests. Change-Id: I0e9108d0d429ed9b7467f993441eefc2557c8e6f
78 lines
2.1 KiB
PHP
78 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace Cite\Tests;
|
|
|
|
use ApiQuerySiteinfo;
|
|
use Cite\Hooks\CiteHooks;
|
|
use MediaWiki\Config\HashConfig;
|
|
use MediaWiki\ResourceLoader\ResourceLoader;
|
|
use MediaWiki\User\Options\StaticUserOptionsLookup;
|
|
|
|
/**
|
|
* @covers \Cite\Hooks\CiteHooks
|
|
* @license GPL-2.0-or-later
|
|
*/
|
|
class CiteHooksTest extends \MediaWikiIntegrationTestCase {
|
|
|
|
/**
|
|
* @dataProvider provideBooleans
|
|
*/
|
|
public function testOnResourceLoaderGetConfigVars( bool $enabled ) {
|
|
$vars = [];
|
|
|
|
$config = new HashConfig( [
|
|
'CiteVisualEditorOtherGroup' => $enabled,
|
|
'CiteResponsiveReferences' => $enabled,
|
|
'CiteBookReferencing' => $enabled,
|
|
] );
|
|
|
|
$citeHooks = new CiteHooks( new StaticUserOptionsLookup( [] ) );
|
|
$citeHooks->onResourceLoaderGetConfigVars( $vars, 'vector', $config );
|
|
|
|
$this->assertSame( [
|
|
'wgCiteVisualEditorOtherGroup' => $enabled,
|
|
'wgCiteResponsiveReferences' => $enabled,
|
|
'wgCiteBookReferencing' => $enabled,
|
|
], $vars );
|
|
}
|
|
|
|
/**
|
|
* @dataProvider provideBooleans
|
|
*/
|
|
public function testOnResourceLoaderRegisterModules( bool $enabled ) {
|
|
$this->markTestSkippedIfExtensionNotLoaded( 'Popups' );
|
|
|
|
$resourceLoader = $this->createMock( ResourceLoader::class );
|
|
$resourceLoader->method( 'getConfig' )
|
|
->willReturn( new HashConfig( [ 'CiteReferencePreviews' => $enabled ] ) );
|
|
$resourceLoader->expects( $this->exactly( (int)$enabled ) )
|
|
->method( 'register' );
|
|
|
|
$citeHooks = new CiteHooks( new StaticUserOptionsLookup( [] ) );
|
|
$citeHooks->onResourceLoaderRegisterModules( $resourceLoader );
|
|
}
|
|
|
|
/**
|
|
* @dataProvider provideBooleans
|
|
*/
|
|
public function testOnAPIQuerySiteInfoGeneralInfo( bool $enabled ) {
|
|
$api = $this->createMock( ApiQuerySiteinfo::class );
|
|
$api->expects( $this->once() )
|
|
->method( 'getConfig' )
|
|
->willReturn( new HashConfig( [ 'CiteResponsiveReferences' => $enabled ] ) );
|
|
|
|
$data = [];
|
|
|
|
$citeHooks = new CiteHooks( new StaticUserOptionsLookup( [] ) );
|
|
$citeHooks->onAPIQuerySiteInfoGeneralInfo( $api, $data );
|
|
|
|
$this->assertSame( [ 'citeresponsivereferences' => $enabled ], $data );
|
|
}
|
|
|
|
public static function provideBooleans() {
|
|
yield [ true ];
|
|
yield [ false ];
|
|
}
|
|
|
|
}
|