/** * Tests that a cached form is deleted after submit. */ 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); }
/** * @covers ::setCached * * @expectedException \LogicException * @expectedExceptionMessage Form state caching on GET requests is not allowed. */ public function testSetCachedGet() { $form_state = new FormState(); $form_state->setRequestMethod('GET'); $form_state->setCached(); }
/** * Tests db log injection serialization. */ public function testLoggerSerialization() { $form_state = new FormState(); // Forms are only serialized during POST requests. $form_state->setRequestMethod('POST'); $form_state->setCached(); $form_builder = $this->container->get('form_builder'); $form_id = $form_builder->getFormId($this, $form_state); $form = $form_builder->retrieveForm($form_id, $form_state); $form_builder->prepareForm($form_id, $form, $form_state); $form_builder->processForm($form_id, $form, $form_state); }
/** * Tests queue injection serialization. */ public function testQueueSerialization() { $form_state = new FormState(); $form_state->setRequestMethod('POST'); $form_state->setCached(); $form_builder = $this->container->get('form_builder'); $form_id = $form_builder->getFormId($this, $form_state); $form = $form_builder->retrieveForm($form_id, $form_state); $form_builder->prepareForm($form_id, $form, $form_state); $form_builder->processForm($form_id, $form, $form_state); }