function FormTestBase::simulateFormSubmission

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Core/Form/FormTestBase.php \Drupal\Tests\Core\Form\FormTestBase::simulateFormSubmission()
  2. 8.9.x core/tests/Drupal/Tests/Core/Form/FormTestBase.php \Drupal\Tests\Core\Form\FormTestBase::simulateFormSubmission()
  3. 11.x core/tests/Drupal/Tests/Core/Form/FormTestBase.php \Drupal\Tests\Core\Form\FormTestBase::simulateFormSubmission()

Simulates a form submission within a request, bypassing submitForm().

Calling submitForm() will reset the form builder, if two forms were on the same page, they will be submitted simultaneously.

Parameters

string $form_id: The unique string identifying the form.

\Drupal\Core\Form\FormInterface $form_arg: The form object.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

bool $programmed: Whether $form_state->setProgrammed() should be passed TRUE or not. If it is not set to TRUE, you must provide additional data in $form_state for the submission to take place.

Return value

array The built form.

7 calls to FormTestBase::simulateFormSubmission()
FormBuilderTest::testFormCacheDeletionCached in core/tests/Drupal/Tests/Core/Form/FormBuilderTest.php
Tests that a cached form is deleted after submit.
FormBuilderTest::testFormCacheDeletionUncached in core/tests/Drupal/Tests/Core/Form/FormBuilderTest.php
Tests that an uncached form does not trigger cache set or delete.
FormBuilderTest::testHandleFormStateResponse in core/tests/Drupal/Tests/Core/Form/FormBuilderTest.php
Tests the handling of FormStateInterface::$response.
FormBuilderTest::testHandleRedirectWithResponse in core/tests/Drupal/Tests/Core/Form/FormBuilderTest.php
Tests the handling of a redirect when FormStateInterface::$response exists.
FormBuilderTest::testInvalidToken in core/tests/Drupal/Tests/Core/Form/FormBuilderTest.php
@covers ::doBuildForm

... See full list

File

core/tests/Drupal/Tests/Core/Form/FormTestBase.php, line 262

Class

FormTestBase
Provides a base class for testing form functionality.

Namespace

Drupal\Tests\Core\Form

Code

protected function simulateFormSubmission($form_id, FormInterface $form_arg, FormStateInterface $form_state, $programmed = TRUE) {
    $input = $form_state->getUserInput();
    $input['op'] = 'Submit';
    $form_state->setUserInput($input)
        ->setProgrammed($programmed)
        ->setSubmitted();
    return $this->formBuilder
        ->buildForm($form_arg, $form_state);
}

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