function KernelTestBase::installEntitySchema

Same name in this branch
  1. 8.9.x core/tests/Drupal/KernelTests/KernelTestBase.php \Drupal\KernelTests\KernelTestBase::installEntitySchema()
Same name in other branches
  1. 9 core/tests/Drupal/KernelTests/KernelTestBase.php \Drupal\KernelTests\KernelTestBase::installEntitySchema()
  2. 10 core/tests/Drupal/KernelTests/KernelTestBase.php \Drupal\KernelTests\KernelTestBase::installEntitySchema()
  3. 11.x 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.

4 calls to KernelTestBase::installEntitySchema()
EntityUnitTestBase::setUp in core/modules/system/src/Tests/Entity/EntityUnitTestBase.php
Performs setup tasks before each individual test method is run.
KernelTestBaseTest::testEnableModulesFixedList in core/modules/simpletest/src/Tests/KernelTestBaseTest.php
Tests that the module list is retained after enabling/installing/disabling.
KernelTestBaseTest::testEnableModulesInstallContainer in core/modules/simpletest/src/Tests/KernelTestBaseTest.php
Tests installing modules with DependencyInjection services.
KernelTestBaseTest::testInstallEntitySchema in core/modules/simpletest/src/Tests/KernelTestBaseTest.php
Tests expected behavior of installEntitySchema().

File

core/modules/simpletest/src/KernelTestBase.php, line 497

Class

KernelTestBase
Base class for functional integration tests.

Namespace

Drupal\simpletest

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(new FormattableMarkup('Installed entity type table for the %entity_type entity type: %table', [
                    '%entity_type' => $entity_type_id,
                    '%table' => $table,
                ]));
                $all_tables_exist = FALSE;
            }
        }
        if ($all_tables_exist) {
            $this->pass(new FormattableMarkup('Installed entity type tables for the %entity_type entity type: %tables', [
                '%entity_type' => $entity_type_id,
                '%tables' => '{' . implode('}, {', $tables) . '}',
            ]));
        }
    }
}

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