function DependencyTest::testModuleEnableOrder

Tests that module dependencies are enabled in the correct order via the UI. Dependencies should be enabled before their dependents.

File

drupal/core/modules/system/lib/Drupal/system/Tests/Module/DependencyTest.php, line 131
Definition of Drupal\system\Tests\Module\DependencyTest.

Class

DependencyTest
Tests module dependency functionality.

Namespace

Drupal\system\Tests\Module

Code

function testModuleEnableOrder() {
  module_enable(array(
    'module_test',
  ), FALSE);
  $this
    ->resetAll();
  $this
    ->assertModules(array(
    'module_test',
  ), TRUE);
  state()
    ->set('module_test.dependency', 'dependency');

  // module_test creates a dependency chain:
  // - forum depends on taxonomy, comment, history, and poll (via module_test)
  // - taxonomy depends on options
  // - poll depends on php (via module_test)
  // The correct enable order is:
  $expected_order = array(
    'comment',
    'history',
    'options',
    'taxonomy',
    'php',
    'poll',
    'forum',
  );

  // Enable the modules through the UI, verifying that the dependency chain
  // is correct.
  $edit = array();
  $edit['modules[Core][forum][enable]'] = 'forum';
  $this
    ->drupalPost('admin/modules', $edit, t('Save configuration'));
  $this
    ->assertModules(array(
    'forum',
  ), FALSE);
  $this
    ->assertText(t('You must enable the History, Taxonomy, Options, Comment, Poll, PHP Filter modules to install Forum.'));
  $edit['modules[Core][history][enable]'] = 'history';
  $edit['modules[Core][options][enable]'] = 'options';
  $edit['modules[Core][taxonomy][enable]'] = 'taxonomy';
  $edit['modules[Core][comment][enable]'] = 'comment';
  $edit['modules[Core][poll][enable]'] = 'poll';
  $edit['modules[Core][php][enable]'] = 'php';
  $this
    ->drupalPost('admin/modules', $edit, t('Save configuration'));
  $this
    ->assertModules(array(
    'forum',
    'poll',
    'php',
    'comment',
    'history',
    'taxonomy',
    'options',
  ), TRUE);

  // Check the actual order which is saved by module_test_modules_enabled().
  $module_order = state()
    ->get('system_test.module_enable_order') ?: array();
  $this
    ->assertIdentical($module_order, $expected_order);
}