mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Gadgets
synced 2024-12-18 18:00:36 +00:00
d12f0f366a
* Add tests for onBeforePageDisplay hook. A simple gadget repo implementation, StaticGadgetRepo, is introduced for this. * Add integrations tests for various gadget load conditions. * Add test for onUserGetDefaultOptions hook. * Add tests for GadgetDefinitionNamespaceRepo. * Convert ResourceLoaderModuleTest to a unit test. Change-Id: I275380c2bfcaa44770b3946a0a468eaaabef70c0
50 lines
2 KiB
PHP
50 lines
2 KiB
PHP
<?php
|
|
|
|
use MediaWiki\CommentStore\CommentStoreComment;
|
|
use MediaWiki\Extension\Gadgets\Content\GadgetDefinitionContent;
|
|
use MediaWiki\Extension\Gadgets\GadgetDefinitionNamespaceRepo;
|
|
use MediaWiki\Revision\SlotRecord;
|
|
|
|
/**
|
|
* @group Gadgets
|
|
* @group Database
|
|
*/
|
|
class GadgetDefinitionNamespaceRepoTest extends MediaWikiIntegrationTestCase {
|
|
|
|
private function createGadgetDefinitionPage( string $title, string $content ) {
|
|
$services = $this->getServiceContainer();
|
|
$page = $services->getWikiPageFactory()->newFromTitle( Title::newFromText( $title ) );
|
|
$updater = $page->newPageUpdater( $this->getTestUser()->getUser() );
|
|
$updater->setContent( SlotRecord::MAIN, new GadgetDefinitionContent( $content ) );
|
|
$updater->saveRevision( CommentStoreComment::newUnsavedComment( "" ) );
|
|
}
|
|
|
|
/**
|
|
* @covers \MediaWiki\Extension\Gadgets\GadgetDefinitionNamespaceRepo
|
|
*/
|
|
public function testGetGadget() {
|
|
$this->createGadgetDefinitionPage( 'Gadget definition:Test',
|
|
'{"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() {
|
|
$this->createGadgetDefinitionPage( 'Gadget definition:X1',
|
|
'{"module":{"scripts":["Gadget:test.js"]}, "settings":{"default":true}}' );
|
|
$this->createGadgetDefinitionPage( 'Gadget definition:X2',
|
|
'{"module":{"scripts":["Gadget:test.js"]}, "settings":{"default":true}}' );
|
|
|
|
$services = $this->getServiceContainer();
|
|
$repo = new GadgetDefinitionNamespaceRepo( $services->getMainWANObjectCache(), $services->getRevisionLookup() );
|
|
$this->assertArrayEquals( [ 'X1', 'X2' ], $repo->getGadgetIds() );
|
|
}
|
|
}
|