You are here

public function EntityReferenceRevisionsAdminTest::testMultipleTargetBundles in Entity Reference Revisions 8

Tests target bundle settings for an entity reference revisions field.

File

tests/src/Functional/EntityReferenceRevisionsAdminTest.php, line 161

Class

EntityReferenceRevisionsAdminTest
Tests the entity_reference_revisions configuration.

Namespace

Drupal\Tests\entity_reference_revisions\Functional

Code

public function testMultipleTargetBundles() {

  // Create a couple of content types for the ERR field to point to.
  $target_types = [];
  for ($i = 0; $i < 2; $i++) {
    $target_types[$i] = $this
      ->drupalCreateContentType([
      'type' => strtolower($this
        ->randomMachineName()),
      'name' => 'Test type ' . $i,
    ]);
  }

  // Create a new field that can point to either target content type.
  $node_type_path = 'admin/structure/types/manage/entity_revisions';

  // Generate a random field name, must be only lowercase characters.
  $field_name = strtolower($this
    ->randomMachineName());
  $field_edit = [];
  $storage_edit = [
    'settings[target_type]' => 'node',
    'cardinality' => '-1',
  ];
  $field_edit['settings[handler_settings][target_bundles][' . $target_types[0]
    ->id() . ']'] = TRUE;
  $field_edit['settings[handler_settings][target_bundles][' . $target_types[1]
    ->id() . ']'] = TRUE;
  $this
    ->fieldUIAddNewField($node_type_path, $field_name, 'Entity reference revisions', 'entity_reference_revisions', $storage_edit, $field_edit);

  // Deleting one of these content bundles at this point should only delete
  // that bundle's body field. Test that there is no second field that will
  // be deleted.
  $this
    ->drupalGet('/admin/structure/types/manage/' . $target_types[0]
    ->id() . '/delete');
  $this
    ->assertNoFieldByXPath('(//details[@id="edit-entity-deletes"]//ul[@data-drupal-selector="edit-field-config"]/li)[2]');
}