You are here

public function EntityDefinitionUpdateTest::testBaseFieldUpdateWithExistingData in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/system/src/Tests/Entity/EntityDefinitionUpdateTest.php \Drupal\system\Tests\Entity\EntityDefinitionUpdateTest::testBaseFieldUpdateWithExistingData()

Tests updating a base field when it has existing data.

File

core/modules/system/src/Tests/Entity/EntityDefinitionUpdateTest.php, line 436
Contains \Drupal\system\Tests\Entity\EntityDefinitionUpdateTest.

Class

EntityDefinitionUpdateTest
Tests EntityDefinitionUpdateManager functionality.

Namespace

Drupal\system\Tests\Entity

Code

public function testBaseFieldUpdateWithExistingData() {

  // Add the base field and run the update.
  $this
    ->addBaseField();
  $this->entityDefinitionUpdateManager
    ->applyUpdates();

  // Save an entity with the base field populated.
  $this->entityManager
    ->getStorage('entity_test_update')
    ->create(array(
    'new_base_field' => 'foo',
  ))
    ->save();

  // Change the field's field type and apply updates. It's expected to
  // throw an exception.
  $this
    ->modifyBaseField();
  try {
    $this->entityDefinitionUpdateManager
      ->applyUpdates();
    $this
      ->fail('FieldStorageDefinitionUpdateForbiddenException thrown when trying to update a field schema that has data.');
  } catch (FieldStorageDefinitionUpdateForbiddenException $e) {
    $this
      ->pass('FieldStorageDefinitionUpdateForbiddenException thrown when trying to update a field schema that has data.');
  }
}