function FormValuesTest::testSimpleAjaxFormValue

Submits forms with select and checkbox elements via Ajax.

File

drupal/core/modules/system/lib/Drupal/system/Tests/Ajax/FormValuesTest.php, line 34
Contains \Drupal\system\Tests\Ajax\FormValuesTest.

Class

FormValuesTest
Tests that $form_state['values'] is properly delivered to $ajax['callback'].

Namespace

Drupal\system\Tests\Ajax

Code

function testSimpleAjaxFormValue() {

  // Verify form values of a select element.
  foreach (array(
    'red',
    'green',
    'blue',
  ) as $item) {
    $edit = array(
      'select' => $item,
    );
    $commands = $this
      ->drupalPostAJAX('ajax_forms_test_get_form', $edit, 'select');
    $expected = new DataCommand('#ajax_selected_color', 'form_state_value_select', $item);
    $this
      ->assertCommand($commands, $expected
      ->render(), 'Verification of AJAX form values from a selectbox issued with a correct value.');
  }

  // Verify form values of a checkbox element.
  foreach (array(
    FALSE,
    TRUE,
  ) as $item) {
    $edit = array(
      'checkbox' => $item,
    );
    $commands = $this
      ->drupalPostAJAX('ajax_forms_test_get_form', $edit, 'checkbox');
    $expected = new DataCommand('#ajax_checkbox_value', 'form_state_value_select', (int) $item);
    $this
      ->assertCommand($commands, $expected
      ->render(), 'Verification of AJAX form values from a checkbox issued with a correct value.');
  }
}