You are here

public function EntityDefinitionUpdateTest::testNewEntityType in Drupal 9

Same name and namespace in other branches
  1. 8 core/tests/Drupal/KernelTests/Core/Entity/EntityDefinitionUpdateTest.php \Drupal\KernelTests\Core\Entity\EntityDefinitionUpdateTest::testNewEntityType()
  2. 10 core/tests/Drupal/KernelTests/Core/Entity/EntityDefinitionUpdateTest.php \Drupal\KernelTests\Core\Entity\EntityDefinitionUpdateTest::testNewEntityType()

Tests that new entity type definitions are correctly handled.

File

core/tests/Drupal/KernelTests/Core/Entity/EntityDefinitionUpdateTest.php, line 80

Class

EntityDefinitionUpdateTest
Tests EntityDefinitionUpdateManager functionality.

Namespace

Drupal\KernelTests\Core\Entity

Code

public function testNewEntityType() {
  $entity_type_id = 'entity_test_new';
  $schema = $this->database
    ->schema();

  // Check that the "entity_test_new" is not defined.
  $entity_types = $this->entityTypeManager
    ->getDefinitions();
  $this
    ->assertFalse(isset($entity_types[$entity_type_id]), 'The "entity_test_new" entity type does not exist.');
  $this
    ->assertFalse($schema
    ->tableExists($entity_type_id), 'Schema for the "entity_test_new" entity type does not exist.');

  // Check that the "entity_test_new" is now defined and the related schema
  // has been created.
  $this
    ->enableNewEntityType();
  $entity_types = $this->entityTypeManager
    ->getDefinitions();
  $this
    ->assertTrue(isset($entity_types[$entity_type_id]), 'The "entity_test_new" entity type exists.');
  $this
    ->assertTrue($schema
    ->tableExists($entity_type_id), 'Schema for the "entity_test_new" entity type has been created.');
}