You are here

public function EntityDefinitionUpdateTest::testEntityTypeUpdateWithData 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::testEntityTypeUpdateWithData()

Tests updating entity schema when there are existing entities.

File

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

Class

EntityDefinitionUpdateTest
Tests EntityDefinitionUpdateManager functionality.

Namespace

Drupal\system\Tests\Entity

Code

public function testEntityTypeUpdateWithData() {

  // Save an entity.
  $this->entityManager
    ->getStorage('entity_test_update')
    ->create()
    ->save();

  // Update the entity type to be revisionable and try to apply the update.
  // It's expected to throw an exception.
  $this
    ->updateEntityTypeToRevisionable();
  try {
    $this->entityDefinitionUpdateManager
      ->applyUpdates();
    $this
      ->fail('EntityStorageException thrown when trying to apply an update that requires data migration.');
  } catch (EntityStorageException $e) {
    $this
      ->pass('EntityStorageException thrown when trying to apply an update that requires data migration.');
  }
}