function FormBuilderTest::testBuildFormWithTriggeringElement

Same name and namespace in other branches
  1. 8.9.x core/tests/Drupal/Tests/Core/Form/FormBuilderTest.php \Drupal\Tests\Core\Form\FormBuilderTest::testBuildFormWithTriggeringElement()
  2. 10 core/tests/Drupal/Tests/Core/Form/FormBuilderTest.php \Drupal\Tests\Core\Form\FormBuilderTest::testBuildFormWithTriggeringElement()
  3. 11.x 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 <a href="/api/drupal/core%21lib%21Drupal%21Core%21Form%21FormBuilder.php/class/FormBuilder/9" title="Provides form building and processing." class="local">\Drupal\Core\Form\FormBuilder</a> @group Form

Namespace

Drupal\Tests\Core\Form

Code

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']);
}

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