ModuleImplementsAlterTest.php in Zircon Profile 8
File
core/modules/system/src/Tests/Module/ModuleImplementsAlterTest.php
View source
<?php
namespace Drupal\system\Tests\Module;
use Drupal\simpletest\KernelTestBase;
class ModuleImplementsAlterTest extends KernelTestBase {
function testModuleImplementsAlter() {
$module_handler = \Drupal::moduleHandler();
$this
->assertTrue($module_handler === \Drupal::moduleHandler(), 'Module handler instance is still the same.');
\Drupal::service('module_installer')
->install(array(
'module_test',
));
$this
->assertFalse($module_handler === \Drupal::moduleHandler(), 'The \\Drupal::moduleHandler() instance has been replaced during \\Drupal::moduleHandler()->install().');
$this
->assertTrue(function_exists('module_test_modules_installed'), 'The file module_test.module was successfully included.');
$this
->assertTrue(array_key_exists('module_test', \Drupal::moduleHandler()
->getModuleList()), 'module_test is in the module list.');
$this
->assertTrue(in_array('module_test', \Drupal::moduleHandler()
->getImplementations('modules_installed')), 'module_test implements hook_modules_installed().');
$this
->assertTrue(in_array('module_test', \Drupal::moduleHandler()
->getImplementations('module_implements_alter')), 'module_test implements hook_module_implements_alter().');
$this
->assertFalse(function_exists('module_test_altered_test_hook'), 'The file module_test.implementations.inc is not included yet.');
$this
->assertTrue(in_array('module_test', \Drupal::moduleHandler()
->getImplementations('altered_test_hook')), 'module_test implements hook_altered_test_hook().');
$this
->assertTrue(function_exists('module_test_altered_test_hook'), 'The file module_test.implementations.inc was included.');
}
function testModuleImplementsAlterNonExistingImplementation() {
\Drupal::service('module_installer')
->install(array(
'module_test',
));
try {
\Drupal::moduleHandler()
->getImplementations('unimplemented_test_hook');
$this
->fail('An exception should be thrown for the non-existing implementation.');
} catch (\RuntimeException $e) {
$this
->pass('An exception should be thrown for the non-existing implementation.');
$this
->assertEqual($e
->getMessage(), 'An invalid implementation module_test_unimplemented_test_hook was added by hook_module_implements_alter()');
}
}
}