function KernelTestBase::disableModules

Same name in other branches
  1. 9 core/tests/Drupal/KernelTests/KernelTestBase.php \Drupal\KernelTests\KernelTestBase::disableModules()
  2. 8.9.x core/modules/simpletest/src/KernelTestBase.php \Drupal\simpletest\KernelTestBase::disableModules()
  3. 8.9.x core/tests/Drupal/KernelTests/KernelTestBase.php \Drupal\KernelTests\KernelTestBase::disableModules()
  4. 11.x core/tests/Drupal/KernelTests/KernelTestBase.php \Drupal\KernelTests\KernelTestBase::disableModules()

Disables modules for this test.

Parameters

string[] $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 enabled modules is still loaded. The modules are only removed from the active module list.

Throws

\LogicException If any module in $modules is already disabled.

\RuntimeException If a module is not disabled after disabling it.

6 calls to KernelTestBase::disableModules()
EntityDefaultLanguageTest::testEntityTranslationDefaultLanguageViaCode in core/modules/language/tests/src/Kernel/EntityDefaultLanguageTest.php
Tests that default language code is properly set for new nodes.
EntityDisplayTest::testComponentDependencies in core/modules/field_ui/tests/src/Kernel/EntityDisplayTest.php
Tests components dependencies additions.
EntityKernelTestBase::uninstallModule in core/tests/Drupal/KernelTests/Core/Entity/EntityKernelTestBase.php
Uninstalls a module and refreshes services.
MigrationPluginListTest::testGetDefinitions in core/modules/migrate/tests/src/Kernel/Plugin/MigrationPluginListTest.php
@covers ::getDefinitions
RecipeTest::testImplicitlyRequiredModule in core/tests/Drupal/KernelTests/Core/Recipe/RecipeTest.php

... See full list

File

core/tests/Drupal/KernelTests/KernelTestBase.php, line 919

Class

KernelTestBase
Base class for functional integration tests.

Namespace

Drupal\KernelTests

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) {
        if (!$module_handler->moduleExists($module)) {
            throw new \LogicException("{$module} module cannot be uninstalled because it is not installed.");
        }
        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->container
        ->get('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();
    foreach ($modules as $module) {
        if ($module_handler->moduleExists($module)) {
            throw new \RuntimeException("{$module} module is not uninstalled after uninstalling it.");
        }
    }
}

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