function KernelTestBaseTest::testEnableModulesFixedList

Tests that the module list is retained after enabling/installing/disabling.

File

core/modules/simpletest/src/Tests/KernelTestBaseTest.php, line 240

Class

KernelTestBaseTest
Tests KernelTestBase functionality.

Namespace

Drupal\simpletest\Tests

Code

public function testEnableModulesFixedList() {
    // Install system module.
    $this->container
        ->get('module_installer')
        ->install([
        'system',
        'user',
        'menu_link_content',
    ]);
    $entity_manager = \Drupal::entityTypeManager();
    // entity_test is loaded via $modules; its entity type should exist.
    $this->assertEqual($this->container
        ->get('module_handler')
        ->moduleExists('entity_test'), TRUE);
    $this->assertTrue(TRUE == $entity_manager->getDefinition('entity_test'));
    // Load some additional modules; entity_test should still exist.
    $this->enableModules([
        'field',
        'text',
        'entity_test',
    ]);
    $this->assertEqual($this->container
        ->get('module_handler')
        ->moduleExists('entity_test'), TRUE);
    $this->assertTrue(TRUE == $entity_manager->getDefinition('entity_test'));
    // Install some other modules; entity_test should still exist.
    $this->container
        ->get('module_installer')
        ->install([
        'user',
        'field',
        'field_test',
    ], FALSE);
    $this->assertEqual($this->container
        ->get('module_handler')
        ->moduleExists('entity_test'), TRUE);
    $this->assertTrue(TRUE == $entity_manager->getDefinition('entity_test'));
    // Uninstall one of those modules; entity_test should still exist.
    $this->container
        ->get('module_installer')
        ->uninstall([
        'field_test',
    ]);
    $this->assertEqual($this->container
        ->get('module_handler')
        ->moduleExists('entity_test'), TRUE);
    $this->assertTrue(TRUE == $entity_manager->getDefinition('entity_test'));
    // Set the weight of a module; entity_test should still exist.
    module_set_weight('field', -1);
    $this->assertEqual($this->container
        ->get('module_handler')
        ->moduleExists('entity_test'), TRUE);
    $this->assertTrue(TRUE == $entity_manager->getDefinition('entity_test'));
    // Reactivate the previously uninstalled module.
    $this->enableModules([
        'field_test',
    ]);
    // Create a field.
    $this->installEntitySchema('entity_test');
    $display = EntityViewDisplay::create([
        'targetEntityType' => 'entity_test',
        'bundle' => 'entity_test',
        'mode' => 'default',
    ]);
    $field_storage = FieldStorageConfig::create([
        'field_name' => 'test_field',
        'entity_type' => 'entity_test',
        'type' => 'test_field',
    ]);
    $field_storage->save();
    FieldConfig::create([
        'field_storage' => $field_storage,
        'bundle' => 'entity_test',
    ])->save();
}

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