mediawiki-extensions-Gadgets/tests/phpunit/GadgetTestTrait.php
Siddharth VP ce486be160 Further expand test coverage
* Separate out tests for MediaWikiGadgetsDefinitionRepo and
Hooks::onGetPreferences. Removed hack in fetchStructuredList() for
overriding page content for tests.
* Add tests for ES6 gadgets. For this, ResourceLoaderModuleTest is
converted back to an integration test.
* Removed createGadgetDefinitionPage() test helper method. Now using
MediaWikiIntegrationTestCase::editPage().
* Fixed GDNamespaceRepoTest failure when GDNamespaceRepo is the active
repo, by clearing WAN process cache.

Change-Id: I26b84576a91f6cb0ebae64c5fc1408666d767911
2023-12-09 09:29:15 +05:30

35 lines
982 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;
}
}