You are here

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

Tests updating a bundle field when the entity type schema has changed.

File

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

Class

EntityDefinitionUpdateTest
Tests EntityDefinitionUpdateManager functionality.

Namespace

Drupal\KernelTests\Core\Entity

Code

public function testBundleFieldUpdateWithEntityTypeSchemaUpdate() {

  // Add the bundle field and run the update.
  $this
    ->addBundleField();
  $this
    ->applyEntityUpdates();

  // Update the entity type schema to revisionable but don't run the updates
  // yet.
  $this
    ->updateEntityTypeToRevisionable();

  // Perform a no-op update on the bundle field, which should work because
  // both the storage and the storage schema are using the last installed
  // entity type definition.
  $entity_definition_update_manager = \Drupal::entityDefinitionUpdateManager();
  $entity_definition_update_manager
    ->updateFieldStorageDefinition($entity_definition_update_manager
    ->getFieldStorageDefinition('new_bundle_field', 'entity_test_update'));
}