public function EntityFormDisplayTest::testDeleteField in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/field_ui/src/Tests/EntityFormDisplayTest.php \Drupal\field_ui\Tests\EntityFormDisplayTest::testDeleteField()
Tests deleting field.
File
- core/
modules/ field_ui/ src/ Tests/ EntityFormDisplayTest.php, line 185 - Contains \Drupal\field_ui\Tests\EntityFormDisplayTest.
Class
- EntityFormDisplayTest
- Tests the entity display configuration entities.
Namespace
Drupal\field_ui\TestsCode
public function testDeleteField() {
$field_name = 'test_field';
// Create a field storage and a field.
$field_storage = FieldStorageConfig::create(array(
'field_name' => $field_name,
'entity_type' => 'entity_test',
'type' => 'test_field',
));
$field_storage
->save();
$field = FieldConfig::create(array(
'field_storage' => $field_storage,
'bundle' => 'entity_test',
));
$field
->save();
// Create default and compact entity display.
EntityFormMode::create(array(
'id' => 'entity_test.compact',
'targetEntityType' => 'entity_test',
))
->save();
EntityFormDisplay::create(array(
'targetEntityType' => 'entity_test',
'bundle' => 'entity_test',
'mode' => 'default',
))
->setComponent($field_name)
->save();
EntityFormDisplay::create(array(
'targetEntityType' => 'entity_test',
'bundle' => 'entity_test',
'mode' => 'compact',
))
->setComponent($field_name)
->save();
// Check the component exists.
$display = entity_get_form_display('entity_test', 'entity_test', 'default');
$this
->assertTrue($display
->getComponent($field_name));
$display = entity_get_form_display('entity_test', 'entity_test', 'compact');
$this
->assertTrue($display
->getComponent($field_name));
// Delete the field.
$field
->delete();
// Check that the component has been removed from the entity displays.
$display = entity_get_form_display('entity_test', 'entity_test', 'default');
$this
->assertFalse($display
->getComponent($field_name));
$display = entity_get_form_display('entity_test', 'entity_test', 'compact');
$this
->assertFalse($display
->getComponent($field_name));
}