public function FormTest::assertFormValuesDefault in Drupal 9
Same name and namespace in other branches
- 8 core/modules/system/tests/src/Functional/Form/FormTest.php \Drupal\Tests\system\Functional\Form\FormTest::assertFormValuesDefault()
- 10 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.
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 794
Class
- FormTest
- Tests various form element validation mechanisms.
Namespace
Drupal\Tests\system\Functional\FormCode
public 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
->assertSame($expected_value, $values[$key], new FormattableMarkup('Default value for %type: expected %expected, returned %returned.', [
'%type' => $key,
'%expected' => var_export($expected_value, TRUE),
'%returned' => var_export($values[$key], TRUE),
]));
}
// Recurse children.
$this
->assertFormValuesDefault($values, $form[$key]);
}
}