You are here

public function SqlContentEntityStorageSchemaColumnTest::testColumnUpdate in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/field/tests/src/Kernel/Entity/Update/SqlContentEntityStorageSchemaColumnTest.php \Drupal\Tests\field\Kernel\Entity\Update\SqlContentEntityStorageSchemaColumnTest::testColumnUpdate()

Tests that column-level schema changes are detected for fields with data.

File

core/modules/field/tests/src/Kernel/Entity/Update/SqlContentEntityStorageSchemaColumnTest.php, line 85

Class

SqlContentEntityStorageSchemaColumnTest
Tests that schema changes in fields with data are detected during updates.

Namespace

Drupal\Tests\field\Kernel\Entity\Update

Code

public function testColumnUpdate() {

  // Change the field type in the stored schema.
  $schema = \Drupal::keyValue('entity.storage_schema.sql')
    ->get('entity_test_rev.field_schema_data.test');
  $schema['entity_test_rev__test']['fields']['test_value']['type'] = 'varchar_ascii';
  \Drupal::keyValue('entity.storage_schema.sql')
    ->set('entity_test_rev.field_schema_data.test', $schema);

  // Now attempt to run automatic updates. An exception should be thrown
  // since there is data in the table.
  $this
    ->expectException(FieldStorageDefinitionUpdateForbiddenException::class);
  $entity_definition_update_manager = \Drupal::entityDefinitionUpdateManager();
  $field_storage_definition = $entity_definition_update_manager
    ->getFieldStorageDefinition('test', 'entity_test_rev');
  $entity_definition_update_manager
    ->updateFieldStorageDefinition($field_storage_definition);
}