You are here

public function NodeRevisionWizardTest::testViewAdd in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/node/src/Tests/Views/NodeRevisionWizardTest.php \Drupal\node\Tests\Views\NodeRevisionWizardTest::testViewAdd()

Tests creating a node revision view.

File

core/modules/node/src/Tests/Views/NodeRevisionWizardTest.php, line 24
Contains \Drupal\node\Tests\Views\NodeRevisionWizardTest.

Class

NodeRevisionWizardTest
Tests the wizard with node_revision as base table.

Namespace

Drupal\node\Tests\Views

Code

public function testViewAdd() {
  $this
    ->drupalCreateContentType(array(
    'type' => 'article',
  ));

  // Create two nodes with two revision.
  $node_storage = \Drupal::entityManager()
    ->getStorage('node');

  /** @var \Drupal\node\NodeInterface $node */
  $node = $node_storage
    ->create(array(
    'title' => $this
      ->randomString(),
    'type' => 'article',
    'created' => REQUEST_TIME + 40,
  ));
  $node
    ->save();
  $node = $node
    ->createDuplicate();
  $node
    ->setNewRevision();
  $node->created->value = REQUEST_TIME + 20;
  $node
    ->save();
  $node = $node_storage
    ->create(array(
    'title' => $this
      ->randomString(),
    'type' => 'article',
    'created' => REQUEST_TIME + 30,
  ));
  $node
    ->save();
  $node = $node
    ->createDuplicate();
  $node
    ->setNewRevision();
  $node->created->value = REQUEST_TIME + 10;
  $node
    ->save();
  $view = array();
  $view['label'] = $this
    ->randomMachineName(16);
  $view['id'] = strtolower($this
    ->randomMachineName(16));
  $view['description'] = $this
    ->randomMachineName(16);
  $view['page[create]'] = FALSE;
  $view['show[wizard_key]'] = 'node_revision';
  $this
    ->drupalPostForm('admin/structure/views/add', $view, t('Save and edit'));
  $view_storage_controller = \Drupal::entityManager()
    ->getStorage('view');

  /** @var \Drupal\views\Entity\View $view */
  $view = $view_storage_controller
    ->load($view['id']);
  $this
    ->assertEqual($view
    ->get('base_table'), 'node_field_revision');
  $executable = Views::executableFactory()
    ->get($view);
  $this
    ->executeView($executable);
  $this
    ->assertIdenticalResultset($executable, array(
    array(
      'vid' => 1,
    ),
    array(
      'vid' => 3,
    ),
    array(
      'vid' => 2,
    ),
    array(
      'vid' => 4,
    ),
  ), array(
    'vid' => 'vid',
  ));
}