mediawiki-extensions-Gadgets/tests/phpunit/integration/GadgetDefinitionNamespaceRepoTest.php
Siddharth VP 0c61a5a468 Specify all source pages in a single array in JSON definitions
As this repo is not used anywhere in production, there is no backward
compatibility. Any scripts, styles, datas specified in existing
definition pages will get ignored.

Gadget::getJSON() no longer checks isPackaged() – that is now left
for callers - only relevant one is in GadgetRLModule. That was done
because validationWarnings() method needs the JSON page list even for
non-package gadgets.

Bug: T353174
Change-Id: Ic820bc4632981369c72f822fb8b9b7195930eaa6
2023-12-16 14:31:09 +05:30

41 lines
1.4 KiB
PHP

<?php
use MediaWiki\Extension\Gadgets\GadgetDefinitionNamespaceRepo;
/**
* @group Gadgets
* @group Database
*/
class GadgetDefinitionNamespaceRepoTest extends MediaWikiIntegrationTestCase {
/**
* @covers \MediaWiki\Extension\Gadgets\GadgetDefinitionNamespaceRepo
*/
public function testGetGadget() {
$this->editPage( 'Gadget definition:Test',
'{"module":{"pages":["test.js"]}, "settings":{"default":true}}' );
$services = $this->getServiceContainer();
$repo = new GadgetDefinitionNamespaceRepo( $services->getMainWANObjectCache(), $services->getRevisionLookup() );
$gadget = $repo->getGadget( 'Test' );
$this->assertTrue( $gadget->isOnByDefault() );
$this->assertArrayEquals( [ "Gadget:test.js" ], $gadget->getScripts() );
}
/**
* @covers \MediaWiki\Extension\Gadgets\GadgetDefinitionNamespaceRepo
*/
public function testGetGadgetIds() {
$this->editPage( 'Gadget definition:X1',
'{"module":{"pages":["Gadget:test.js"]}, "settings":{"default":true}}' );
$this->editPage( 'Gadget definition:X2',
'{"module":{"pages":["Gadget:test.js"]}, "settings":{"default":true}}' );
$services = $this->getServiceContainer();
$wanCache = $services->getMainWANObjectCache();
$repo = new GadgetDefinitionNamespaceRepo( $wanCache, $services->getRevisionLookup() );
$wanCache->clearProcessCache();
$this->assertArrayEquals( [ 'X1', 'X2' ], $repo->getGadgetIds() );
}
}