You are here

protected function KernelTestBase::installEntitySchema in Zircon Profile 8

Same name in this branch
  1. 8 core/tests/Drupal/KernelTests/KernelTestBase.php \Drupal\KernelTests\KernelTestBase::installEntitySchema()
  2. 8 core/modules/simpletest/src/KernelTestBase.php \Drupal\simpletest\KernelTestBase::installEntitySchema()
Same name and namespace in other branches
  1. 8.0 core/tests/Drupal/KernelTests/KernelTestBase.php \Drupal\KernelTests\KernelTestBase::installEntitySchema()

Installs the storage schema for a specific entity type.

Parameters

string $entity_type_id: The ID of the entity type.

6 calls to KernelTestBase::installEntitySchema()
EntityReferenceSelectionReferenceableTest::setUp in core/modules/system/tests/src/Kernel/Entity/EntityReferenceSelectionReferenceableTest.php
FileItemValidationTest::setUp in core/modules/file/tests/src/Kernel/FileItemValidationTest.php
ItemWithoutFeedTest::setUp in core/modules/aggregator/src/Tests/ItemWithoutFeedTest.php
ModuleHandlerTest::testUninstallContentDependency in core/modules/system/tests/src/Kernel/Extension/ModuleHandlerTest.php
Tests uninstalling a module that has content.
NormalizerTestBase::setUp in core/modules/serialization/src/Tests/NormalizerTestBase.php

... See full list

File

core/tests/Drupal/KernelTests/KernelTestBase.php, line 756
Contains \Drupal\KernelTests\KernelTestBase.

Class

KernelTestBase
Base class for functional integration tests.

Namespace

Drupal\KernelTests

Code

protected function installEntitySchema($entity_type_id) {

  /** @var \Drupal\Core\Entity\EntityManagerInterface $entity_manager */
  $entity_manager = $this->container
    ->get('entity.manager');
  $entity_type = $entity_manager
    ->getDefinition($entity_type_id);
  $entity_manager
    ->onEntityTypeCreate($entity_type);

  // For test runs, the most common storage backend is a SQL database. For
  // this case, ensure the tables got created.
  $storage = $entity_manager
    ->getStorage($entity_type_id);
  if ($storage instanceof SqlEntityStorageInterface) {
    $tables = $storage
      ->getTableMapping()
      ->getTableNames();
    $db_schema = $this->container
      ->get('database')
      ->schema();
    $all_tables_exist = TRUE;
    foreach ($tables as $table) {
      if (!$db_schema
        ->tableExists($table)) {
        $this
          ->fail(SafeMarkup::format('Installed entity type table for the %entity_type entity type: %table', array(
          '%entity_type' => $entity_type_id,
          '%table' => $table,
        )));
        $all_tables_exist = FALSE;
      }
    }
    if ($all_tables_exist) {
      $this
        ->pass(SafeMarkup::format('Installed entity type tables for the %entity_type entity type: %tables', array(
        '%entity_type' => $entity_type_id,
        '%tables' => '{' . implode('}, {', $tables) . '}',
      )));
    }
  }
}