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. 8.9.x 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 243

Class

DependencyTest
Enable module without dependency enabled.

Namespace

Drupal\Tests\system\Functional\Module

Code

public function testModuleEnableOrder() : void {
    \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:
    // - dblog depends on config
    // - config depends on help
    $expected_order = [
        'help',
        'config',
        'dblog',
    ];
    // Enable the modules through the UI, verifying that the dependency chain
    // is correct.
    $edit = [];
    $edit['modules[dblog][enable]'] = 'dblog';
    $this->drupalGet('admin/modules');
    $this->submitForm($edit, 'Install');
    $this->assertModules([
        'dblog',
    ], FALSE);
    // Note that dependencies are sorted alphabetically in the confirmation
    // message.
    $this->assertSession()
        ->pageTextContains('You must install the Configuration Manager, Help modules to install Database Logging.');
    $edit['modules[config][enable]'] = 'config';
    $edit['modules[help][enable]'] = 'help';
    $this->drupalGet('admin/modules');
    $this->submitForm($edit, 'Install');
    $this->assertModules([
        'dblog',
        '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->assertSame($expected_order, $module_order);
}

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