protected function KernelTestBase::installEntitySchema in SimpleTest 8.3
Installs the storage schema for a specific entity type.
Parameters
string $entity_type_id: The ID of the entity type.
3 calls to KernelTestBase::installEntitySchema()
- KernelTestBaseTest::testEnableModulesFixedList in src/
Tests/ KernelTestBaseTest.php - Tests that the module list is retained after enabling/installing/disabling.
- KernelTestBaseTest::testEnableModulesInstallContainer in src/
Tests/ KernelTestBaseTest.php - Tests installing modules with DependencyInjection services.
- KernelTestBaseTest::testInstallEntitySchema in src/
Tests/ KernelTestBaseTest.php - Tests expected behavior of installEntitySchema().
File
- src/
KernelTestBase.php, line 491
Class
- KernelTestBase
- Base class for functional integration tests.
Namespace
Drupal\simpletestCode
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) . '}',
]));
}
}
}