function FieldCrudTest::testDeleteFieldCrossDeletion in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/field/src/Tests/FieldCrudTest.php \Drupal\field\Tests\FieldCrudTest::testDeleteFieldCrossDeletion()
Tests the cross deletion behavior between field storages and fields.
File
- core/
modules/ field/ src/ Tests/ FieldCrudTest.php, line 251 - Contains \Drupal\field\Tests\FieldCrudTest.
Class
- FieldCrudTest
- Create field entities by attaching fields to entities.
Namespace
Drupal\field\TestsCode
function testDeleteFieldCrossDeletion() {
$field_definition_2 = $this->fieldDefinition;
$field_definition_2['bundle'] .= '_another_bundle';
entity_test_create_bundle($field_definition_2['bundle']);
// Check that deletion of a field storage deletes its fields.
$field_storage = $this->fieldStorage;
entity_create('field_config', $this->fieldDefinition)
->save();
entity_create('field_config', $field_definition_2)
->save();
$field_storage
->delete();
$this
->assertFalse(FieldConfig::loadByName('entity_test', $this->fieldDefinition['bundle'], $field_storage
->getName()));
$this
->assertFalse(FieldConfig::loadByName('entity_test', $field_definition_2['bundle'], $field_storage
->getName()));
// Check that deletion of the last field deletes the storage.
$field_storage = entity_create('field_storage_config', $this->fieldStorageDefinition);
$field_storage
->save();
$field = entity_create('field_config', $this->fieldDefinition);
$field
->save();
$field_2 = entity_create('field_config', $field_definition_2);
$field_2
->save();
$field
->delete();
$this
->assertTrue(FieldStorageConfig::loadByName('entity_test', $field_storage
->getName()));
$field_2
->delete();
$this
->assertFalse(FieldStorageConfig::loadByName('entity_test', $field_storage
->getName()));
// Check that deletion of all fields using a storage simultaneously deletes
// the storage.
$field_storage = entity_create('field_storage_config', $this->fieldStorageDefinition);
$field_storage
->save();
$field = entity_create('field_config', $this->fieldDefinition);
$field
->save();
$field_2 = entity_create('field_config', $field_definition_2);
$field_2
->save();
$this->container
->get('entity.manager')
->getStorage('field_config')
->delete(array(
$field,
$field_2,
));
$this
->assertFalse(FieldStorageConfig::loadByName('entity_test', $field_storage
->getName()));
}