You are here

public function DependencyTest::testModuleEnableOrder in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/system/tests/src/Functional/Module/DependencyTest.php \Drupal\Tests\system\Functional\Module\DependencyTest::testModuleEnableOrder()
  2. 10 core/modules/system/tests/src/Functional/Module/DependencyTest.php \Drupal\Tests\system\Functional\Module\DependencyTest::testModuleEnableOrder()

Tests that module dependencies are enabled in the correct order in the UI.

Dependencies should be enabled before their dependents.

File

core/modules/system/tests/src/Functional/Module/DependencyTest.php, line 162

Class

DependencyTest
Enable module without dependency enabled.

Namespace

Drupal\Tests\system\Functional\Module

Code

public function testModuleEnableOrder() {
  \Drupal::service('module_installer')
    ->install([
    'module_test',
  ], FALSE);
  $this
    ->resetAll();
  $this
    ->assertModules([
    'module_test',
  ], TRUE);
  \Drupal::state()
    ->set('module_test.dependency', 'dependency');

  // module_test creates a dependency chain:
  // - color depends on config
  // - config depends on help
  $expected_order = [
    'help',
    'config',
    'color',
  ];

  // Enable the modules through the UI, verifying that the dependency chain
  // is correct.
  $edit = [];
  $edit['modules[color][enable]'] = 'color';
  $this
    ->drupalGet('admin/modules');
  $this
    ->submitForm($edit, 'Install');
  $this
    ->assertModules([
    'color',
  ], FALSE);

  // Note that dependencies are sorted alphabetically in the confirmation
  // message.
  $this
    ->assertSession()
    ->pageTextContains('You must enable the Configuration Manager, Help modules to install Color.');
  $edit['modules[config][enable]'] = 'config';
  $edit['modules[help][enable]'] = 'help';
  $this
    ->drupalGet('admin/modules');
  $this
    ->submitForm($edit, 'Install');
  $this
    ->assertModules([
    'color',
    'config',
    'help',
  ], TRUE);

  // Check the actual order which is saved by module_test_modules_enabled().
  $module_order = \Drupal::state()
    ->get('module_test.install_order', []);
  $this
    ->assertSame($expected_order, $module_order);
}