2023-12-05 18:04:27 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
use MediaWiki\Extension\Gadgets\GadgetDefinitionNamespaceRepo;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @group Gadgets
|
|
|
|
* @group Database
|
|
|
|
*/
|
|
|
|
class GadgetDefinitionNamespaceRepoTest extends MediaWikiIntegrationTestCase {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers \MediaWiki\Extension\Gadgets\GadgetDefinitionNamespaceRepo
|
|
|
|
*/
|
|
|
|
public function testGetGadget() {
|
2023-12-06 07:06:06 +00:00
|
|
|
$this->editPage( 'Gadget definition:Test',
|
2023-12-05 18:04:27 +00:00
|
|
|
'{"module":{"scripts":["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() {
|
2023-12-06 07:06:06 +00:00
|
|
|
$this->editPage( 'Gadget definition:X1',
|
2023-12-05 18:04:27 +00:00
|
|
|
'{"module":{"scripts":["Gadget:test.js"]}, "settings":{"default":true}}' );
|
2023-12-06 07:06:06 +00:00
|
|
|
$this->editPage( 'Gadget definition:X2',
|
2023-12-05 18:04:27 +00:00
|
|
|
'{"module":{"scripts":["Gadget:test.js"]}, "settings":{"default":true}}' );
|
|
|
|
|
|
|
|
$services = $this->getServiceContainer();
|
2023-12-06 07:06:06 +00:00
|
|
|
$wanCache = $services->getMainWANObjectCache();
|
|
|
|
$repo = new GadgetDefinitionNamespaceRepo( $wanCache, $services->getRevisionLookup() );
|
|
|
|
$wanCache->clearProcessCache();
|
2023-12-05 18:04:27 +00:00
|
|
|
$this->assertArrayEquals( [ 'X1', 'X2' ], $repo->getGadgetIds() );
|
|
|
|
}
|
|
|
|
}
|