function ViewsDataIntegrationTest::testContentModerationStateBaseJoin

Tests the join from the data table to the moderation state table.

File

core/modules/content_moderation/tests/src/Kernel/ViewsDataIntegrationTest.php, line 94

Class

ViewsDataIntegrationTest
Tests the views integration of content_moderation.

Namespace

Drupal\Tests\content_moderation\Kernel

Code

public function testContentModerationStateBaseJoin() {
  $node = Node::create([
    'type' => 'page',
    'title' => 'Test title first revision',
  ]);
  $node->moderation_state->value = 'published';
  $node->save();
  $revision = clone $node;
  $revision->setNewRevision(TRUE);
  $revision->isDefaultRevision(FALSE);
  $revision->title->value = 'Test title second revision';
  $revision->moderation_state->value = 'draft';
  $revision->save();
  $view = Views::getView('test_content_moderation_base_table_test');
  $view->execute();
  $expected_result = [
    [
      'nid' => $node->id(),
      // Joins from the base table to the default revision of the
      // content_moderation.
'moderation_state' => 'published',
      // Joins from the revision table to the default revision of the
      // content_moderation.
'moderation_state_1' => 'published',
      // Joins from the revision table to the revision of the
      // content_moderation.
'moderation_state_2' => 'published',
    ],
  ];
  $this->assertIdenticalResultset($view, $expected_result, [
    'nid' => 'nid',
    'moderation_state' => 'moderation_state',
    'moderation_state_1' => 'moderation_state_1',
    'moderation_state_2' => 'moderation_state_2',
  ]);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.