You are here

public function EntityFormDisplayTest::testOnDependencyRemoval in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/field_ui/src/Tests/EntityFormDisplayTest.php \Drupal\field_ui\Tests\EntityFormDisplayTest::testOnDependencyRemoval()

Tests \Drupal\Core\Entity\EntityDisplayBase::onDependencyRemoval().

File

core/modules/field_ui/src/Tests/EntityFormDisplayTest.php, line 232
Contains \Drupal\field_ui\Tests\EntityFormDisplayTest.

Class

EntityFormDisplayTest
Tests the entity display configuration entities.

Namespace

Drupal\field_ui\Tests

Code

public function testOnDependencyRemoval() {
  $this
    ->enableModules(array(
    'field_plugins_test',
  ));
  $field_name = 'test_field';

  // Create a field.
  $field_storage = FieldStorageConfig::create(array(
    'field_name' => $field_name,
    'entity_type' => 'entity_test',
    'type' => 'text',
  ));
  $field_storage
    ->save();
  $field = FieldConfig::create(array(
    'field_storage' => $field_storage,
    'bundle' => 'entity_test',
  ));
  $field
    ->save();
  EntityFormDisplay::create(array(
    'targetEntityType' => 'entity_test',
    'bundle' => 'entity_test',
    'mode' => 'default',
  ))
    ->setComponent($field_name, array(
    'type' => 'field_plugins_test_text_widget',
  ))
    ->save();

  // Check the component exists and is of the correct type.
  $display = entity_get_form_display('entity_test', 'entity_test', 'default');
  $this
    ->assertEqual($display
    ->getComponent($field_name)['type'], 'field_plugins_test_text_widget');

  // Removing the field_plugins_test module should change the component to use
  // the default widget for test fields.
  \Drupal::service('config.manager')
    ->uninstall('module', 'field_plugins_test');
  $display = entity_get_form_display('entity_test', 'entity_test', 'default');
  $this
    ->assertEqual($display
    ->getComponent($field_name)['type'], 'text_textfield');

  // Removing the text module should remove the field from the form display.
  \Drupal::service('config.manager')
    ->uninstall('module', 'text');
  $display = entity_get_form_display('entity_test', 'entity_test', 'default');
  $this
    ->assertFalse($display
    ->getComponent($field_name));
}