1.20.x form.test FormsTestCase::assertFormValuesDefault($values, $form)

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

File

modules/simpletest/tests/form.test, line 482
Unit tests for the Backdrop Form API.

Class

FormsTestCase

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