function KernelTestBase::enableModules
Same name in other branches
- 8.9.x core/modules/simpletest/src/KernelTestBase.php \Drupal\simpletest\KernelTestBase::enableModules()
- 8.9.x core/tests/Drupal/KernelTests/KernelTestBase.php \Drupal\KernelTests\KernelTestBase::enableModules()
- 10 core/tests/Drupal/KernelTests/KernelTestBase.php \Drupal\KernelTests\KernelTestBase::enableModules()
- 11.x core/tests/Drupal/KernelTests/KernelTestBase.php \Drupal\KernelTests\KernelTestBase::enableModules()
Enables modules for this test.
This method does not install modules fully. Services and hooks for the module are available, but the install process is not performed.
To install test modules outside of the testing environment, add
$settings['extension_discovery_scan_tests'] = TRUE;
to your settings.php.
Parameters
string[] $modules: A list of modules to enable. Dependencies are not resolved; i.e., multiple modules have to be specified individually. The modules are only added to the active module list and loaded; i.e., their database schema is not installed. hook_install() is not invoked. A custom module weight is not applied.
Throws
\LogicException If any module in $modules is already enabled.
\RuntimeException If a module is not enabled after enabling it.
87 calls to KernelTestBase::enableModules()
- CacheableMetadataCalculationTest::testCacheableMetadataCalculation in core/
modules/ views/ tests/ src/ Kernel/ CacheableMetadataCalculationTest.php - Tests that cacheability metadata is only calculated when needed.
- CKEditor4to5UpgradeCompletenessTest::testButtonsWithTestOnlyModule in core/
modules/ ckeditor5/ tests/ src/ Kernel/ CKEditor4to5UpgradeCompletenessTest.php - Tests that the test-only CKEditor 4 module does not have an upgrade path.
- CKEditor4to5UpgradeCompletenessTest::testLyingUpgradePluginForCKEditor4Button in core/
modules/ ckeditor5/ tests/ src/ Kernel/ CKEditor4to5UpgradeCompletenessTest.php - Tests detecting a lying upgrade plugin cke4_button annotation.
- CKEditor4to5UpgradeCompletenessTest::testLyingUpgradePluginForCKEditor4PluginSettings in core/
modules/ ckeditor5/ tests/ src/ Kernel/ CKEditor4to5UpgradeCompletenessTest.php - Tests detecting a lying upgrade plugin cke4_plugin_settings annotation.
- CKEditor4to5UpgradeCompletenessTest::testLyingUpgradePluginForCKEditor5ConfigurableSubsetPlugin in core/
modules/ ckeditor5/ tests/ src/ Kernel/ CKEditor4to5UpgradeCompletenessTest.php - Tests detecting lying cke5_plugin_elements_subset_configuration annotation.
File
-
core/
tests/ Drupal/ KernelTests/ KernelTestBase.php, line 812
Class
- KernelTestBase
- Base class for functional integration tests.
Namespace
Drupal\KernelTestsCode
protected function enableModules(array $modules) {
// Perform an ExtensionDiscovery scan as this function may receive a
// profile that is not the current profile, and we don't yet have a cached
// way to receive inactive profile information.
// @todo Remove as part of https://www.drupal.org/node/2186491
$listing = new ExtensionDiscovery($this->root);
$module_list = $listing->scan('module');
// In ModuleHandlerTest we pass in a profile as if it were a module.
$module_list += $listing->scan('profile');
// Set the list of modules in the extension handler.
$module_handler = $this->container
->get('module_handler');
// Write directly to active storage to avoid early instantiation of
// the event dispatcher which can prevent modules from registering events.
$active_storage = $this->container
->get('config.storage');
$extension_config = $active_storage->read('core.extension');
foreach ($modules as $module) {
if ($module_handler->moduleExists($module)) {
continue;
}
$module_handler->addModule($module, $module_list[$module]->getPath());
// Maintain the list of enabled modules in configuration.
$extension_config['module'][$module] = 0;
}
$active_storage->write('core.extension', $extension_config);
// Update the kernel to make their services available.
$extensions = $module_handler->getModuleList();
$this->container
->get('kernel')
->updateModules($extensions, $extensions);
// Ensure isLoaded() is TRUE in order to make
// \Drupal\Core\Theme\ThemeManagerInterface::render() work.
// Note that the kernel has rebuilt the container; this $module_handler is
// no longer the $module_handler instance from above.
$module_handler = $this->container
->get('module_handler');
$module_handler->reload();
foreach ($modules as $module) {
if (!$module_handler->moduleExists($module)) {
throw new \RuntimeException("{$module} module is not enabled after enabling it.");
}
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.