diff -u b/core/lib/Drupal/Core/Extension/ModuleHandler.php b/core/lib/Drupal/Core/Extension/ModuleHandler.php --- b/core/lib/Drupal/Core/Extension/ModuleHandler.php +++ b/core/lib/Drupal/Core/Extension/ModuleHandler.php @@ -845,7 +845,9 @@ drupal_set_installed_schema_version($module, $version); // Notify the entity manager that this module's entity types are new, - // so that it can install its schemas or whatever else is needed. + // so that it can notify all interested handlers. For example, a + // SQL-based storage handler can use this as an opportunity to create + // the necessary database tables. $entity_manager = \Drupal::entityManager(); foreach ($entity_manager->getDefinitions() as $entity_type) { if ($entity_type->getProvider() == $module) { @@ -958,8 +960,9 @@ \Drupal::service('config.manager')->uninstall('module', $module); // Notify the entity manager that this module's entity types are being - // deleted, so that it can uninstall its schemas or whatever else is - // needed. + // deleted, so that it can notify all interested handlers. For example, + // a SQL-based storage handler can use this as an opportunity to drop + // the corresponding database tables. foreach ($entity_manager->getDefinitions() as $entity_type) { if ($entity_type->getProvider() == $module) { $entity_manager->onEntityTypeDelete($entity_type); diff -u b/core/modules/simpletest/src/KernelTestBase.php b/core/modules/simpletest/src/KernelTestBase.php --- b/core/modules/simpletest/src/KernelTestBase.php +++ b/core/modules/simpletest/src/KernelTestBase.php @@ -378,13 +378,10 @@ /** - * Installs the tables for a specific entity type. + * Installs the storage schema for a specific entity type. * * @param string $entity_type_id * The ID of the entity type. - * - * @throws \RuntimeException - * Thrown when the entity type does not support automatic schema installation. */ protected function installEntitySchema($entity_type_id) { /** @var \Drupal\Core\Entity\EntityManagerInterface $entity_manager */ @@ -392,13 +389,28 @@ $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 && $storage instanceof EntityTypeListenerInterface) { - $table_mapping = $storage->getTableMapping(); - $this->pass(String::format('Installed entity type tables for the %entity_type entity type: %tables', array( - '%entity_type' => $entity_type_id, - '%tables' => '{' . implode('}, {', $table_mapping->getTableNames()) . '}', - ))); + 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(String::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(String::format('Installed entity type tables for the %entity_type entity type: %tables', array( + '%entity_type' => $entity_type_id, + '%tables' => '{' . implode('}, {', $tables) . '}', + ))); + } } }