You are here

function KernelTestBaseTest::testEnableModulesFixedList in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/simpletest/src/Tests/KernelTestBaseTest.php \Drupal\simpletest\Tests\KernelTestBaseTest::testEnableModulesFixedList()

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

File

core/modules/simpletest/src/Tests/KernelTestBaseTest.php, line 242
Contains \Drupal\simpletest\Tests\KernelTestBaseTest.

Class

KernelTestBaseTest
Tests KernelTestBase functionality.

Namespace

Drupal\simpletest\Tests

Code

function testEnableModulesFixedList() {

  // Install system module.
  $this->container
    ->get('module_installer')
    ->install(array(
    'system',
    'menu_link_content',
  ));
  $entity_manager = \Drupal::entityManager();

  // 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(array(
    '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(array(
    '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(array(
    '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(array(
    'field_test',
  ));

  // Create a field.
  entity_create('entity_view_display', array(
    'targetEntityType' => 'entity_test',
    'bundle' => 'entity_test',
    'mode' => 'default',
  ));
  $field_storage = entity_create('field_storage_config', array(
    'field_name' => 'test_field',
    'entity_type' => 'entity_test',
    'type' => 'test_field',
  ));
  $field_storage
    ->save();
  entity_create('field_config', array(
    'field_storage' => $field_storage,
    'bundle' => 'entity_test',
  ))
    ->save();
}