3 namespace Drupal\Tests\node\Kernel\Views;
5 use Drupal\node\Entity\Node;
6 use Drupal\node\Entity\NodeType;
7 use Drupal\Tests\views\Kernel\ViewsKernelTestBase;
8 use Drupal\views\Views;
9 use Drupal\views\Tests\ViewTestData;
12 * Tests the integration of node_revision table of node module.
16 class RevisionRelationshipsTest extends ViewsKernelTestBase {
23 public static $modules = ['node' , 'node_test_views'];
28 protected function setUp($import_test_views = TRUE) {
29 parent::setUp($import_test_views);
31 $this->installSchema('node', 'node_access');
33 $this->installEntitySchema('user');
34 $this->installEntitySchema('node');
36 ViewTestData::createTestViews(get_class($this), ['node_test_views']);
40 * Views used by this test.
44 public static $testViews = ['test_node_revision_nid', 'test_node_revision_vid'];
47 * Create a node with revision and rest result count for both views.
49 public function testNodeRevisionRelationship() {
50 $type = NodeType::create(['type' => 'page', 'name' => 'page']);
52 $node = Node::create(['type' => 'page', 'title' => 'test', 'uid' => 1]);
54 // Create revision of the node.
55 $node->setNewRevision(TRUE);
59 'node_field_data_node_field_revision_nid' => 'node_node_revision_nid',
63 // Here should be two rows.
64 $view_nid = Views::getView('test_node_revision_nid');
65 $this->executeView($view_nid, [$node->id()]);
69 'node_node_revision_nid' => '1',
74 'node_revision_nid' => '1',
75 'node_node_revision_nid' => '1',
79 $this->assertIdenticalResultset($view_nid, $resultset_nid, $column_map);
81 // There should be only one row with active revision 2.
82 $view_vid = Views::getView('test_node_revision_vid');
83 $this->executeView($view_vid, [$node->id()]);
87 'node_node_revision_nid' => '1',
91 $this->assertIdenticalResultset($view_vid, $resultset_vid, $column_map);