function ViewsModerationStateFilterTest::assertFilterStates

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()
  2. 8.9.x core/modules/content_moderation/tests/src/Functional/ViewsModerationStateFilterTest.php \Drupal\Tests\content_moderation\Functional\ViewsModerationStateFilterTest::assertFilterStates()
  3. 10 core/modules/content_moderation/tests/src/Functional/ViewsModerationStateFilterTest.php \Drupal\Tests\content_moderation\Functional\ViewsModerationStateFilterTest::assertFilterStates()

Assert the states which appear in the filter.

@internal

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 335

Class

ViewsModerationStateFilterTest
Tests the views 'moderation_state_filter' filter plugin.

Namespace

Drupal\Tests\content_moderation\Functional

Code

protected function assertFilterStates(array $states, bool $check_size = FALSE) : void {
    $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);
    }
}

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