mediawiki-extensions-Gadgets/tests/phpunit/integration/GadgetResourceLoaderModuleTest.php
Reedy 01f6a6c34e Namespace extension
Bug: T278278
Change-Id: I49b57e68079c998419e235b1727eea8c121c234b
2022-03-05 17:03:35 +00:00

47 lines
1.4 KiB
PHP

<?php
use MediaWiki\Extension\Gadgets\Gadget;
use Wikimedia\TestingAccessWrapper;
/**
* @group Gadgets
*/
class GadgetResourceLoaderModuleTest extends MediaWikiIntegrationTestCase {
/**
* @var Gadget
*/
private $gadget;
/**
* @var TestingAccessWrapper
*/
private $gadgetModule;
protected function setUp(): void {
parent::setUp();
$this->gadget = GadgetTestUtils::makeGadget( '*foo [ResourceLoader|package]|foo.js|foo.css|foo.json' );
$this->gadgetModule = GadgetTestUtils::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 = GadgetTestUtils::makeGadget( '*foo [ResourceLoader]|foo.js|foo.css|foo.json' );
$nonPackageGadgetModule = GadgetTestUtils::makeGadgetModule( $nonPackageGadget );
$this->assertArrayNotHasKey( 'MediaWiki:Gadget-foo.json',
$nonPackageGadgetModule->getPages( ResourceLoaderContext::newDummyContext() ) );
}
}