function SqlContentEntityStorageSchemaColumnTest::testColumnUpdate

Same name in other branches
  1. 9 core/modules/field/tests/src/Kernel/Entity/Update/SqlContentEntityStorageSchemaColumnTest.php \Drupal\Tests\field\Kernel\Entity\Update\SqlContentEntityStorageSchemaColumnTest::testColumnUpdate()
  2. 8.9.x core/modules/field/tests/src/Kernel/Entity/Update/SqlContentEntityStorageSchemaColumnTest.php \Drupal\Tests\field\Kernel\Entity\Update\SqlContentEntityStorageSchemaColumnTest::testColumnUpdate()
  3. 10 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 103

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() : void {
    // 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);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.