You are here

function FormsTestCase::assertFormValuesDefault in Drupal 7

Assert that the values submitted to a form matches the default values of the elements.

1 call to FormsTestCase::assertFormValuesDefault()
FormsTestCase::testDisabledElements in modules/simpletest/tests/form.test
Test handling of disabled elements.

File

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

Class

FormsTestCase
@file Unit tests for the Drupal Form API.

Code

function assertFormValuesDefault($values, $form) {
  foreach (element_children($form) as $key) {
    if (isset($form[$key]['#default_value'])) {
      if (isset($form[$key]['#expected_value'])) {
        $expected_value = $form[$key]['#expected_value'];
      }
      else {
        $expected_value = $form[$key]['#default_value'];
      }
      if ($key == 'checkboxes_multiple') {

        // Checkboxes values are not filtered out.
        $values[$key] = array_filter($values[$key]);
      }
      $this
        ->assertIdentical($expected_value, $values[$key], format_string('Default value for %type: expected %expected, returned %returned.', array(
        '%type' => $key,
        '%expected' => var_export($expected_value, TRUE),
        '%returned' => var_export($values[$key], TRUE),
      )));
    }

    // Recurse children.
    $this
      ->assertFormValuesDefault($values, $form[$key]);
  }
}