c9eb4ec9da7bdb4e47f6a154d4ec8cab545f3625
[yaffs-website] / DiffPluginEntityTest.php
1 <?php
2
3 namespace Drupal\diff\Tests;
4
5 use Drupal\field_ui\Tests\FieldUiTestTrait;
6
7 /**
8  * Tests the Diff module entity plugins.
9  *
10  * @group diff
11  */
12 class DiffPluginEntityTest extends DiffPluginTestBase {
13
14   use FieldUiTestTrait;
15
16   /**
17    * Modules to enable.
18    *
19    * @var array
20    */
21   public static $modules = [
22     'file',
23     'image',
24     'field_ui',
25   ];
26
27   /**
28    * The file system service.
29    *
30    * @var \Drupal\Core\File\FileSystemInterface
31    */
32   protected $fileSystem;
33
34   /**
35    * {@inheritdoc}
36    */
37   protected function setUp() {
38     parent::setUp();
39
40     $this->fileSystem = \Drupal::service('file_system');
41
42     // FieldUiTestTrait checks the breadcrumb when adding a field, so we need
43     // to show the breadcrumb block.
44     $this->drupalPlaceBlock('system_breadcrumb_block');
45   }
46
47   /**
48    * Tests the EntityReference plugin.
49    *
50    * @see \Drupal\diff\Plugin\diff\Field\EntityReferenceFieldBuilder
51    */
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);
60
61     // Create three article nodes.
62     $node1 = $this->drupalCreateNode([
63       'type' => 'article',
64       'title' => 'Article A',
65     ]);
66     $node2 = $this->drupalCreateNode([
67       'type' => 'article',
68       'title' => 'Article B',
69     ]);
70     $node3 = $this->drupalCreateNode([
71       'type' => 'article',
72       'title' => 'Article C',
73     ]);
74
75     // Reference article B in article A.
76     $edit = array(
77       'field_reference[0][target_id]' => 'Article B (' . $node2->id() . ')',
78       'revision' => TRUE,
79     );
80     $this->drupalPostForm('node/' . $node1->id() . '/edit', $edit, t('Save and keep published'));
81
82     // Update article A so it points to article C instead of B.
83     $edit = array(
84       'field_reference[0][target_id]' => 'Article C (' . $node3->id() . ')',
85       'revision' => TRUE,
86     );
87     $this->drupalPostForm('node/' . $node1->id() . '/edit', $edit, t('Save and keep published'));
88
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');
95   }
96
97 }