You are here

function DependencyTest::testModuleEnableOrder in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/system/src/Tests/Module/DependencyTest.php \Drupal\system\Tests\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/src/Tests/Module/DependencyTest.php, line 128
Contains \Drupal\system\Tests\Module\DependencyTest.

Class

DependencyTest
Enable module without dependency enabled.

Namespace

Drupal\system\Tests\Module

Code

function testModuleEnableOrder() {
  \Drupal::service('module_installer')
    ->install(array(
    'module_test',
  ), FALSE);
  $this
    ->resetAll();
  $this
    ->assertModules(array(
    '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 = array(
    'help',
    'config',
    'color',
  );

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

  // Note that dependencies are sorted alphabetically in the confirmation
  // message.
  $this
    ->assertText(t('You must enable the Configuration Manager, Help modules to install Color.'));
  $edit['modules[Core][config][enable]'] = 'config';
  $edit['modules[Core][help][enable]'] = 'help';
  $this
    ->drupalPostForm('admin/modules', $edit, t('Install'));
  $this
    ->assertModules(array(
    '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') ?: array();
  $this
    ->assertIdentical($module_order, $expected_order);
}