You are here

protected function FormsTestCase::checkFormValue in Drupal 7

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 modules/simpletest/tests/form.test
Tests that submitted values are converted to scalar strings for textfields.

File

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);

  // Set the CSRF token in the user-provided input.
  $form_state['input']['form_token'] = $form['form_token']['#default_value'];

  // 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,
  )));
}