You are here

public function SqlContentEntityStorageSchemaColumnTest::testColumnUpdate in Zircon Profile 8.0

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

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

File

core/modules/field/src/Tests/Entity/Update/SqlContentEntityStorageSchemaColumnTest.php, line 87
Contains \Drupal\field\Tests\Entity\Update\SqlContentEntityStorageSchemaColumnTest.

Class

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

Namespace

Drupal\field\Tests\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.
  try {
    \Drupal::service('entity.definition_update_manager')
      ->applyUpdates();
    $this
      ->fail('Failed to detect a schema change in a field with data.');
  } catch (FieldStorageDefinitionUpdateForbiddenException $e) {
    $this
      ->pass('Detected a schema change in a field with data.');
  }
}