function ManageFieldsTest::testDeleteField in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/field_ui/src/Tests/ManageFieldsTest.php \Drupal\field_ui\Tests\ManageFieldsTest::testDeleteField()
Tests that deletion removes field storages and fields as expected.
File
- core/
modules/ field_ui/ src/ Tests/ ManageFieldsTest.php, line 448 - Contains \Drupal\field_ui\Tests\ManageFieldsTest.
Class
- ManageFieldsTest
- Tests the Field UI "Manage fields" screen.
Namespace
Drupal\field_ui\TestsCode
function testDeleteField() {
// Create a new field.
$bundle_path1 = 'admin/structure/types/manage/' . $this->contentType;
$this
->fieldUIAddNewField($bundle_path1, $this->fieldNameInput, $this->fieldLabel);
// Create an additional node type.
$type_name2 = strtolower($this
->randomMachineName(8)) . '_test';
$type2 = $this
->drupalCreateContentType(array(
'name' => $type_name2,
'type' => $type_name2,
));
$type_name2 = $type2
->id();
// Add a field to the second node type.
$bundle_path2 = 'admin/structure/types/manage/' . $type_name2;
$this
->fieldUIAddExistingField($bundle_path2, $this->fieldName, $this->fieldLabel);
// Delete the first field.
$this
->fieldUIDeleteField($bundle_path1, "node.{$this->contentType}.{$this->fieldName}", $this->fieldLabel, $this->contentType);
// Check that the field was deleted.
$this
->assertNull(FieldConfig::loadByName('node', $this->contentType, $this->fieldName), 'Field was deleted.');
// Check that the field storage was not deleted
$this
->assertNotNull(FieldStorageConfig::loadByName('node', $this->fieldName), 'Field storage was not deleted.');
// Delete the second field.
$this
->fieldUIDeleteField($bundle_path2, "node.{$type_name2}.{$this->fieldName}", $this->fieldLabel, $type_name2);
// Check that the field was deleted.
$this
->assertNull(FieldConfig::loadByName('node', $type_name2, $this->fieldName), 'Field was deleted.');
// Check that the field storage was deleted too.
$this
->assertNull(FieldStorageConfig::loadByName('node', $this->fieldName), 'Field storage was deleted.');
}