You are here

public function ModuleHandlerTest::testProfileAllDependencies in Drupal 9

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

Tests that a profile can supply only real dependencies.

File

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

Class

ModuleHandlerTest
Tests ModuleHandler functionality.

Namespace

Drupal\Tests\system\Kernel\Extension

Code

public function testProfileAllDependencies() {
  $profile = 'testing_install_profile_all_dependencies';
  $dependencies = [
    'dblog',
    'ban',
  ];
  $this
    ->setInstallProfile($profile);

  // Prime the \Drupal\Core\Extension\ExtensionList::getPathname() 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
  $profile_list = \Drupal::service('extension.list.profile');
  assert($profile_list instanceof ProfileExtensionList);
  $profile_list
    ->setPathname($profile, 'core/profiles/' . $profile . '/' . $profile . '.info.yml');
  $this
    ->enableModules([
    'module_test',
    $profile,
  ]);
  $data = \Drupal::service('extension.list.module')
    ->reset()
    ->getList();
  foreach ($dependencies as $dependency) {
    $this
      ->assertArrayHasKey($dependency, $data[$profile]->requires);
  }
  $this
    ->moduleInstaller()
    ->install($dependencies);
  foreach ($dependencies as $dependency) {
    $this
      ->assertTrue($this
      ->moduleHandler()
      ->moduleExists($dependency));
  }

  // Try uninstalling the dependencies.
  $this
    ->expectException(ModuleUninstallValidatorException::class);
  $this
    ->expectExceptionMessage('The following reasons prevent the modules from being uninstalled: The Testing install profile all dependencies module is required');
  $this
    ->moduleInstaller()
    ->uninstall($dependencies);
}