function ExposedFormTest::testResetButton

Same name in other branches
  1. 9 core/modules/views/tests/src/Functional/Plugin/ExposedFormTest.php \Drupal\Tests\views\Functional\Plugin\ExposedFormTest::testResetButton()
  2. 10 core/modules/views/tests/src/Functional/Plugin/ExposedFormTest.php \Drupal\Tests\views\Functional\Plugin\ExposedFormTest::testResetButton()
  3. 11.x core/modules/views/tests/src/Functional/Plugin/ExposedFormTest.php \Drupal\Tests\views\Functional\Plugin\ExposedFormTest::testResetButton()

Tests whether the reset button works on an exposed form.

File

core/modules/views/tests/src/Functional/Plugin/ExposedFormTest.php, line 156

Class

ExposedFormTest
Tests exposed forms functionality.

Namespace

Drupal\Tests\views\Functional\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', [
        'query' => [
            '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', [
        'query' => [
            'op' => 'Reset',
        ],
    ]);
    $this->assertSession()
        ->statusCodeEquals(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', [
        'query' => [
            'type' => 'article',
            'op' => 'Reset',
        ],
    ]);
    $this->assertSession()
        ->statusCodeEquals(200);
    $this->assertFieldById('edit-type', 'All', 'Article type filter has been reset.');
    // Test the button is hidden after reset.
    $this->assertNoField('edit-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', [
        'query' => [
            'type' => 'article',
        ],
    ]);
    $this->assertSession()
        ->statusCodeEquals(200);
    $this->helperButtonHasLabel('edit-reset', $expected_label);
}

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