You are here

public function EntityReferenceSettingsTest::testCustomTargetBundleDeletion in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/field/src/Tests/EntityReference/EntityReferenceSettingsTest.php \Drupal\field\Tests\EntityReference\EntityReferenceSettingsTest::testCustomTargetBundleDeletion()

Tests that deletions of custom bundles are mirrored in field settings.

File

core/modules/field/src/Tests/EntityReference/EntityReferenceSettingsTest.php, line 107
Contains \Drupal\field\Tests\EntityReference\EntityReferenceSettingsTest.

Class

EntityReferenceSettingsTest
Tests entity reference field settings.

Namespace

Drupal\field\Tests\EntityReference

Code

public function testCustomTargetBundleDeletion() {

  // Attach an entity reference field to $this->nodeType.
  $name = Unicode::strtolower($this
    ->randomMachineName());
  $label = $this
    ->randomString();
  $handler_settings = [
    'target_bundles' => [
      $this->customBundle => $this->customBundle,
    ],
  ];
  $this
    ->createEntityReferenceField('node', $this->nodeType
    ->id(), $name, $label, 'entity_test', 'default', $handler_settings);

  // Check that the 'target_bundle' setting contains the custom bundle.
  $field_config = FieldConfig::loadByName('node', $this->nodeType
    ->id(), $name);
  $actual_handler_settings = $field_config
    ->getSetting('handler_settings');
  $this
    ->assertEqual($handler_settings, $actual_handler_settings);

  // Delete the custom bundle.
  entity_test_delete_bundle($this->customBundle, 'entity_test');

  // Check that the deleted bundle is no longer present in the
  // 'target_bundles' field setting.
  $field_config = FieldConfig::loadByName('node', $this->nodeType
    ->id(), $name);
  $handler_settings = $field_config
    ->getSetting('handler_settings');
  $this
    ->assertTrue(empty($handler_settings['target_bundles']));
}