You are here

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

Tests deleting a bundle field when it has existing data.

File

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

Class

EntityDefinitionUpdateTest
Tests EntityDefinitionUpdateManager functionality.

Namespace

Drupal\system\Tests\Entity

Code

public function testBundleFieldDeleteWithExistingData() {

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

  // Save an entity with the bundle field populated.
  entity_test_create_bundle('custom');
  $this->entityManager
    ->getStorage('entity_test_update')
    ->create(array(
    'type' => 'test_bundle',
    'new_bundle_field' => 'foo',
  ))
    ->save();

  // Remove the bundle field and apply updates. It's expected to throw an
  // exception.
  // @todo Revisit that expectation once purging is implemented for
  //   all fields: https://www.drupal.org/node/2282119.
  $this
    ->removeBundleField();
  try {
    $this->entityDefinitionUpdateManager
      ->applyUpdates();
    $this
      ->fail('FieldStorageDefinitionUpdateForbiddenException thrown when trying to apply an update that deletes a non-purgeable field with data.');
  } catch (FieldStorageDefinitionUpdateForbiddenException $e) {
    $this
      ->pass('FieldStorageDefinitionUpdateForbiddenException thrown when trying to apply an update that deletes a non-purgeable field with data.');
  }
}