public function FormTest::assertFormValuesDefault in Drupal 10
Same name and namespace in other branches
- 8 core/modules/system/tests/src/Functional/Form/FormTest.php \Drupal\Tests\system\Functional\Form\FormTest::assertFormValuesDefault()
- 9 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 796
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], 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]);
}
}