public function EntityDefinitionUpdateTest::testBundleFieldCreateUpdateDeleteWithoutData in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/system/src/Tests/Entity/EntityDefinitionUpdateTest.php \Drupal\system\Tests\Entity\EntityDefinitionUpdateTest::testBundleFieldCreateUpdateDeleteWithoutData()
Tests creating, updating, and deleting a bundle field if no entities exist.
File
- core/
modules/ system/ src/ Tests/ Entity/ EntityDefinitionUpdateTest.php, line 214 - Contains \Drupal\system\Tests\Entity\EntityDefinitionUpdateTest.
Class
- EntityDefinitionUpdateTest
- Tests EntityDefinitionUpdateManager functionality.
Namespace
Drupal\system\Tests\EntityCode
public function testBundleFieldCreateUpdateDeleteWithoutData() {
// 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.');
$expected = array(
'entity_test_update' => array(
t('Create the %field_name field.', array(
'%field_name' => t('A new bundle field'),
)),
),
);
$this
->assertEqual($this->entityDefinitionUpdateManager
->getChangeSummary(), $expected, 'EntityDefinitionUpdateManager reports the expected change summary.');
$this->entityDefinitionUpdateManager
->applyUpdates();
$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.');
$expected = array(
'entity_test_update' => array(
t('Update the %field_name field.', array(
'%field_name' => t('A new bundle field'),
)),
),
);
$this
->assertEqual($this->entityDefinitionUpdateManager
->getChangeSummary(), $expected, 'EntityDefinitionUpdateManager reports the expected change summary.');
$this->entityDefinitionUpdateManager
->applyUpdates();
$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.');
$expected = array(
'entity_test_update' => array(
t('Delete the %field_name field.', array(
'%field_name' => t('A new bundle field'),
)),
),
);
$this
->assertEqual($this->entityDefinitionUpdateManager
->getChangeSummary(), $expected, 'EntityDefinitionUpdateManager reports the expected change summary.');
$this->entityDefinitionUpdateManager
->applyUpdates();
$this
->assertFalse($this->database
->schema()
->tableExists('entity_test_update__new_bundle_field'), 'Dedicated table deleted for new_bundle_field.');
}