public function FormBuilderTest::testFormCacheDeletionCached in Drupal 9
Same name and namespace in other branches
- 8 core/tests/Drupal/Tests/Core/Form/FormBuilderTest.php \Drupal\Tests\Core\Form\FormBuilderTest::testFormCacheDeletionCached()
Tests that a cached form is deleted after submit.
File
- core/
tests/ Drupal/ Tests/ Core/ Form/ FormBuilderTest.php, line 521 - Contains \Drupal\Tests\Core\Form\FormBuilderTest.
Class
- FormBuilderTest
- @coversDefaultClass \Drupal\Core\Form\FormBuilder @group Form
Namespace
Drupal\Tests\Core\FormCode
public function testFormCacheDeletionCached() {
$form_id = 'test_form_id';
$form_build_id = $this
->randomMachineName();
$expected_form = $form_id();
$expected_form['#build_id'] = $form_build_id;
$form_arg = $this
->getMockForm($form_id, $expected_form);
$form_arg
->expects($this
->once())
->method('submitForm')
->willReturnCallback(function (array &$form, FormStateInterface $form_state) {
// Mimic EntityForm by cleaning the $form_state upon submit.
$form_state
->cleanValues();
});
$this->formCache
->expects($this
->once())
->method('deleteCache')
->with($form_build_id);
$form_state = new FormState();
$form_state
->setRequestMethod('POST');
$form_state
->setCached();
$this
->simulateFormSubmission($form_id, $form_arg, $form_state);
}