You are here

public function ViewsDataIntegrationTest::testViewsData in Workbench Moderation 8

Test views data.

File

tests/src/Kernel/ViewsDataIntegrationTest.php, line 41

Class

ViewsDataIntegrationTest
Tests the views integration of workbench_moderation.

Namespace

Drupal\Tests\workbench_moderation\Kernel

Code

public function testViewsData() {
  $node_type = NodeType::create([
    'type' => 'page',
  ]);
  $node_type
    ->setThirdPartySetting('workbench_moderation', 'enabled', TRUE);
  $node_type
    ->save();
  $node = Node::create([
    'type' => 'page',
    'title' => 'Test title first revision',
    'moderation_state' => 'published',
  ]);
  $node
    ->save();
  $revision = clone $node;
  $revision
    ->setNewRevision(TRUE);
  $revision
    ->isDefaultRevision(FALSE);
  $revision->title->value = 'Test title second revision';
  $revision->moderation_state->target_id = 'draft';
  $revision
    ->save();
  $view = Views::getView('test_workbench_moderation_latest_revision');
  $view
    ->execute();

  // Ensure that the workbench_revision_tracker contains the right latest
  // revision ID.
  // Also ensure that the relationship back to the revision table contains the
  // right latest revision.
  $expected_result = [
    [
      'nid' => $node
        ->id(),
      'revision_id' => $revision
        ->getRevisionId(),
      'title' => $revision
        ->label(),
      'moderation_state_revision' => 'draft',
      'moderation_state' => 'published',
    ],
  ];
  $this
    ->assertIdenticalResultset($view, $expected_result, [
    'title' => 'title',
    'nid' => 'nid',
    'workbench_revision_tracker_revision_id' => 'revision_id',
    'moderation_state_revision' => 'moderation_state_revision',
    'moderation_state' => 'moderation_state',
  ]);
}