mediawiki-extensions-Gadgets/includes/StaticGadgetRepo.php
Siddharth VP d12f0f366a Expand test coverage
* 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
2023-12-06 09:18:09 +05:30

32 lines
565 B
PHP

<?php
namespace MediaWiki\Extension\Gadgets;
use InvalidArgumentException;
/**
* @internal For use in tests.
*/
class StaticGadgetRepo extends GadgetRepo {
/**
* @var Gadget[]
*/
private array $gadgets;
public function __construct( array $gadgets ) {
$this->gadgets = $gadgets;
}
public function getGadgetIds(): array {
return array_keys( $this->gadgets );
}
public function getGadget( string $id ): Gadget {
if ( !array_key_exists( $id, $this->gadgets ) ) {
throw new InvalidArgumentException();
}
return $this->gadgets[$id];
}
}