You are here

protected function KernelTestBase::enableModules in SimpleTest 8.3

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.

8 calls to KernelTestBase::enableModules()
KernelTestBase::setUp in src/KernelTestBase.php
Performs setup tasks before each individual test method is run.
KernelTestBaseTest::testEnableModulesFixedList in src/Tests/KernelTestBaseTest.php
Tests that the module list is retained after enabling/installing/disabling.
KernelTestBaseTest::testEnableModulesInstallContainer in src/Tests/KernelTestBaseTest.php
Tests installing modules with DependencyInjection services.
KernelTestBaseTest::testEnableModulesLoad in src/Tests/KernelTestBaseTest.php
Tests expected load behavior of enableModules().
KernelTestBaseTest::testEnableModulesTheme in src/Tests/KernelTestBaseTest.php
Tests that ThemeManager works right after loading a module.

... See full list

File

src/KernelTestBase.php, line 536

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),
  ]));
}