mediawiki-extensions-Gadgets/tests/phpunit/integration/GadgetResourceLoaderModuleTest.php
Siddharth VP 22752225a1 Make GadgetRepo a service
Turn GadgetRepo into a service, deprecate GadgetRepo::singleton()

Change-Id: I0ab14ca936eec1eead91d4eb0970f898628c8388
2023-12-05 17:38:41 -06:00

48 lines
1.4 KiB
PHP

<?php
use MediaWiki\Extension\Gadgets\Gadget;
use Wikimedia\TestingAccessWrapper;
/**
* @group Gadgets
*/
class GadgetResourceLoaderModuleTest extends MediaWikiIntegrationTestCase {
use GadgetTestTrait;
/**
* @var Gadget
*/
private $gadget;
/**
* @var TestingAccessWrapper
*/
private $gadgetModule;
protected function setUp(): void {
parent::setUp();
$this->gadget = $this->makeGadget( '*foo [ResourceLoader|package]|foo.js|foo.css|foo.json' );
$this->gadgetModule = $this->makeGadgetModule( $this->gadget );
}
/**
* @covers \MediaWiki\Extension\Gadgets\GadgetResourceLoaderModule::getPages
*/
public function testGetPages() {
$pages = $this->gadgetModule->getPages( ResourceLoaderContext::newDummyContext() );
$this->assertArrayHasKey( 'MediaWiki:Gadget-foo.css', $pages );
$this->assertArrayHasKey( 'MediaWiki:Gadget-foo.js', $pages );
$this->assertArrayHasKey( 'MediaWiki:Gadget-foo.json', $pages );
$this->assertArrayEquals( $pages, [
[ 'type' => 'style' ],
[ 'type' => 'script' ],
[ 'type' => 'data' ]
] );
$nonPackageGadget = $this->makeGadget( '*foo [ResourceLoader]|foo.js|foo.css|foo.json' );
$nonPackageGadgetModule = $this->makeGadgetModule( $nonPackageGadget );
$this->assertArrayNotHasKey( 'MediaWiki:Gadget-foo.json',
$nonPackageGadgetModule->getPages( ResourceLoaderContext::newDummyContext() ) );
}
}