You are here

public function ExposedFormTest::testSubmitButton in Zircon Profile 8

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

Tests the submit button.

File

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

Class

ExposedFormTest
Tests exposed forms functionality.

Namespace

Drupal\views\Tests\Plugin

Code

public function testSubmitButton() {

  // Test the submit button value defaults to 'Apply'.
  $this
    ->drupalGet('test_exposed_form_buttons');
  $this
    ->assertResponse(200);
  $this
    ->helperButtonHasLabel('edit-submit-test-exposed-form-buttons', t('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', t('Apply'));
}