Submitting a form programatically from a unit test

by spiridon   Last Updated October 09, 2019 08:07 AM - source

I have a form in the UI which I would like to submit from my unit test programmatically (i.e. not with a UiHelperTrait method) from the test. The drupalPostForm solution would be quite straightforward:

$this->drupalPostForm('/url/of/the/form', [
  'entity' => $value,
], 'Save');

But I am wondering if there is a way to achieve submitting the form with the EntityForm class's save(array $form, FormStateInterface $form_state) method? How would I be able to retrieve the $form and the $form_state values in the test class?

Tags : 8

Related Questions