Updated to Drupal 8.6.4, which is PHP 7.3 friendly. Also updated HTMLaw library....
[yaffs-website] / web / core / modules / node / tests / src / Kernel / Views / RevisionRelationshipsTest.php
1 <?php
2
3 namespace Drupal\Tests\node\Kernel\Views;
4
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;
10
11 /**
12  * Tests the integration of node_revision table of node module.
13  *
14  * @group node
15  */
16 class RevisionRelationshipsTest extends ViewsKernelTestBase {
17
18   /**
19    * Modules to enable.
20    *
21    * @var array
22    */
23   public static $modules = ['node' , 'node_test_views'];
24
25   /**
26    * {@inheritdoc}
27    */
28   protected function setUp($import_test_views = TRUE) {
29     parent::setUp($import_test_views);
30
31     $this->installSchema('node', 'node_access');
32
33     $this->installEntitySchema('user');
34     $this->installEntitySchema('node');
35
36     ViewTestData::createTestViews(get_class($this), ['node_test_views']);
37   }
38
39   /**
40    * Views used by this test.
41    *
42    * @var array
43    */
44   public static $testViews = ['test_node_revision_nid', 'test_node_revision_vid'];
45
46   /**
47    * Create a node with revision and rest result count for both views.
48    */
49   public function testNodeRevisionRelationship() {
50     $type = NodeType::create(['type' => 'page', 'name' => 'page']);
51     $type->save();
52     $node = Node::create(['type' => 'page', 'title' => 'test', 'uid' => 1]);
53     $node->save();
54     // Create revision of the node.
55     $node->setNewRevision(TRUE);
56     $node->save();
57     $column_map = [
58       'vid' => 'vid',
59       'node_field_data_node_field_revision_nid' => 'node_node_revision_nid',
60       'nid_1' => 'nid_1',
61     ];
62
63     // Here should be two rows.
64     $view_nid = Views::getView('test_node_revision_nid');
65     $this->executeView($view_nid, [$node->id()]);
66     $resultset_nid = [
67       [
68         'vid' => '1',
69         'node_node_revision_nid' => '1',
70         'nid_1' => '1',
71       ],
72       [
73         'vid' => '2',
74         'node_revision_nid' => '1',
75         'node_node_revision_nid' => '1',
76         'nid_1' => '1',
77       ],
78     ];
79     $this->assertIdenticalResultset($view_nid, $resultset_nid, $column_map);
80
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()]);
84     $resultset_vid = [
85       [
86         'vid' => '2',
87         'node_node_revision_nid' => '1',
88         'nid_1' => '1',
89       ],
90     ];
91     $this->assertIdenticalResultset($view_vid, $resultset_vid, $column_map);
92   }
93
94 }