function ExposedFormTest::testSubmitButton

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

Tests the submit button.

File

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

Class

ExposedFormTest
Tests exposed forms functionality.

Namespace

Drupal\Tests\views\Functional\Plugin

Code

public function testSubmitButton() {
    // Test the submit button value defaults to 'Apply'.
    $this->drupalGet('test_exposed_form_buttons');
    $this->assertSession()
        ->statusCodeEquals(200);
    $this->helperButtonHasLabel('edit-submit-test-exposed-form-buttons', 'Apply');
    // Rename the label of the submit button.
    $view = Views::getView('test_exposed_form_buttons');
    $view->setDisplay();
    $exposed_form = $view->display_handler
        ->getOption('exposed_form');
    $exposed_form['options']['submit_button'] = $expected_label = $this->randomMachineName();
    $view->display_handler
        ->setOption('exposed_form', $exposed_form);
    $view->save();
    // Make sure the submit button label changed.
    $this->drupalGet('test_exposed_form_buttons');
    $this->helperButtonHasLabel('edit-submit-test-exposed-form-buttons', $expected_label);
    // Make sure an empty label uses the default 'Apply' button value too.
    $view = Views::getView('test_exposed_form_buttons');
    $view->setDisplay();
    $exposed_form = $view->display_handler
        ->getOption('exposed_form');
    $exposed_form['options']['submit_button'] = '';
    $view->display_handler
        ->setOption('exposed_form', $exposed_form);
    $view->save();
    // Make sure the submit button label shows 'Apply'.
    $this->drupalGet('test_exposed_form_buttons');
    $this->helperButtonHasLabel('edit-submit-test-exposed-form-buttons', 'Apply');
}

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