mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Gadgets
synced 2024-12-18 09:50:37 +00:00
22752225a1
Turn GadgetRepo into a service, deprecate GadgetRepo::singleton() Change-Id: I0ab14ca936eec1eead91d4eb0970f898628c8388
34 lines
981 B
PHP
34 lines
981 B
PHP
<?php
|
|
|
|
use MediaWiki\Extension\Gadgets\Gadget;
|
|
use MediaWiki\Extension\Gadgets\GadgetResourceLoaderModule;
|
|
use MediaWiki\Extension\Gadgets\MediaWikiGadgetsDefinitionRepo;
|
|
use MediaWiki\Revision\RevisionLookup;
|
|
use Wikimedia\TestingAccessWrapper;
|
|
|
|
/**
|
|
* A trait providing utility function 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 ) {
|
|
$wanCache = WANObjectCache::newEmpty();
|
|
$revLookup = $this->createMock( RevisionLookup::class );
|
|
$repo = new MediaWikiGadgetsDefinitionRepo( $wanCache, $revLookup );
|
|
return $repo->newFromDefinition( $line, 'misc' );
|
|
}
|
|
|
|
public function makeGadgetModule( Gadget $g ) {
|
|
$module = TestingAccessWrapper::newFromObject(
|
|
new GadgetResourceLoaderModule( [ 'id' => null ] )
|
|
);
|
|
$module->gadget = $g;
|
|
return $module;
|
|
}
|
|
}
|