function KernelTestBase::enableModules

Same name in this branch
  1. 8.9.x core/tests/Drupal/KernelTests/KernelTestBase.php \Drupal\KernelTests\KernelTestBase::enableModules()
Same name in other branches
  1. 9 core/tests/Drupal/KernelTests/KernelTestBase.php \Drupal\KernelTests\KernelTestBase::enableModules()
  2. 10 core/tests/Drupal/KernelTests/KernelTestBase.php \Drupal\KernelTests\KernelTestBase::enableModules()
  3. 11.x core/tests/Drupal/KernelTests/KernelTestBase.php \Drupal\KernelTests\KernelTestBase::enableModules()

Enables modules for this test.

To install test modules outside of the testing environment, add

$settings['extension_discovery_scan_tests'] = TRUE;

to your settings.php.

Parameters

array $modules: A list of modules to enable. Dependencies are not resolved; i.e., multiple modules have to be specified with dependent modules first. The new modules are only added to the active module list and loaded.

9 calls to KernelTestBase::enableModules()
EntityUnitTestBase::installModule in core/modules/system/src/Tests/Entity/EntityUnitTestBase.php
Installs a module and refreshes services.
KernelTestBase::setUp in core/modules/simpletest/src/KernelTestBase.php
Performs setup tasks before each individual test method is run.
KernelTestBaseTest::testEnableModulesFixedList in core/modules/simpletest/src/Tests/KernelTestBaseTest.php
Tests that the module list is retained after enabling/installing/disabling.
KernelTestBaseTest::testEnableModulesInstallContainer in core/modules/simpletest/src/Tests/KernelTestBaseTest.php
Tests installing modules with DependencyInjection services.
KernelTestBaseTest::testEnableModulesLoad in core/modules/simpletest/src/Tests/KernelTestBaseTest.php
Tests expected load behavior of enableModules().

... See full list

File

core/modules/simpletest/src/KernelTestBase.php, line 542

Class

KernelTestBase
Base class for functional integration tests.

Namespace

Drupal\simpletest

Code

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(\Drupal::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 = \Drupal::service('config.storage');
    $extensions = $active_storage->read('core.extension');
    foreach ($modules as $module) {
        $module_handler->addModule($module, $module_list[$module]->getPath());
        // Maintain the list of enabled modules in configuration.
        $extensions['module'][$module] = 0;
    }
    $active_storage->write('core.extension', $extensions);
    // Update the kernel to make their services available.
    $module_filenames = $module_handler->getModuleList();
    $this->kernel
        ->updateModules($module_filenames, $module_filenames);
    // 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.
    $this->container
        ->get('module_handler')
        ->reload();
    $this->pass(new FormattableMarkup('Enabled modules: %modules.', [
        '%modules' => implode(', ', $modules),
    ]));
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.