function EntityDefinitionUpdateTest::testBundleFieldCreateUpdateDeleteWithoutData
Same name in other branches
- 9 core/tests/Drupal/KernelTests/Core/Entity/EntityDefinitionUpdateTest.php \Drupal\KernelTests\Core\Entity\EntityDefinitionUpdateTest::testBundleFieldCreateUpdateDeleteWithoutData()
- 8.9.x core/tests/Drupal/KernelTests/Core/Entity/EntityDefinitionUpdateTest.php \Drupal\KernelTests\Core\Entity\EntityDefinitionUpdateTest::testBundleFieldCreateUpdateDeleteWithoutData()
- 11.x core/tests/Drupal/KernelTests/Core/Entity/EntityDefinitionUpdateTest.php \Drupal\KernelTests\Core\Entity\EntityDefinitionUpdateTest::testBundleFieldCreateUpdateDeleteWithoutData()
Tests creating, updating, and deleting a bundle field if no entities exist.
File
-
core/
tests/ Drupal/ KernelTests/ Core/ Entity/ EntityDefinitionUpdateTest.php, line 362
Class
- EntityDefinitionUpdateTest
- Tests EntityDefinitionUpdateManager functionality.
Namespace
Drupal\KernelTests\Core\EntityCode
public function testBundleFieldCreateUpdateDeleteWithoutData() : void {
// Add a bundle field, ensure the update manager reports it, and the update
// creates its schema.
$this->addBundleField();
$this->assertTrue($this->entityDefinitionUpdateManager
->needsUpdates(), 'EntityDefinitionUpdateManager reports that updates are needed.');
$changes = $this->entityDefinitionUpdateManager
->getChangeSummary();
$this->assertCount(1, $changes['entity_test_update']);
$this->assertEquals('The A new bundle field field needs to be installed.', strip_tags((string) $changes['entity_test_update'][0]));
$this->applyEntityUpdates();
$this->assertTrue($this->database
->schema()
->tableExists('entity_test_update__new_bundle_field'), 'Dedicated table created for new_bundle_field.');
// Update the type of the base field from 'string' to 'text', ensure the
// update manager reports it, and the update adjusts the schema
// accordingly.
$this->modifyBundleField();
$this->assertTrue($this->entityDefinitionUpdateManager
->needsUpdates(), 'EntityDefinitionUpdateManager reports that updates are needed.');
$changes = $this->entityDefinitionUpdateManager
->getChangeSummary();
$this->assertCount(1, $changes['entity_test_update']);
$this->assertEquals('The A new bundle field field needs to be updated.', strip_tags((string) $changes['entity_test_update'][0]));
$this->applyEntityUpdates();
$this->assertTrue($this->database
->schema()
->fieldExists('entity_test_update__new_bundle_field', 'new_bundle_field_format'), 'Format column created in dedicated table for new_base_field.');
// Remove the bundle field, ensure the update manager reports it, and the
// update deletes the schema.
$this->removeBundleField();
$this->assertTrue($this->entityDefinitionUpdateManager
->needsUpdates(), 'EntityDefinitionUpdateManager reports that updates are needed.');
$changes = $this->entityDefinitionUpdateManager
->getChangeSummary();
$this->assertCount(1, $changes['entity_test_update']);
$this->assertEquals('The A new bundle field field needs to be uninstalled.', strip_tags((string) $changes['entity_test_update'][0]));
$this->applyEntityUpdates();
$this->assertFalse($this->database
->schema()
->tableExists('entity_test_update__new_bundle_field'), 'Dedicated table deleted for new_bundle_field.');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.