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() { ...@@ -111,8 +111,9 @@ function testEnableRequirementsFailureDependency() {
} }
/** /**
* Tests that module dependencies are enabled in the correct order via the * Tests that module dependencies are enabled in the correct order in the UI.
* UI. Dependencies should be enabled before their dependents. *
* Dependencies should be enabled before their dependents.
*/ */
function testModuleEnableOrder() { function testModuleEnableOrder() {
\Drupal::moduleHandler()->install(array('module_test'), FALSE); \Drupal::moduleHandler()->install(array('module_test'), FALSE);
...@@ -120,34 +121,24 @@ function testModuleEnableOrder() { ...@@ -120,34 +121,24 @@ function testModuleEnableOrder() {
$this->assertModules(array('module_test'), TRUE); $this->assertModules(array('module_test'), TRUE);
\Drupal::state()->set('module_test.dependency', 'dependency'); \Drupal::state()->set('module_test.dependency', 'dependency');
// module_test creates a dependency chain: // module_test creates a dependency chain:
// - forum depends on node, taxonomy, comment, datetime, history, and // - color depends on config
// ban (via module_test) // - config depends on help
// - node depends on text $expected_order = array('help', 'config', 'color');
// - 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');
// Enable the modules through the UI, verifying that the dependency chain // Enable the modules through the UI, verifying that the dependency chain
// is correct. // is correct.
$edit = array(); $edit = array();
$edit['modules[Core][forum][enable]'] = 'forum'; $edit['modules[Core][color][enable]'] = 'color';
$this->drupalPostForm('admin/modules', $edit, t('Save configuration')); $this->drupalPostForm('admin/modules', $edit, t('Save configuration'));
$this->assertModules(array('forum'), FALSE); $this->assertModules(array('color'), FALSE);
$this->assertText(t('You must enable the Node, Text, Filter, History, Taxonomy, Options, Comment, Datetime, Ban, XML-RPC modules to install Forum.')); // Note that dependencies are sorted alphabetically in the confirmation
$edit['modules[Core][node][enable]'] = 'node'; // message.
$edit['modules[Field types][text][enable]'] = 'text'; $this->assertText(t('You must enable the Configuration Manager, Help modules to install Color.'));
$edit['modules[Core][filter][enable]'] = 'filter';
$edit['modules[Core][history][enable]'] = 'history'; $edit['modules[Core][config][enable]'] = 'config';
$edit['modules[Field types][options][enable]'] = 'options'; $edit['modules[Core][help][enable]'] = 'help';
$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->drupalPostForm('admin/modules', $edit, t('Save configuration')); $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(). // Check the actual order which is saved by module_test_modules_enabled().
$module_order = \Drupal::state()->get('module_test.install_order') ?: array(); $module_order = \Drupal::state()->get('module_test.install_order') ?: array();
......
...@@ -18,36 +18,36 @@ function module_test_permission() { ...@@ -18,36 +18,36 @@ function module_test_permission() {
*/ */
function module_test_system_info_alter(&$info, Extension $file, $type) { function module_test_system_info_alter(&$info, Extension $file, $type) {
if (\Drupal::state()->get('module_test.dependency') == 'missing dependency') { if (\Drupal::state()->get('module_test.dependency') == 'missing dependency') {
if ($file->getName() == 'forum') { if ($file->getName() == 'color') {
// Make forum module depend on ban. // Make color module depend on config.
$info['dependencies'][] = 'ban'; $info['dependencies'][] = 'config';
} }
elseif ($file->getName() == 'ban') { elseif ($file->getName() == 'config') {
// Make ban depend on a made-up module. // Make config module depend on a non-existing module.
$info['dependencies'][] = 'foo'; $info['dependencies'][] = 'foo';
} }
} }
elseif (\Drupal::state()->get('module_test.dependency') == 'dependency') { elseif (\Drupal::state()->get('module_test.dependency') == 'dependency') {
if ($file->getName() == 'forum') { if ($file->getName() == 'color') {
// Make the forum module depend on ban. // Make color module depend on config.
$info['dependencies'][] = 'ban'; $info['dependencies'][] = 'config';
} }
elseif ($file->getName() == 'ban') { elseif ($file->getName() == 'config') {
// Make ban depend on xmlrpc module. // Make config module depend on help module.
$info['dependencies'][] = 'xmlrpc'; $info['dependencies'][] = 'help';
} }
} }
elseif (\Drupal::state()->get('module_test.dependency') == 'version dependency') { elseif (\Drupal::state()->get('module_test.dependency') == 'version dependency') {
if ($file->getName() == 'forum') { if ($file->getName() == 'color') {
// Make the forum module depend on ban. // Make color module depend on config.
$info['dependencies'][] = 'ban'; $info['dependencies'][] = 'config';
} }
elseif ($file->getName() == 'ban') { elseif ($file->getName() == 'config') {
// Make ban depend on a specific version of xmlrpc module. // Make config module depend on a specific version of help module.
$info['dependencies'][] = 'xmlrpc (1.x)'; $info['dependencies'][] = 'help (1.x)';
} }
elseif ($file->getName() == 'xmlrpc') { elseif ($file->getName() == 'help') {
// Set xmlrpc module to a version compatible with the above. // Set help module to a version compatible with the above.
$info['version'] = '8.x-1.0'; $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