You are here

public function ExposedFormCheckboxesTest::testExposedFormRenderCheckboxes in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/views/tests/src/Functional/Plugin/ExposedFormCheckboxesTest.php \Drupal\Tests\views\Functional\Plugin\ExposedFormCheckboxesTest::testExposedFormRenderCheckboxes()
  2. 10 core/modules/views/tests/src/Functional/Plugin/ExposedFormCheckboxesTest.php \Drupal\Tests\views\Functional\Plugin\ExposedFormCheckboxesTest::testExposedFormRenderCheckboxes()

Tests overriding the default render option with checkboxes.

File

core/modules/views/tests/src/Functional/Plugin/ExposedFormCheckboxesTest.php, line 85

Class

ExposedFormCheckboxesTest
Tests exposed forms functionality.

Namespace

Drupal\Tests\views\Functional\Plugin

Code

public function testExposedFormRenderCheckboxes() {

  // Use a test theme to convert multi-select elements into checkboxes.
  \Drupal::service('theme_installer')
    ->install([
    'views_test_checkboxes_theme',
  ]);
  $this
    ->config('system.theme')
    ->set('default', 'views_test_checkboxes_theme')
    ->save();

  // Only display 5 items per page so we can test that paging works.
  $view = Views::getView('test_exposed_form_checkboxes');
  $display =& $view->storage
    ->getDisplay('default');
  $display['display_options']['pager']['options']['items_per_page'] = 5;
  $view
    ->save();
  $this
    ->drupalGet('test_exposed_form_checkboxes');
  $this
    ->assertSame('checkbox', $this
    ->assertSession()
    ->fieldExists('type[article]')
    ->getAttribute('type'));
  $this
    ->assertSame('checkbox', $this
    ->assertSession()
    ->fieldExists('type[page]')
    ->getAttribute('type'));

  // Ensure that all results are displayed.
  // 5 rows are displayed by default on the first page when no options are
  // checked.
  $this
    ->assertSession()
    ->elementsCount('xpath', "//div[contains(@class, 'views-row')]", 5);

  // 1 row is displayed by default on the second page when no options are
  // checked.
  $this
    ->clickLink('Page 2');
  $this
    ->assertSession()
    ->elementsCount('xpath', "//div[contains(@class, 'views-row')]", 1);
  $this
    ->assertSession()
    ->pageTextNotContains('An illegal choice has been detected. Please contact the site administrator.');
}