public function EntityDisplayTest::testDeleteField in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/field_ui/src/Tests/EntityDisplayTest.php \Drupal\field_ui\Tests\EntityDisplayTest::testDeleteField()
Tests deleting field.
File
- core/
modules/ field_ui/ src/ Tests/ EntityDisplayTest.php, line 329 - Contains \Drupal\field_ui\Tests\EntityDisplayTest.
Class
- EntityDisplayTest
- 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 teaser entity display.
EntityViewMode::create(array(
'id' => 'entity_test.teaser',
'targetEntityType' => 'entity_test',
))
->save();
EntityViewDisplay::create(array(
'targetEntityType' => 'entity_test',
'bundle' => 'entity_test',
'mode' => 'default',
))
->setComponent($field_name)
->save();
EntityViewDisplay::create(array(
'targetEntityType' => 'entity_test',
'bundle' => 'entity_test',
'mode' => 'teaser',
))
->setComponent($field_name)
->save();
// Check the component exists.
$display = entity_get_display('entity_test', 'entity_test', 'default');
$this
->assertTrue($display
->getComponent($field_name));
$display = entity_get_display('entity_test', 'entity_test', 'teaser');
$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_display('entity_test', 'entity_test', 'default');
$this
->assertFalse($display
->getComponent($field_name));
$display = entity_get_display('entity_test', 'entity_test', 'teaser');
$this
->assertFalse($display
->getComponent($field_name));
}