function FormTestBase::simulateFormSubmission

Same name and namespace in other branches
  1. 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.

File

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

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.