function AJAXFormValuesTestCase::testSimpleAJAXFormValue

Create a simple form, then POST to system/ajax to change to it.

File

drupal/modules/simpletest/tests/ajax.test, line 404

Class

AJAXFormValuesTestCase
Test that $form_state['values'] is properly delivered to $ajax['callback'].

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 = array(
      'command' => 'data',
      'value' => $item,
    );
    $this
      ->assertCommand($commands, $expected, "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 = array(
      'command' => 'data',
      'value' => (int) $item,
    );
    $this
      ->assertCommand($commands, $expected, "verification of AJAX form values from a checkbox issued with a correct value");
  }
}