protected function FormsTestCase::checkFormValue

Checks that a given form input value is sanitized to the expected result.

Parameters

string $element_type: The form element type. Example: textfield.

mixed $input_value: The submitted user input value for the form element.

mixed $expected_value: The sanitized result value in the form state after calling form_builder().

1 call to FormsTestCase::checkFormValue()
FormsTestCase::testTextfieldStringValue in drupal/modules/simpletest/tests/form.test
Tests that submitted values are converted to scalar strings for textfields.

File

drupal/modules/simpletest/tests/form.test, line 508
Unit tests for the Drupal Form API.

Class

FormsTestCase
@file Unit tests for the Drupal Form API.

Code

protected function checkFormValue($element_type, $input_value, $expected_value) {
  $form_id = $this
    ->randomName();
  $form = array();
  $form_state = form_state_defaults();
  $form['op'] = array(
    '#type' => 'submit',
    '#value' => t('Submit'),
  );
  $form[$element_type] = array(
    '#type' => $element_type,
    '#title' => 'test',
  );
  $form_state['input'][$element_type] = $input_value;
  $form_state['input']['form_id'] = $form_id;
  $form_state['method'] = 'post';
  $form_state['values'] = array();
  drupal_prepare_form($form_id, $form, $form_state);

  // This is the main function we want to test: it is responsible for
  // populating user supplied $form_state['input'] to sanitized
  // $form_state['values'].
  form_builder($form_id, $form, $form_state);
  $this
    ->assertIdentical($form_state['values'][$element_type], $expected_value, format_string('Form submission for the "@element_type" element type has been correctly sanitized.', array(
    '@element_type' => $element_type,
  )));
}