public function EntityDisplayTest::testOnDependencyRemoval in Drupal 8
Same name and namespace in other branches
- 9 core/modules/field_ui/tests/src/Kernel/EntityDisplayTest.php \Drupal\Tests\field_ui\Kernel\EntityDisplayTest::testOnDependencyRemoval()
- 10 core/modules/field_ui/tests/src/Kernel/EntityDisplayTest.php \Drupal\Tests\field_ui\Kernel\EntityDisplayTest::testOnDependencyRemoval()
Tests \Drupal\Core\Entity\EntityDisplayBase::onDependencyRemoval().
File
- core/
modules/ field_ui/ tests/ src/ Kernel/ EntityDisplayTest.php, line 428
Class
- EntityDisplayTest
- Tests the entity display configuration entities.
Namespace
Drupal\Tests\field_ui\KernelCode
public function testOnDependencyRemoval() {
$this
->enableModules([
'field_plugins_test',
]);
$field_name = 'test_field';
// Create a field.
$field_storage = FieldStorageConfig::create([
'field_name' => $field_name,
'entity_type' => 'entity_test',
'type' => 'text',
]);
$field_storage
->save();
$field = FieldConfig::create([
'field_storage' => $field_storage,
'bundle' => 'entity_test',
]);
$field
->save();
EntityViewDisplay::create([
'targetEntityType' => 'entity_test',
'bundle' => 'entity_test',
'mode' => 'default',
])
->setComponent($field_name, [
'type' => 'field_plugins_test_text_formatter',
])
->save();
/** @var \Drupal\Core\Entity\EntityDisplayRepositoryInterface $display_repository */
$display_repository = \Drupal::service('entity_display.repository');
// Check the component exists and is of the correct type.
$display = $display_repository
->getViewDisplay('entity_test', 'entity_test');
$this
->assertEqual($display
->getComponent($field_name)['type'], 'field_plugins_test_text_formatter');
// Removing the field_plugins_test module should change the component to use
// the default formatter for test fields.
\Drupal::service('config.manager')
->uninstall('module', 'field_plugins_test');
$display = $display_repository
->getViewDisplay('entity_test', 'entity_test');
$this
->assertEqual($display
->getComponent($field_name)['type'], 'text_default');
// Removing the text module should remove the field from the view display.
\Drupal::service('config.manager')
->uninstall('module', 'text');
$display = $display_repository
->getViewDisplay('entity_test', 'entity_test');
$this
->assertNull($display
->getComponent($field_name));
}