function SqlContentEntityStorageSchemaColumnTest::testColumnUpdateWithFlag

Same name in other branches
  1. 11.x core/modules/field/tests/src/Kernel/Entity/Update/SqlContentEntityStorageSchemaColumnTest.php \Drupal\Tests\field\Kernel\Entity\Update\SqlContentEntityStorageSchemaColumnTest::testColumnUpdateWithFlag()

Tests that schema changes are updated for fields with data with the flag.

File

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

Class

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

Namespace

Drupal\Tests\field\Kernel\Entity\Update

Code

public function testColumnUpdateWithFlag() : 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. It should succeed if the
    // column_changes_handled flag is passed.
    $entity_definition_update_manager = \Drupal::entityDefinitionUpdateManager();
    $field_storage_definition = $entity_definition_update_manager->getFieldStorageDefinition('test', 'entity_test_rev');
    // Provide the flag to allow schema updates.
    $field_storage_definition->setSetting('column_changes_handled', TRUE);
    $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.