You are here

public function ViewsModerationStateFilterTest::testFilterRenderCache in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/content_moderation/tests/src/Functional/ViewsModerationStateFilterTest.php \Drupal\Tests\content_moderation\Functional\ViewsModerationStateFilterTest::testFilterRenderCache()

Tests the content moderation state filter caching is correct.

File

core/modules/content_moderation/tests/src/Functional/ViewsModerationStateFilterTest.php, line 263

Class

ViewsModerationStateFilterTest
Tests the views 'moderation_state_filter' filter plugin.

Namespace

Drupal\Tests\content_moderation\Functional

Code

public function testFilterRenderCache() {

  // Initially all states of the workflow are displayed.
  $this
    ->drupalPostForm('admin/config/workflow/workflows/manage/editorial/type/node', [
    'bundles[example_a]' => TRUE,
  ], 'Save');
  $this
    ->assertFilterStates([
    'All',
    'editorial-draft',
    'editorial-published',
    'editorial-archived',
  ]);

  // Adding a new state to the editorial workflow will display that state in
  // the list of filters.
  $this
    ->drupalPostForm('admin/config/workflow/workflows/manage/editorial/add_state', [
    'label' => 'Foo',
    'id' => 'foo',
  ], 'Save');
  $this
    ->assertFilterStates([
    'All',
    'editorial-draft',
    'editorial-published',
    'editorial-archived',
    'editorial-foo',
  ]);

  // Adding a second workflow to nodes will also show new states.
  $this
    ->drupalPostForm('admin/config/workflow/workflows/manage/new_workflow/type/node', [
    'bundles[example_b]' => TRUE,
  ], 'Save');
  $this
    ->assertFilterStates([
    'All',
    'editorial-draft',
    'editorial-published',
    'editorial-archived',
    'editorial-foo',
    'new_workflow-draft',
    'new_workflow-published',
    'new_workflow-bar',
  ]);

  // Add a few more states and change the exposed filter to allow multiple
  // selections so we can check that the size of the select element does not
  // exceed 8 options.
  $this
    ->drupalPostForm('admin/config/workflow/workflows/manage/editorial/add_state', [
    'label' => 'Foo 2',
    'id' => 'foo2',
  ], 'Save');
  $this
    ->drupalPostForm('admin/config/workflow/workflows/manage/editorial/add_state', [
    'label' => 'Foo 3',
    'id' => 'foo3',
  ], 'Save');
  $view_id = 'test_content_moderation_state_filter_base_table';
  $edit['options[expose][multiple]'] = TRUE;
  $this
    ->drupalPostForm("admin/structure/views/nojs/handler/{$view_id}/default/filter/moderation_state", $edit, 'Apply');
  $this
    ->drupalPostForm("admin/structure/views/view/{$view_id}", [], 'Save');
  $this
    ->assertFilterStates([
    'editorial-draft',
    'editorial-published',
    'editorial-archived',
    'editorial-foo',
    'editorial-foo2',
    'editorial-foo3',
    'new_workflow-draft',
    'new_workflow-published',
    'new_workflow-bar',
  ], TRUE);
}