You are here

public function ModuleHandlerTest::testModuleList in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/system/tests/src/Kernel/Extension/ModuleHandlerTest.php \Drupal\Tests\system\Kernel\Extension\ModuleHandlerTest::testModuleList()
  2. 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 26

Class

ModuleHandlerTest
Tests ModuleHandler functionality.

Namespace

Drupal\Tests\system\Kernel\Extension

Code

public function testModuleList() {
  $module_list = [
    'path_alias',
    'system',
  ];
  $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, t('When using a fixed list'));
}