function FormSubmitterTest::testExecuteSubmitHandlers
Same name in other branches
- 9 core/tests/Drupal/Tests/Core/Form/FormSubmitterTest.php \Drupal\Tests\Core\Form\FormSubmitterTest::testExecuteSubmitHandlers()
- 8.9.x core/tests/Drupal/Tests/Core/Form/FormSubmitterTest.php \Drupal\Tests\Core\Form\FormSubmitterTest::testExecuteSubmitHandlers()
- 11.x core/tests/Drupal/Tests/Core/Form/FormSubmitterTest.php \Drupal\Tests\Core\Form\FormSubmitterTest::testExecuteSubmitHandlers()
@covers ::executeSubmitHandlers
File
-
core/
tests/ Drupal/ Tests/ Core/ Form/ FormSubmitterTest.php, line 232
Class
- FormSubmitterTest
- @coversDefaultClass \Drupal\Core\Form\FormSubmitter @group Form
Namespace
Drupal\Tests\Core\FormCode
public function testExecuteSubmitHandlers() : void {
$form_submitter = $this->getFormSubmitter();
$mock = $this->prophesize(MockFormBase::class);
$mock->hash_submit(Argument::type('array'), Argument::type(FormStateInterface::class))
->shouldBeCalledOnce();
$mock->submit_handler(Argument::type('array'), Argument::type(FormStateInterface::class))
->shouldBeCalledOnce();
$mock->simple_string_submit(Argument::type('array'), Argument::type(FormStateInterface::class))
->shouldBeCalledOnce();
$form = [];
$form_state = new FormState();
$form_submitter->executeSubmitHandlers($form, $form_state);
$form['#submit'][] = [
$mock->reveal(),
'hash_submit',
];
$form_submitter->executeSubmitHandlers($form, $form_state);
// $form_state submit handlers will supersede $form handlers.
$form_state->setSubmitHandlers([
[
$mock->reveal(),
'submit_handler',
],
]);
$form_submitter->executeSubmitHandlers($form, $form_state);
// Methods directly on the form object can be specified as a string.
$form_state = (new FormState())->setFormObject($mock->reveal())
->setSubmitHandlers([
'::simple_string_submit',
]);
$form_submitter->executeSubmitHandlers($form, $form_state);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.