mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Gadgets
synced 2024-11-27 16:50:00 +00:00
de999997e7
Bug: T363770 Change-Id: I6c7967ef092513b1a57bacc4d68b9ee3a50822e8
39 lines
1.1 KiB
PHP
39 lines
1.1 KiB
PHP
<?php
|
|
|
|
use MediaWiki\Extension\Gadgets\Gadget;
|
|
use MediaWiki\Extension\Gadgets\GadgetResourceLoaderModule;
|
|
use MediaWiki\Extension\Gadgets\MediaWikiGadgetsDefinitionRepo;
|
|
use MediaWiki\Revision\RevisionLookup;
|
|
use Wikimedia\Rdbms\IConnectionProvider;
|
|
use Wikimedia\TestingAccessWrapper;
|
|
|
|
/**
|
|
* Utility functions for testing gadgets.
|
|
*
|
|
* This trait is intended to be used on subclasses of MediaWikiUnitTestCase
|
|
* or MediaWikiIntegrationTestCase.
|
|
*/
|
|
trait GadgetTestTrait {
|
|
/**
|
|
* @param string $line
|
|
* @return Gadget
|
|
*/
|
|
public function makeGadget( string $line ) {
|
|
$dbProvider = $this->createMock( IConnectionProvider::class );
|
|
$wanCache = WANObjectCache::newEmpty();
|
|
$revLookup = $this->createMock( RevisionLookup::class );
|
|
$srvCache = new HashBagOStuff();
|
|
$repo = new MediaWikiGadgetsDefinitionRepo( $dbProvider, $wanCache, $revLookup, $srvCache );
|
|
return $repo->newFromDefinition( $line, 'misc' );
|
|
}
|
|
|
|
public function makeGadgetModule( Gadget $g ) {
|
|
$module = TestingAccessWrapper::newFromObject(
|
|
new GadgetResourceLoaderModule( [ 'id' => null ] )
|
|
);
|
|
$module->gadget = $g;
|
|
return $module;
|
|
}
|
|
|
|
}
|