You are here

public function EntityDefinitionUpdateTest::testUpdateFieldableEntityTypeWithoutInCodeDefinition 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::testUpdateFieldableEntityTypeWithoutInCodeDefinition()

Tests updating a fieldable entity type that doesn't exist in code anymore.

@covers ::updateFieldableEntityType

File

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

Class

EntityDefinitionUpdateTest
Tests EntityDefinitionUpdateManager functionality.

Namespace

Drupal\KernelTests\Core\Entity

Code

public function testUpdateFieldableEntityTypeWithoutInCodeDefinition() {
  $entity_type = clone $this->entityTypeManager
    ->getDefinition('entity_test_update');
  $field_storage_definitions = \Drupal::service('entity_field.manager')
    ->getFieldStorageDefinitions('entity_test_update');

  // Remove the entity type definition. This is the same thing as removing the
  // code that defines it.
  $this
    ->deleteEntityType();

  // Rename the base table, update the fieldable entity type and check that
  // the table has been renamed.
  $entity_type
    ->set('base_table', 'entity_test_update_new');
  $this->entityDefinitionUpdateManager
    ->updateFieldableEntityType($entity_type, $field_storage_definitions);
  $this
    ->assertTrue($this->database
    ->schema()
    ->tableExists('entity_test_update_new'), 'The base table has been renamed.');
  $this
    ->assertFalse($this->database
    ->schema()
    ->tableExists('entity_test_update'), 'The old base table does not exist anymore.');
}