You are here

public function EntityReferenceRevisionsAutocompleteTest::testEntityReferenceRevisionsAutocompleteProcessing in Entity Reference Revisions 8

Test for autocomplete processing.

Tests that processing does not crash when the entity types of the referenced entity and of the entity the field is attached to are different.

File

tests/src/Functional/EntityReferenceRevisionsAutocompleteTest.php, line 55

Class

EntityReferenceRevisionsAutocompleteTest
Tests the entity_reference_revisions autocomplete.

Namespace

Drupal\Tests\entity_reference_revisions\Functional

Code

public function testEntityReferenceRevisionsAutocompleteProcessing() {
  $admin_user = $this
    ->drupalCreateUser(array(
    'administer site configuration',
    'administer nodes',
    'administer blocks',
    'create article content',
    'administer content types',
    'administer node fields',
    'administer node display',
    'administer node form display',
    'edit any article content',
  ));
  $this
    ->drupalLogin($admin_user);

  // Create a custom block content bundle.
  $this
    ->createBlockContentType(array(
    'type' => 'customblockcontent',
    'name' => 'Custom Block Content',
  ));

  // Create entity reference revisions field attached to article.
  static::fieldUIAddNewField('admin/structure/types/manage/article', 'entity_reference_revisions', 'Entity reference revisions', 'entity_reference_revisions', array(
    'settings[target_type]' => 'block_content',
    'cardinality' => '-1',
  ), array(
    'settings[handler_settings][target_bundles][customblockcontent]' => TRUE,
  ));

  // Create custom block.
  $block_label = $this
    ->randomMachineName();
  $block_content = $this
    ->randomString();
  $edit = array(
    'info[0][value]' => $block_label,
    'body[0][value]' => $block_content,
  );
  $this
    ->drupalGet('block/add');
  $this
    ->submitForm($edit, 'Save');
  $block = $this
    ->drupalGetBlockByInfo($block_label);

  // Create an article.
  $title = $this
    ->randomMachineName();
  $edit = array(
    'title[0][value]' => $title,
    'body[0][value]' => 'Revision 1',
    'field_entity_reference_revisions[0][target_id]' => $block_label . ' (' . $block
      ->id() . ')',
  );
  $this
    ->drupalGet('node/add/article');
  $this
    ->submitForm($edit, 'Save');
  $this
    ->assertText($title);
  $this
    ->assertText(Html::escape($block_content));

  // Check if the block content is not deleted since there is no composite
  // relationship.
  $node = $this
    ->drupalGetNodeByTitle($edit['title[0][value]']);
  $node = Node::load($node
    ->id());
  $node
    ->delete();
  $this
    ->assertNotNull(BlockContent::load($block
    ->id()));
}