You are here

public function EntityDisplayTest::testOnDependencyRemoval in Zircon Profile 8

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

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

File

core/modules/field_ui/src/Tests/EntityDisplayTest.php, line 376
Contains \Drupal\field_ui\Tests\EntityDisplayTest.

Class

EntityDisplayTest
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();
  EntityViewDisplay::create(array(
    'targetEntityType' => 'entity_test',
    'bundle' => 'entity_test',
    'mode' => 'default',
  ))
    ->setComponent($field_name, array(
    'type' => 'field_plugins_test_text_formatter',
  ))
    ->save();

  // Check the component exists and is of the correct type.
  $display = entity_get_display('entity_test', 'entity_test', 'default');
  $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 = entity_get_display('entity_test', 'entity_test', 'default');
  $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 = entity_get_display('entity_test', 'entity_test', 'default');
  $this
    ->assertFalse($display
    ->getComponent($field_name));
}