function FormTest::assertFormValuesDefault
Same name in other branches
- 9 core/modules/system/tests/src/Functional/Form/FormTest.php \Drupal\Tests\system\Functional\Form\FormTest::assertFormValuesDefault()
- 8.9.x core/modules/system/tests/src/Functional/Form/FormTest.php \Drupal\Tests\system\Functional\Form\FormTest::assertFormValuesDefault()
- 11.x core/modules/system/tests/src/Functional/Form/FormTest.php \Drupal\Tests\system\Functional\Form\FormTest::assertFormValuesDefault()
Assert that the values submitted to a form matches the default values of the elements.
@internal
1 call to FormTest::assertFormValuesDefault()
- FormTest::testDisabledElements in core/
modules/ system/ tests/ src/ Functional/ Form/ FormTest.php - Tests handling of disabled elements.
File
-
core/
modules/ system/ tests/ src/ Functional/ Form/ FormTest.php, line 797
Class
- FormTest
- Tests various form element validation mechanisms.
Namespace
Drupal\Tests\system\Functional\FormCode
public function assertFormValuesDefault(array $values, array $form) : void {
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 (in_array($key, [
'checkboxes_multiple',
'checkboxes_single_select',
'checkboxes_single_unselect',
], TRUE)) {
// Checkboxes values are not filtered out.
$values[$key] = array_filter($values[$key]);
}
$this->assertSame($expected_value, $values[$key], sprintf('Default value for %s: expected %s, returned %s.', $key, var_export($expected_value, TRUE), var_export($values[$key], TRUE)));
}
// Recurse children.
$this->assertFormValuesDefault($values, $form[$key]);
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.