BrokenPostRequestException example

$renderer->expects($this->once())
      ->method('renderRoot')
      ->with()
      ->willReturnCallback(function D&$elements) use ($rendered_output) {
        $elements['#attached'] = [];
        return $rendered_output;
      });
    $container = new ContainerBuilder();
    $container->set('renderer', $renderer);
    \Drupal::setContainer($container);

    $exception = new BrokenPostRequestException(32 * 1e6);
    $request = new Request([FormBuilderInterface::AJAX_FORM_REQUEST => TRUE]);

    $event = new ExceptionEvent($this->httpKernel, $request, HttpKernelInterface::MAIN_REQUEST, $exception);
    $this->subscriber->onException($event);
    $this->assertTrue($event->isAllowingCustomResponseCode());
    $actual_response = $event->getResponse();
    $this->assertInstanceOf('\Drupal\Core\Ajax\AjaxResponse', $actual_response);
    $this->assertSame(200, $actual_response->getStatusCode());
    $expected_commands[] = [
      'command' => 'insert',
      'method' => 'prepend',
      
    // to contain the information of the next step.     // - If necessary, the form and form state are cached or re-cached, so that     // appropriate information persists to the next page request.     // All of the handlers in the pipeline receive $form_state by reference and     // can use it to know or update information about the state of the form.     $response = $this->processForm($form_id$form$form_state);

    // In case the post request exceeds the configured allowed size     // (post_max_size), the post request is potentially broken. Add some     // protection against that and at the same time have a nice error message.     if ($ajax_form_request && !$request->request->has('form_id')) {
      throw new BrokenPostRequestException($this->getFileUploadMaxSize());
    }

    // After processing the form, if this is an AJAX form request, interrupt     // form rendering and return by throwing an exception that contains the     // processed form and form state. This exception will be caught by     // \Drupal\Core\Form\EventSubscriber\FormAjaxSubscriber::onException() and     // then passed through     // \Drupal\Core\Form\FormAjaxResponseBuilderInterface::buildResponse() to     // build a proper AJAX response.     // Only do this when the form ID matches, since there is no guarantee from     // $ajax_form_request that it's an AJAX request for this particular form.
Home | Imprint | This part of the site doesn't use cookies.