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. 8.9.x core/modules/views/tests/src/Functional/Plugin/ExposedFormTest.php \Drupal\Tests\views\Functional\Plugin\ExposedFormTest::testResetButton()
  3. 10 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 202

Class

ExposedFormTest
Tests exposed forms functionality.

Namespace

Drupal\Tests\views\Functional\Plugin

Code

public function testResetButton() : void {
    // Test the button is hidden when there is no exposed input.
    $this->drupalGet('test_exposed_form_buttons');
    $this->assertSession()
        ->fieldNotExists('edit-reset');
    $this->drupalGet('test_exposed_form_buttons', [
        'query' => [
            'type' => 'article',
        ],
    ]);
    // Test that the type has been set.
    $this->assertSession()
        ->fieldValueEquals('edit-type', 'article');
    // Test the reset works.
    $this->drupalGet('test_exposed_form_buttons', [
        'query' => [
            'op' => 'Reset',
        ],
    ]);
    $this->assertSession()
        ->statusCodeEquals(200);
    // Test the type has been reset.
    $this->assertSession()
        ->fieldValueEquals('edit-type', 'All');
    // Test the button is hidden after reset.
    $this->assertSession()
        ->fieldNotExists('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->assertSession()
        ->fieldValueEquals('edit-type', 'All');
    // Test the button is hidden after reset.
    $this->assertSession()
        ->fieldNotExists('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.