You are here

public function RevisionRelationships::testNodeRevisionRelationship in Views (for Drupal 7) 8.3

Create a node with revision and rest result count for both views.

File

lib/Drupal/views/Tests/Node/RevisionRelationships.php, line 27
Definition of Drupal\views\Tests\Node\RevisionRelationships.

Class

RevisionRelationships
Tests basic node_revision table integration into views.

Namespace

Drupal\views\Tests\Node

Code

public function testNodeRevisionRelationship() {
  $node = $this
    ->drupalCreateNode();

  // Create revision of the node.
  $node_revision = clone $node;
  $node_revision
    ->setNewRevision();
  $node_revision
    ->save();
  $column_map = array(
    'vid' => 'vid',
    'node_revision_nid' => 'node_revision_nid',
    'node_node_revision_nid' => 'node_node_revision_nid',
  );

  // Here should be two rows.
  $view_nid = $this
    ->createViewFromConfig('test_node_revision_nid');
  $this
    ->executeView($view_nid, array(
    $node->nid,
  ));
  $resultset_nid = array(
    array(
      'vid' => '1',
      'node_revision_nid' => '1',
      'node_node_revision_nid' => '1',
    ),
    array(
      'vid' => '2',
      'node_revision_nid' => '1',
      'node_node_revision_nid' => '1',
    ),
  );
  $this
    ->assertIdenticalResultset($view_nid, $resultset_nid, $column_map);

  // There should be only one row with active revision 2.
  $view_vid = $this
    ->createViewFromConfig('test_node_revision_vid');
  $this
    ->executeView($view_vid, array(
    $node->nid,
  ));
  $resultset_vid = array(
    array(
      'vid' => '2',
      'node_revision_nid' => '1',
      'node_node_revision_nid' => '1',
    ),
  );
  $this
    ->assertIdenticalResultset($view_vid, $resultset_vid, $column_map);
}