function KernelTestBase::disableModules

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

Disables modules for this test.

Parameters

array $modules: A list of modules to disable. Dependencies are not resolved; i.e., multiple modules have to be specified with dependent modules first. Code of previously active modules is still loaded. The modules are only removed from the active module list.

2 calls to KernelTestBase::disableModules()
EntityUnitTestBase::uninstallModule in core/modules/system/src/Tests/Entity/EntityUnitTestBase.php
Uninstalls a module and refreshes services.
KernelTestBaseTest::testEnableModulesTheme in core/modules/simpletest/src/Tests/KernelTestBaseTest.php
Tests that ThemeManager works right after loading a module.

File

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

Class

KernelTestBase
Base class for functional integration tests.

Namespace

Drupal\simpletest

Code

protected function disableModules(array $modules) {
    // Unset the list of modules in the extension handler.
    $module_handler = $this->container
        ->get('module_handler');
    $module_filenames = $module_handler->getModuleList();
    $extension_config = $this->config('core.extension');
    foreach ($modules as $module) {
        unset($module_filenames[$module]);
        $extension_config->clear('module.' . $module);
    }
    $extension_config->save();
    $module_handler->setModuleList($module_filenames);
    $module_handler->resetImplementations();
    // Update the kernel to remove their services.
    $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.
    $module_handler = $this->container
        ->get('module_handler');
    $module_handler->reload();
    $this->pass(new FormattableMarkup('Disabled modules: %modules.', [
        '%modules' => implode(', ', $modules),
    ]));
}

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