function EntityDefinitionUpdateBundleTest::testBundleFieldUpdateWithExistingData
Same name and namespace in other branches
- 11.x core/tests/Drupal/KernelTests/Core/Entity/EntityDefinitionUpdateBundleTest.php \Drupal\KernelTests\Core\Entity\EntityDefinitionUpdateBundleTest::testBundleFieldUpdateWithExistingData()
Tests updating a bundle field when it has existing data.
File
-
core/
tests/ Drupal/ KernelTests/ Core/ Entity/ EntityDefinitionUpdateBundleTest.php, line 240
Class
- EntityDefinitionUpdateBundleTest
- Tests EntityDefinitionUpdateManager functionality.
Namespace
Drupal\KernelTests\Core\EntityCode
public function testBundleFieldUpdateWithExistingData() : void {
// Add the bundle field and run the update.
$this->addBundleField();
$this->applyEntityUpdates();
// Save an entity with the bundle field populated.
EntityTestHelper::createBundle('custom');
$this->entityTypeManager
->getStorage('entity_test_update')
->create([
'type' => 'test_bundle',
'new_bundle_field' => 'foo',
])
->save();
// Change the field's field type and apply updates. It's expected to
// throw an exception.
$this->modifyBundleField();
try {
$this->applyEntityUpdates();
$this->fail('FieldStorageDefinitionUpdateForbiddenException thrown when trying to update a field schema that has data.');
} catch (FieldStorageDefinitionUpdateForbiddenException) {
// Expected exception; just continue testing.
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.