Tests that module dependencies are enabled in the correct order via the UI. Dependencies should be enabled before their dependents.
function testModuleEnableOrder() {
module_enable(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:
// - forum depends on taxonomy, comment, datetime, history, and ban (via module_test)
// - taxonomy depends on options
// - options depends on number
// - ban depends on php (via module_test)
// The correct enable order is:
$expected_order = array(
'php',
'ban',
'datetime',
'comment',
'history',
'number',
'options',
'taxonomy',
'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, Number, Comment, Datetime, Ban, PHP Filter modules to install Forum.'));
$edit['modules[Core][history][enable]'] = 'history';
$edit['modules[Core][options][enable]'] = 'options';
$edit['modules[Core][number][enable]'] = 'number';
$edit['modules[Core][taxonomy][enable]'] = 'taxonomy';
$edit['modules[Core][comment][enable]'] = 'comment';
$edit['modules[Core][datetime][enable]'] = 'datetime';
$edit['modules[Core][ban][enable]'] = 'ban';
$edit['modules[Core][php][enable]'] = 'php';
$this
->drupalPost('admin/modules', $edit, t('Save configuration'));
$this
->assertModules(array(
'forum',
'ban',
'php',
'datetime',
'comment',
'history',
'taxonomy',
'options',
'number',
), TRUE);
// Check the actual order which is saved by module_test_modules_enabled().
$module_order = \Drupal::state()
->get('system_test.module_enable_order') ?: array();
$this
->assertIdentical($module_order, $expected_order);
}