Commit c1ca6224 authored by alexpott's avatar alexpott

Issue #2245449 by lostkangaroo, chx, Xano: Added a ModuleHandler::getModule().

parent 43324d17
......@@ -148,6 +148,16 @@ public function getModuleList() {
return $this->moduleList;
}
/**
* {@inheritdoc}
*/
public function getModule($name) {
if (isset($this->moduleList[$name])) {
return $this->moduleList[$name];
}
throw new \InvalidArgumentException(sprintf('The module %s does not exist.', $name));
}
/**
* {@inheritdoc}
*/
......
......@@ -57,6 +57,20 @@ public function reload();
*/
public function getModuleList();
/**
* Returns a module extension object from the currently active modules list.
*
* @param string $name
* The name of the module to return.
*
* @return \Drupal\Core\Extension\Extension
* An extension object.
*
* @throws \InvalidArgumentException
* Thrown when the requested module does not exist.
*/
public function getModule($name);
/**
* Sets an explicit list of currently active modules.
*
......
......@@ -49,6 +49,8 @@ public static function getInfo() {
/**
* {@inheritdoc}
*
* @covers ::__construct
*/
protected function setUp() {
$this->cacheBackend = $this->getMock('Drupal\Core\Cache\CacheBackendInterface');
......@@ -151,6 +153,24 @@ public function testGetModuleList() {
));
}
/**
* Confirm we get back a module from the module list
*
* @covers ::getModule
*/
public function testGetModuleWithExistingModule() {
$this->assertEquals($this->moduleHandler->getModule('module_handler_test'), new Extension('module', 'core/tests/Drupal/Tests/Core/Extension/modules/module_handler_test/module_handler_test.info.yml', 'module_handler_test.module'));
}
/**
* @covers ::getModule
*
* @expectedException \InvalidArgumentException
*/
public function testGetModuleWithNonExistingModule() {
$this->moduleHandler->getModule('claire_alice_watch_my_little_pony_module_that_does_not_exist');
}
/**
* Ensure setting the module list replaces the module list and resets internal structures.
*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment