public function FormBuilderTest::testBuildFormWithTriggeringElement in Drupal 9
Same name and namespace in other branches
- 8 core/tests/Drupal/Tests/Core/Form/FormBuilderTest.php \Drupal\Tests\Core\Form\FormBuilderTest::testBuildFormWithTriggeringElement()
Tests whether the triggering element is properly identified.
@covers ::buildForm
@dataProvider providerTestBuildFormWithTriggeringElement
Parameters
string $element_value: The input element "#value" value.
string $input_value: The corresponding submitted input value.
File
- core/
tests/ Drupal/ Tests/ Core/ Form/ FormBuilderTest.php, line 306 - Contains \Drupal\Tests\Core\Form\FormBuilderTest.
Class
- FormBuilderTest
- @coversDefaultClass \Drupal\Core\Form\FormBuilder @group Form
Namespace
Drupal\Tests\Core\FormCode
public function testBuildFormWithTriggeringElement($element_value, $input_value) {
$form_id = 'test_form_id';
$expected_form = $form_id();
$expected_form['actions']['other_submit'] = [
'#type' => 'submit',
'#value' => $element_value,
];
$form_arg = $this
->getMockForm($form_id, $expected_form, 2);
$form_state = new FormState();
$form_state
->setProcessInput();
$form_state
->setUserInput([
'form_id' => $form_id,
'op' => $input_value,
]);
$this->request
->setMethod('POST');
$this->formBuilder
->buildForm($form_arg, $form_state);
$this
->assertEquals($expected_form['actions']['other_submit']['#value'], $form_state
->getTriggeringElement()['#value']);
}