You are here

public function DiffPluginEntityTest::testEntityReferencePlugin in Diff 8

Tests the EntityReference plugin.

See also

\Drupal\diff\Plugin\diff\Field\EntityReferenceFieldBuilder

File

tests/src/Functional/DiffPluginEntityTest.php, line 51

Class

DiffPluginEntityTest
Tests the Diff module entity plugins.

Namespace

Drupal\Tests\diff\Functional

Code

public function testEntityReferencePlugin() {

  // Add an entity reference field to the article content type.
  $bundle_path = 'admin/structure/types/manage/article';
  $field_name = 'reference';
  $storage_edit = $field_edit = array();
  $storage_edit['settings[target_type]'] = 'node';
  $field_edit['settings[handler_settings][target_bundles][article]'] = TRUE;
  $this
    ->fieldUIAddNewField($bundle_path, $field_name, 'Reference', 'entity_reference', $storage_edit, $field_edit);

  // Create three article nodes.
  $node1 = $this
    ->drupalCreateNode([
    'type' => 'article',
    'title' => 'Article A',
  ]);
  $node2 = $this
    ->drupalCreateNode([
    'type' => 'article',
    'title' => 'Article B',
  ]);
  $node3 = $this
    ->drupalCreateNode([
    'type' => 'article',
    'title' => 'Article C',
  ]);

  // Reference article B in article A.
  $edit = array(
    'field_reference[0][target_id]' => 'Article B (' . $node2
      ->id() . ')',
    'revision' => TRUE,
  );
  $this
    ->drupalPostNodeForm('node/' . $node1
    ->id() . '/edit', $edit, t('Save and keep published'));

  // Update article A so it points to article C instead of B.
  $edit = array(
    'field_reference[0][target_id]' => 'Article C (' . $node3
      ->id() . ')',
    'revision' => TRUE,
  );
  $this
    ->drupalPostNodeForm('node/' . $node1
    ->id() . '/edit', $edit, t('Save and keep published'));

  // Check differences between revisions.
  $this
    ->clickLink(t('Revisions'));
  $this
    ->drupalPostForm(NULL, NULL, t('Compare selected revisions'));
  $this
    ->assertText('Reference');
  $this
    ->assertText('Article B');
  $this
    ->assertText('Article C');
}