function ModuleHandlerTest::testModuleList

Same name in other branches
  1. 9 core/modules/system/tests/src/Kernel/Extension/ModuleHandlerTest.php \Drupal\Tests\system\Kernel\Extension\ModuleHandlerTest::testModuleList()
  2. 8.9.x core/modules/system/tests/src/Kernel/Extension/ModuleHandlerTest.php \Drupal\Tests\system\Kernel\Extension\ModuleHandlerTest::testModuleList()
  3. 10 core/modules/system/tests/src/Kernel/Extension/ModuleHandlerTest.php \Drupal\Tests\system\Kernel\Extension\ModuleHandlerTest::testModuleList()

The basic functionality of retrieving enabled modules.

File

core/modules/system/tests/src/Kernel/Extension/ModuleHandlerTest.php, line 29

Class

ModuleHandlerTest
Tests ModuleHandler functionality.

Namespace

Drupal\Tests\system\Kernel\Extension

Code

public function testModuleList() : void {
    $module_list = [
        'system',
    ];
    $database_module = \Drupal::database()->getProvider();
    if ($database_module !== 'core') {
        $module_list[] = $database_module;
    }
    sort($module_list);
    $this->assertModuleList($module_list, 'Initial');
    // Try to install a new module.
    $this->moduleInstaller()
        ->install([
        'ban',
    ]);
    $module_list[] = 'ban';
    sort($module_list);
    $this->assertModuleList($module_list, 'After adding a module');
    // Try to mess with the module weights.
    module_set_weight('ban', 20);
    // Move ban to the end of the array.
    unset($module_list[array_search('ban', $module_list)]);
    $module_list[] = 'ban';
    $this->assertModuleList($module_list, 'After changing weights');
    // Test the fixed list feature.
    $fixed_list = [
        'system' => 'core/modules/system/system.module',
        'menu' => 'core/modules/menu/menu.module',
    ];
    $this->moduleHandler()
        ->setModuleList($fixed_list);
    $new_module_list = array_combine(array_keys($fixed_list), array_keys($fixed_list));
    $this->assertModuleList($new_module_list, 'When using a fixed list');
}

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