function ModuleHandlerTest::testUninstallProfileDependency

Same name in other branches
  1. 9 core/modules/system/tests/src/Kernel/Extension/ModuleHandlerTest.php \Drupal\Tests\system\Kernel\Extension\ModuleHandlerTest::testUninstallProfileDependency()
  2. 10 core/modules/system/tests/src/Kernel/Extension/ModuleHandlerTest.php \Drupal\Tests\system\Kernel\Extension\ModuleHandlerTest::testUninstallProfileDependency()
  3. 11.x core/modules/system/tests/src/Kernel/Extension/ModuleHandlerTest.php \Drupal\Tests\system\Kernel\Extension\ModuleHandlerTest::testUninstallProfileDependency()

Tests uninstalling a module installed by a profile.

File

core/modules/system/tests/src/Kernel/Extension/ModuleHandlerTest.php, line 194

Class

ModuleHandlerTest
Tests ModuleHandler functionality.

Namespace

Drupal\Tests\system\Kernel\Extension

Code

public function testUninstallProfileDependency() {
    $profile = 'testing_install_profile_dependencies';
    $dependency = 'dblog';
    $non_dependency = 'ban';
    $this->setInstallProfile($profile);
    // Prime the drupal_get_filename() static cache with the location of the
    // testing_install_profile_dependencies profile as it is not the currently
    // active profile and we don't yet have any cached way to retrieve its
    // location.
    // @todo Remove as part of https://www.drupal.org/node/2186491
    drupal_get_filename('profile', $profile, 'core/profiles/' . $profile . '/' . $profile . '.info.yml');
    $this->enableModules([
        'module_test',
        $profile,
    ]);
    $data = \Drupal::service('extension.list.module')->reset()
        ->getList();
    $this->assertArrayHasKey($dependency, $data[$profile]->requires);
    $this->assertArrayNotHasKey($non_dependency, $data[$profile]->requires);
    $this->moduleInstaller()
        ->install([
        $dependency,
        $non_dependency,
    ]);
    $this->assertTrue($this->moduleHandler()
        ->moduleExists($dependency));
    // Uninstall the profile module that is not a dependent.
    $result = $this->moduleInstaller()
        ->uninstall([
        $non_dependency,
    ]);
    $this->assertTrue($result, 'ModuleInstaller::uninstall() returns TRUE.');
    $this->assertFalse($this->moduleHandler()
        ->moduleExists($non_dependency));
    $this->assertEquals(drupal_get_installed_schema_version($non_dependency), SCHEMA_UNINSTALLED, "{$non_dependency} module was uninstalled.");
    // Verify that the installation profile itself was not uninstalled.
    $uninstalled_modules = \Drupal::state()->get('module_test.uninstall_order') ?: [];
    $this->assertContains($non_dependency, $uninstalled_modules, "{$non_dependency} module is in the list of uninstalled modules.");
    $this->assertNotContains($profile, $uninstalled_modules, 'The installation profile is not in the list of uninstalled modules.');
    // Try uninstalling the required module.
    $this->expectException(ModuleUninstallValidatorException::class);
    $this->expectExceptionMessage('The following reasons prevent the modules from being uninstalled: The Testing install profile dependencies module is required');
    $this->moduleInstaller()
        ->uninstall([
        $dependency,
    ]);
}

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