You are here

protected function ViewsModerationStateFilterTest::assertFilterStates 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::assertFilterStates()

Assert the states which appear in the filter.

Parameters

array $states: The states which should appear in the filter.

bool $check_size: (optional) Whether to check that size of the select element is not greater than 8. Defaults to FALSE.

1 call to ViewsModerationStateFilterTest::assertFilterStates()
ViewsModerationStateFilterTest::testFilterRenderCache in core/modules/content_moderation/tests/src/Functional/ViewsModerationStateFilterTest.php
Tests the content moderation state filter caching is correct.

File

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

Class

ViewsModerationStateFilterTest
Tests the views 'moderation_state_filter' filter plugin.

Namespace

Drupal\Tests\content_moderation\Functional

Code

protected function assertFilterStates($states, $check_size = FALSE) {
  $this
    ->drupalGet('/filter-test-path');
  $assert_session = $this
    ->assertSession();

  // Check that the select contains the correct number of options.
  $assert_session
    ->elementsCount('css', '#edit-default-revision-state option', count($states));

  // Check that the size of the select element does not exceed 8 options.
  if ($check_size) {
    $this
      ->assertGreaterThan(8, count($states));
    $assert_session
      ->elementAttributeContains('css', '#edit-default-revision-state', 'size', 8);
  }

  // Check that an option exists for each of the expected states.
  foreach ($states as $state) {
    $assert_session
      ->optionExists('Default Revision State', $state);
  }
}