3 namespace Drupal\diff\Tests;
5 use Drupal\field_ui\Tests\FieldUiTestTrait;
8 * Tests the Diff module entity plugins.
12 class DiffPluginEntityTest extends DiffPluginTestBase {
21 public static $modules = [
28 * The file system service.
30 * @var \Drupal\Core\File\FileSystemInterface
32 protected $fileSystem;
37 protected function setUp() {
40 $this->fileSystem = \Drupal::service('file_system');
42 // FieldUiTestTrait checks the breadcrumb when adding a field, so we need
43 // to show the breadcrumb block.
44 $this->drupalPlaceBlock('system_breadcrumb_block');
48 * Tests the EntityReference plugin.
50 * @see \Drupal\diff\Plugin\diff\Field\EntityReferenceFieldBuilder
52 public function testEntityReferencePlugin() {
53 // Add an entity reference field to the article content type.
54 $bundle_path = 'admin/structure/types/manage/article';
55 $field_name = 'reference';
56 $storage_edit = $field_edit = array();
57 $storage_edit['settings[target_type]'] = 'node';
58 $field_edit['settings[handler_settings][target_bundles][article]'] = TRUE;
59 $this->fieldUIAddNewField($bundle_path, $field_name, 'Reference', 'entity_reference', $storage_edit, $field_edit);
61 // Create three article nodes.
62 $node1 = $this->drupalCreateNode([
64 'title' => 'Article A',
66 $node2 = $this->drupalCreateNode([
68 'title' => 'Article B',
70 $node3 = $this->drupalCreateNode([
72 'title' => 'Article C',
75 // Reference article B in article A.
77 'field_reference[0][target_id]' => 'Article B (' . $node2->id() . ')',
80 $this->drupalPostForm('node/' . $node1->id() . '/edit', $edit, t('Save and keep published'));
82 // Update article A so it points to article C instead of B.
84 'field_reference[0][target_id]' => 'Article C (' . $node3->id() . ')',
87 $this->drupalPostForm('node/' . $node1->id() . '/edit', $edit, t('Save and keep published'));
89 // Check differences between revisions.
90 $this->clickLink(t('Revisions'));
91 $this->drupalPostForm(NULL, NULL, t('Compare selected revisions'));
92 $this->assertText('Reference');
93 $this->assertText('Article B');
94 $this->assertText('Article C');