simulateFormSubmission example

$form_arg = $this->getMockForm($form_id$expected_form);
    $form_arg->expects($this->any())
      ->method('submitForm')
      ->willReturnCallback(function D$form, FormStateInterface $form_state) use ($response$form_state_key) {
        $form_state->setFormState([$form_state_key => $response]);
      });

    $form_state = new FormState();
    try {
      $input['form_id'] = $form_id;
      $form_state->setUserInput($input);
      $this->simulateFormSubmission($form_id$form_arg$form_state, FALSE);
      $this->fail('EnforcedResponseException was not thrown.');
    }
    catch (EnforcedResponseException $e) {
      $this->assertSame($response$e->getResponse());
    }
    $this->assertSame($response$form_state->getResponse());
  }

  /** * Provides test data for testHandleFormStateResponse(). */
  
Home | Imprint | This part of the site doesn't use cookies.