Commit 6c91ce87 authored by alexpott's avatar alexpott

Issue #2254203 by sun, neclimdul: Fix test performance of Drupal\system\Tests\Module\ModuleApiTest.

parent f02bf6cf
......@@ -111,8 +111,9 @@ function testEnableRequirementsFailureDependency() {
}
/**
* Tests that module dependencies are enabled in the correct order via the
* UI. Dependencies should be enabled before their dependents.
* Tests that module dependencies are enabled in the correct order in the UI.
*
* Dependencies should be enabled before their dependents.
*/
function testModuleEnableOrder() {
\Drupal::moduleHandler()->install(array('module_test'), FALSE);
......@@ -120,34 +121,24 @@ function testModuleEnableOrder() {
$this->assertModules(array('module_test'), TRUE);
\Drupal::state()->set('module_test.dependency', 'dependency');
// module_test creates a dependency chain:
// - forum depends on node, taxonomy, comment, datetime, history, and
// ban (via module_test)
// - node depends on text
// - text depends on filter
// - taxonomy depends on options
// - ban depends on xmlrpc (via module_test)
// The correct enable order is:
$expected_order = array('filter', 'text', 'options', 'xmlrpc', 'ban', 'node', 'datetime', 'comment', 'history', 'taxonomy', 'forum');
// - 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][forum][enable]'] = 'forum';
$edit['modules[Core][color][enable]'] = 'color';
$this->drupalPostForm('admin/modules', $edit, t('Save configuration'));
$this->assertModules(array('forum'), FALSE);
$this->assertText(t('You must enable the Node, Text, Filter, History, Taxonomy, Options, Comment, Datetime, Ban, XML-RPC modules to install Forum.'));
$edit['modules[Core][node][enable]'] = 'node';
$edit['modules[Field types][text][enable]'] = 'text';
$edit['modules[Core][filter][enable]'] = 'filter';
$edit['modules[Core][history][enable]'] = 'history';
$edit['modules[Field types][options][enable]'] = 'options';
$edit['modules[Core][taxonomy][enable]'] = 'taxonomy';
$edit['modules[Core][comment][enable]'] = 'comment';
$edit['modules[Field types][datetime][enable]'] = 'datetime';
$edit['modules[Core][ban][enable]'] = 'ban';
$edit['modules[Core][xmlrpc][enable]'] = 'xmlrpc';
$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('Save configuration'));
$this->assertModules(array('forum', 'ban', 'node', 'text', 'filter', 'xmlrpc', 'datetime', 'comment', 'history', 'taxonomy', 'options'), TRUE);
$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();
......
......@@ -18,36 +18,36 @@ function module_test_permission() {
*/
function module_test_system_info_alter(&$info, Extension $file, $type) {
if (\Drupal::state()->get('module_test.dependency') == 'missing dependency') {
if ($file->getName() == 'forum') {
// Make forum module depend on ban.
$info['dependencies'][] = 'ban';
if ($file->getName() == 'color') {
// Make color module depend on config.
$info['dependencies'][] = 'config';
}
elseif ($file->getName() == 'ban') {
// Make ban depend on a made-up module.
elseif ($file->getName() == 'config') {
// Make config module depend on a non-existing module.
$info['dependencies'][] = 'foo';
}
}
elseif (\Drupal::state()->get('module_test.dependency') == 'dependency') {
if ($file->getName() == 'forum') {
// Make the forum module depend on ban.
$info['dependencies'][] = 'ban';
if ($file->getName() == 'color') {
// Make color module depend on config.
$info['dependencies'][] = 'config';
}
elseif ($file->getName() == 'ban') {
// Make ban depend on xmlrpc module.
$info['dependencies'][] = 'xmlrpc';
elseif ($file->getName() == 'config') {
// Make config module depend on help module.
$info['dependencies'][] = 'help';
}
}
elseif (\Drupal::state()->get('module_test.dependency') == 'version dependency') {
if ($file->getName() == 'forum') {
// Make the forum module depend on ban.
$info['dependencies'][] = 'ban';
if ($file->getName() == 'color') {
// Make color module depend on config.
$info['dependencies'][] = 'config';
}
elseif ($file->getName() == 'ban') {
// Make ban depend on a specific version of xmlrpc module.
$info['dependencies'][] = 'xmlrpc (1.x)';
elseif ($file->getName() == 'config') {
// Make config module depend on a specific version of help module.
$info['dependencies'][] = 'help (1.x)';
}
elseif ($file->getName() == 'xmlrpc') {
// Set xmlrpc module to a version compatible with the above.
elseif ($file->getName() == 'help') {
// Set help module to a version compatible with the above.
$info['version'] = '8.x-1.0';
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment