You are here

protected function ViewsModerationStateFilterTest::assertNodesWithFilters in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/content_moderation/tests/src/Kernel/ViewsModerationStateFilterTest.php \Drupal\Tests\content_moderation\Kernel\ViewsModerationStateFilterTest::assertNodesWithFilters()

Assert the nodes appear when the test view is executed.

Parameters

\Drupal\node\NodeInterface[] $nodes: Nodes to assert are in the views result.

array $filters: An array of filters to apply to the view.

string $view_id: The view to execute for the results.

1 call to ViewsModerationStateFilterTest::assertNodesWithFilters()
ViewsModerationStateFilterTest::testStateFilterViewsRelationship in core/modules/content_moderation/tests/src/Kernel/ViewsModerationStateFilterTest.php
Tests the content moderation state filter.

File

core/modules/content_moderation/tests/src/Kernel/ViewsModerationStateFilterTest.php, line 342

Class

ViewsModerationStateFilterTest
Tests the views 'moderation_state_filter' filter plugin.

Namespace

Drupal\Tests\content_moderation\Kernel

Code

protected function assertNodesWithFilters(array $nodes, array $filters, $view_id = 'test_content_moderation_state_filter_base_table') {
  $view = Views::getView($view_id);
  $view
    ->setExposedInput($filters);
  $view
    ->execute();

  // Verify the join configuration.
  $query = $view
    ->getQuery();
  $join = $query
    ->getTableInfo('content_moderation_state')['join'];
  $configuration = $join->configuration;
  $this
    ->assertEquals('content_moderation_state_field_revision', $configuration['table']);
  $this
    ->assertEquals('content_entity_revision_id', $configuration['field']);
  $this
    ->assertEquals('vid', $configuration['left_field']);
  $this
    ->assertEquals('content_entity_type_id', $configuration['extra'][0]['field']);
  $this
    ->assertEquals('node', $configuration['extra'][0]['value']);
  $this
    ->assertEquals('content_entity_id', $configuration['extra'][1]['field']);
  $this
    ->assertEquals('nid', $configuration['extra'][1]['left_field']);
  $this
    ->assertEquals('langcode', $configuration['extra'][2]['field']);
  $this
    ->assertEquals('langcode', $configuration['extra'][2]['left_field']);
  $expected_result = [];
  foreach ($nodes as $node) {
    $expected_result[] = [
      'nid' => $node
        ->id(),
    ];
  }
  $this
    ->assertIdenticalResultset($view, $expected_result, [
    'nid' => 'nid',
  ]);
}