function DependencyTest::testModuleEnableOrder

Same name in other branches
  1. 9 core/modules/system/tests/src/Functional/Module/DependencyTest.php \Drupal\Tests\system\Functional\Module\DependencyTest::testModuleEnableOrder()
  2. 10 core/modules/system/tests/src/Functional/Module/DependencyTest.php \Drupal\Tests\system\Functional\Module\DependencyTest::testModuleEnableOrder()
  3. 11.x core/modules/system/tests/src/Functional/Module/DependencyTest.php \Drupal\Tests\system\Functional\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/tests/src/Functional/Module/DependencyTest.php, line 163

Class

DependencyTest
Enable module without dependency enabled.

Namespace

Drupal\Tests\system\Functional\Module

Code

public function testModuleEnableOrder() {
    \Drupal::service('module_installer')->install([
        'module_test',
    ], FALSE);
    $this->resetAll();
    $this->assertModules([
        '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 = [
        'help',
        'config',
        'color',
    ];
    // Enable the modules through the UI, verifying that the dependency chain
    // is correct.
    $edit = [];
    $edit['modules[color][enable]'] = 'color';
    $this->drupalPostForm('admin/modules', $edit, t('Install'));
    $this->assertModules([
        '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[config][enable]'] = 'config';
    $edit['modules[help][enable]'] = 'help';
    $this->drupalPostForm('admin/modules', $edit, t('Install'));
    $this->assertModules([
        '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') ?: [];
    $this->assertIdentical($module_order, $expected_order);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.