You are here

function ModuleHandlerTest::testUninstallProfileDependency in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/system/tests/src/Kernel/Extension/ModuleHandlerTest.php \Drupal\Tests\system\Kernel\Extension\ModuleHandlerTest::testUninstallProfileDependency()

Tests uninstalling a module that is a "dependency" of a profile.

File

core/modules/system/tests/src/Kernel/Extension/ModuleHandlerTest.php, line 188
Contains \Drupal\system\Tests\Extension\ModuleHandlerTest.

Class

ModuleHandlerTest
Tests ModuleHandler functionality.

Namespace

Drupal\Tests\system\Kernel\Extension

Code

function testUninstallProfileDependency() {
  $profile = 'minimal';
  $dependency = 'dblog';
  $this
    ->setSetting('install_profile', $profile);

  // Prime the drupal_get_filename() static cache with the location of the
  // minimal 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(array(
    'module_test',
    $profile,
  ));
  drupal_static_reset('system_rebuild_module_data');
  $data = system_rebuild_module_data();
  $this
    ->assertTrue(isset($data[$profile]->requires[$dependency]));
  $this
    ->moduleInstaller()
    ->install(array(
    $dependency,
  ));
  $this
    ->assertTrue($this
    ->moduleHandler()
    ->moduleExists($dependency));

  // Uninstall the profile module "dependency".
  $result = $this
    ->moduleInstaller()
    ->uninstall(array(
    $dependency,
  ));
  $this
    ->assertTrue($result, 'ModuleHandler::uninstall() returns TRUE.');
  $this
    ->assertFalse($this
    ->moduleHandler()
    ->moduleExists($dependency));
  $this
    ->assertEqual(drupal_get_installed_schema_version($dependency), SCHEMA_UNINSTALLED, "{$dependency} module was uninstalled.");

  // Verify that the installation profile itself was not uninstalled.
  $uninstalled_modules = \Drupal::state()
    ->get('module_test.uninstall_order') ?: array();
  $this
    ->assertTrue(in_array($dependency, $uninstalled_modules), "{$dependency} module is in the list of uninstalled modules.");
  $this
    ->assertFalse(in_array($profile, $uninstalled_modules), 'The installation profile is not in the list of uninstalled modules.');
}