function ViewsModerationStateFilterTest::testModerationStateFilterOnJoinedEntity

Same name and namespace in other branches
  1. 9 core/modules/content_moderation/tests/src/Kernel/ViewsModerationStateFilterTest.php \Drupal\Tests\content_moderation\Kernel\ViewsModerationStateFilterTest::testModerationStateFilterOnJoinedEntity()
  2. 8.9.x core/modules/content_moderation/tests/src/Kernel/ViewsModerationStateFilterTest.php \Drupal\Tests\content_moderation\Kernel\ViewsModerationStateFilterTest::testModerationStateFilterOnJoinedEntity()
  3. 10 core/modules/content_moderation/tests/src/Kernel/ViewsModerationStateFilterTest.php \Drupal\Tests\content_moderation\Kernel\ViewsModerationStateFilterTest::testModerationStateFilterOnJoinedEntity()

Tests the moderation state filter on an entity added via a relationship.

File

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

Class

ViewsModerationStateFilterTest
Tests the views 'moderation_state_filter' filter plugin.

Namespace

Drupal\Tests\content_moderation\Kernel

Code

public function testModerationStateFilterOnJoinedEntity() : void {
  $workflow = Workflow::load('editorial');
  $workflow->getTypePlugin()
    ->addEntityTypeAndBundle('node', 'example');
  $workflow->save();
  // Create some sample content that will satisfy a view of users with a
  // relationship to an item of content.
  $user = $this->createUser([], 'Test user');
  $node = Node::create([
    'type' => 'example',
    'title' => 'Test node',
    'moderation_state' => 'published',
    'uid' => $user->id(),
  ]);
  $node->save();
  // When filtering by published nodes, the sample content will appear.
  $view = Views::getView('test_content_moderation_filter_via_relationship');
  $view->setExposedInput([
    'moderation_state' => 'editorial-published',
  ]);
  $view->execute();
  $this->assertIdenticalResultset($view, [
    [
      'name' => 'Test user',
      'title' => 'Test node',
      'moderation_state' => 'published',
    ],
  ], [
    'name' => 'name',
    'title' => 'title',
    'moderation_state' => 'moderation_state',
  ]);
  // Filtering by the draft state will filter out the sample content.
  $view = Views::getView('test_content_moderation_filter_via_relationship');
  $view->setExposedInput([
    'moderation_state' => 'editorial-draft',
  ]);
  $view->execute();
  $this->assertIdenticalResultset($view, [], [
    'name' => 'name',
  ]);
  // Revision Data Table Relationship: Filtering by the published state will
  // filter out the sample content.
  $view = Views::getView('test_content_moderation_filter_via_revision_relationship');
  $view->setExposedInput([
    'moderation_state' => 'editorial-published',
  ]);
  $view->execute();
  $this->assertIdenticalResultset($view, [
    [
      'name' => 'Test user',
      'title' => 'Test node',
      'moderation_state' => 'published',
    ],
  ], [
    'name' => 'name',
    'title' => 'title',
    'moderation_state' => 'moderation_state',
  ]);
  // Revision Data Table Relationship: Filtering by the draft state will
  // filter out the sample content.
  $view = Views::getView('test_content_moderation_filter_via_revision_relationship');
  $view->setExposedInput([
    'moderation_state' => 'editorial-draft',
  ]);
  $view->execute();
  $this->assertIdenticalResultset($view, [], [
    'name' => 'name',
  ]);
}

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