You are here

public function ExposedFormCheckboxesTest::testExposedFormRenderCheckboxes in Drupal 8

Same name and namespace in other branches
  1. 9 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');
  $actual = $this
    ->xpath('//form//input[@type="checkbox" and @name="type[article]"]');
  $this
    ->assertCount(1, $actual, 'Article option renders as a checkbox.');
  $actual = $this
    ->xpath('//form//input[@type="checkbox" and @name="type[page]"]');
  $this
    ->assertCount(1, $actual, 'Page option renders as a checkbox');

  // Ensure that all results are displayed.
  $rows = $this
    ->xpath("//div[contains(@class, 'views-row')]");
  $this
    ->assertCount(5, $rows, '5 rows are displayed by default on the first page when no options are checked.');
  $this
    ->clickLink('Page 2');
  $rows = $this
    ->xpath("//div[contains(@class, 'views-row')]");
  $this
    ->assertCount(1, $rows, '1 row is displayed by default on the second page when no options are checked.');
  $this
    ->assertNoText('An illegal choice has been detected. Please contact the site administrator.');
}