public function ManageFieldsFunctionalTest::testDeleteField in Drupal 9
Same name and namespace in other branches
- 8 core/modules/field_ui/tests/src/Functional/ManageFieldsFunctionalTest.php \Drupal\Tests\field_ui\Functional\ManageFieldsFunctionalTest::testDeleteField()
- 10 core/modules/field_ui/tests/src/Functional/ManageFieldsFunctionalTest.php \Drupal\Tests\field_ui\Functional\ManageFieldsFunctionalTest::testDeleteField()
Tests that deletion removes field storages and fields as expected.
File
- core/
modules/ field_ui/ tests/ src/ Functional/ ManageFieldsFunctionalTest.php, line 577
Class
- ManageFieldsFunctionalTest
- Tests the Field UI "Manage fields" screen.
Namespace
Drupal\Tests\field_ui\FunctionalCode
public 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([
'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.');
}