You are here

public function ExposedFormTest::testResetButton in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/modules/views/src/Tests/Plugin/ExposedFormTest.php \Drupal\views\Tests\Plugin\ExposedFormTest::testResetButton()

Tests whether the reset button works on an exposed form.

File

core/modules/views/src/Tests/Plugin/ExposedFormTest.php, line 90
Contains \Drupal\views\Tests\Plugin\ExposedFormTest.

Class

ExposedFormTest
Tests exposed forms functionality.

Namespace

Drupal\views\Tests\Plugin

Code

public function testResetButton() {

  // Test the button is hidden when there is no exposed input.
  $this
    ->drupalGet('test_exposed_form_buttons');
  $this
    ->assertNoField('edit-reset');
  $this
    ->drupalGet('test_exposed_form_buttons', array(
    'query' => array(
      'type' => 'article',
    ),
  ));

  // Test that the type has been set.
  $this
    ->assertFieldById('edit-type', 'article', 'Article type filter set.');

  // Test the reset works.
  $this
    ->drupalGet('test_exposed_form_buttons', array(
    'query' => array(
      'op' => 'Reset',
    ),
  ));
  $this
    ->assertResponse(200);

  // Test the type has been reset.
  $this
    ->assertFieldById('edit-type', 'All', 'Article type filter has been reset.');

  // Test the button is hidden after reset.
  $this
    ->assertNoField('edit-reset');

  // Test the reset works with type set.
  $this
    ->drupalGet('test_exposed_form_buttons', array(
    'query' => array(
      'type' => 'article',
      'op' => 'Reset',
    ),
  ));
  $this
    ->assertResponse(200);
  $this
    ->assertFieldById('edit-type', 'All', 'Article type filter has been reset.');

  // Rename the label of the reset button.
  $view = Views::getView('test_exposed_form_buttons');
  $view
    ->setDisplay();
  $exposed_form = $view->display_handler
    ->getOption('exposed_form');
  $exposed_form['options']['reset_button_label'] = $expected_label = $this
    ->randomMachineName();
  $exposed_form['options']['reset_button'] = TRUE;
  $view->display_handler
    ->setOption('exposed_form', $exposed_form);
  $view
    ->save();

  // Look whether the reset button label changed.
  $this
    ->drupalGet('test_exposed_form_buttons', array(
    'query' => array(
      'type' => 'article',
    ),
  ));
  $this
    ->assertResponse(200);
  $this
    ->helperButtonHasLabel('edit-reset', $expected_label);
}