function FormBuilderTest::testBuildFormWithTriggeringElement

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/Core/Form/FormBuilderTest.php \Drupal\Tests\Core\Form\FormBuilderTest::testBuildFormWithTriggeringElement()
  2. 8.9.x core/tests/Drupal/Tests/Core/Form/FormBuilderTest.php \Drupal\Tests\Core\Form\FormBuilderTest::testBuildFormWithTriggeringElement()
  3. 10 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 319

Class

FormBuilderTest
@coversDefaultClass \Drupal\Core\Form\FormBuilder[[api-linebreak]] @group Form

Namespace

Drupal\Tests\Core\Form

Code

public function testBuildFormWithTriggeringElement($element_value, $input_value) : void {
  $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']);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.