You are here

function FormTest::assertFormValuesDefault in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/system/src/Tests/Form/FormTest.php \Drupal\system\Tests\Form\FormTest::assertFormValuesDefault()

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

1 call to FormTest::assertFormValuesDefault()
FormTest::testDisabledElements in core/modules/system/src/Tests/Form/FormTest.php
Test handling of disabled elements.

File

core/modules/system/src/Tests/Form/FormTest.php, line 633
Contains \Drupal\system\Tests\Form\FormTest.

Class

FormTest
Tests various form element validation mechanisms.

Namespace

Drupal\system\Tests\Form

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