function ProgrammaticTest::doSubmitForm
Same name in other branches
- 9 core/modules/system/tests/src/Kernel/Form/ProgrammaticTest.php \Drupal\Tests\system\Kernel\Form\ProgrammaticTest::doSubmitForm()
- 8.9.x core/modules/system/tests/src/Kernel/Form/ProgrammaticTest.php \Drupal\Tests\system\Kernel\Form\ProgrammaticTest::doSubmitForm()
- 11.x core/modules/system/tests/src/Kernel/Form/ProgrammaticTest.php \Drupal\Tests\system\Kernel\Form\ProgrammaticTest::doSubmitForm()
Programmatically submits the form_test.module form with the given values.
Parameters
$values: An array of field values to be submitted.
$valid_input: A boolean indicating whether or not the form submission is expected to be valid.
1 call to ProgrammaticTest::doSubmitForm()
- ProgrammaticTest::testSubmissionWorkflow in core/
modules/ system/ tests/ src/ Kernel/ Form/ ProgrammaticTest.php - Tests the programmatic form submission workflow.
File
-
core/
modules/ system/ tests/ src/ Kernel/ Form/ ProgrammaticTest.php, line 67
Class
- ProgrammaticTest
- Tests the programmatic form submission behavior.
Namespace
Drupal\Tests\system\Kernel\FormCode
protected function doSubmitForm($values, $valid_input) {
// Programmatically submit the given values.
$form_state = (new FormState())->setValues($values);
\Drupal::formBuilder()->submitForm('\\Drupal\\form_test\\Form\\FormTestProgrammaticForm', $form_state);
// Check that the form returns an error when expected, and vice versa.
$errors = $form_state->getErrors();
$valid_form = empty($errors);
$input_values = print_r($values, TRUE);
$validation_errors = $valid_form ? t('None') : implode(' ', $errors);
$this->assertSame($valid_form, $valid_input, sprintf('Input values: %s<br />Validation handler errors: %s', $input_values, $validation_errors));
// We check submitted values only if we have a valid input.
if ($valid_input) {
// Fetching the values that were set in the submission handler.
$stored_values = $form_state->get('programmatic_form_submit');
foreach ($values as $key => $value) {
$this->assertEquals($value, $stored_values[$key], sprintf('Submission handler correctly executed: %s is %s', $key, print_r($value, TRUE)));
}
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.