2022-08-16 15:24:01 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
use MediaWiki\Extension\Gadgets\Gadget;
|
|
|
|
use MediaWiki\Extension\Gadgets\GadgetResourceLoaderModule;
|
|
|
|
use MediaWiki\Extension\Gadgets\MediaWikiGadgetsDefinitionRepo;
|
|
|
|
use MediaWiki\Revision\RevisionLookup;
|
2024-10-19 23:15:50 +00:00
|
|
|
use Wikimedia\ObjectCache\HashBagOStuff;
|
|
|
|
use Wikimedia\ObjectCache\WANObjectCache;
|
2024-02-25 02:49:56 +00:00
|
|
|
use Wikimedia\Rdbms\IConnectionProvider;
|
2022-08-16 15:24:01 +00:00
|
|
|
use Wikimedia\TestingAccessWrapper;
|
|
|
|
|
|
|
|
/**
|
2024-02-13 13:44:09 +00:00
|
|
|
* Utility functions for testing gadgets.
|
|
|
|
*
|
2022-08-16 15:24:01 +00:00
|
|
|
* 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 ) {
|
2024-02-25 02:49:56 +00:00
|
|
|
$dbProvider = $this->createMock( IConnectionProvider::class );
|
2022-08-16 15:24:01 +00:00
|
|
|
$wanCache = WANObjectCache::newEmpty();
|
|
|
|
$revLookup = $this->createMock( RevisionLookup::class );
|
2024-05-14 15:08:02 +00:00
|
|
|
$srvCache = new HashBagOStuff();
|
|
|
|
$repo = new MediaWikiGadgetsDefinitionRepo( $dbProvider, $wanCache, $revLookup, $srvCache );
|
2022-08-16 15:24:01 +00:00
|
|
|
return $repo->newFromDefinition( $line, 'misc' );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function makeGadgetModule( Gadget $g ) {
|
|
|
|
$module = TestingAccessWrapper::newFromObject(
|
|
|
|
new GadgetResourceLoaderModule( [ 'id' => null ] )
|
|
|
|
);
|
|
|
|
$module->gadget = $g;
|
|
|
|
return $module;
|
|
|
|
}
|
2023-12-06 07:06:06 +00:00
|
|
|
|
2022-08-16 15:24:01 +00:00
|
|
|
}
|