3 namespace Drupal\Tests\node\Kernel\Views;
5 use Drupal\language\Entity\ConfigurableLanguage;
6 use Drupal\node\Entity\Node;
7 use Drupal\node\Entity\NodeType;
8 use Drupal\Tests\views\Kernel\ViewsKernelTestBase;
9 use Drupal\views\Views;
10 use Drupal\views\Tests\ViewTestData;
13 * Tests the integration of node_revision table of node module.
17 class RevisionRelationshipsTest extends ViewsKernelTestBase {
24 public static $modules = [
28 'content_translation',
34 protected function setUp($import_test_views = TRUE) {
35 parent::setUp($import_test_views);
37 $this->installSchema('node', 'node_access');
39 $this->installEntitySchema('user');
40 $this->installEntitySchema('node');
42 ConfigurableLanguage::createFromLangcode('fr')->save();
44 ViewTestData::createTestViews(get_class($this), ['node_test_views']);
48 * Views used by this test.
52 public static $testViews = ['test_node_revision_nid', 'test_node_revision_vid'];
55 * Create a node with revision and rest result count for both views.
57 public function testNodeRevisionRelationship() {
58 $type = NodeType::create(['type' => 'page', 'name' => 'page']);
60 $node = Node::create(['type' => 'page', 'title' => 'test', 'uid' => 1]);
64 $translation = $node->addTranslation('fr', $node->toArray());
66 // Create revision of the node.
67 $node->setNewRevision(TRUE);
72 'node_field_data_node_field_revision_nid' => 'node_node_revision_nid',
74 'node_field_revision_langcode' => 'node_field_revision_langcode',
77 // Here should be two rows for each translation.
78 $view_nid = Views::getView('test_node_revision_nid');
79 $this->executeView($view_nid, [$node->id()]);
83 'node_node_revision_nid' => '1',
85 'node_field_revision_langcode' => 'fr',
89 'node_node_revision_nid' => '1',
91 'node_field_revision_langcode' => 'en',
95 'node_revision_nid' => '1',
96 'node_node_revision_nid' => '1',
98 'node_field_revision_langcode' => 'fr',
102 'node_revision_nid' => '1',
103 'node_node_revision_nid' => '1',
105 'node_field_revision_langcode' => 'en',
108 $this->assertIdenticalResultset($view_nid, $resultset_nid, $column_map);
110 // There should be one row with active revision 2 for each translation.
111 $view_vid = Views::getView('test_node_revision_vid');
112 $this->executeView($view_vid, [$node->id()]);
116 'node_node_revision_nid' => '1',
118 'node_field_revision_langcode' => 'en',
122 'node_node_revision_nid' => '1',
124 'node_field_revision_langcode' => 'fr',
127 $this->assertIdenticalResultset($view_vid, $resultset_vid, $column_map);