BigPipeResponse example

'AjaxResponse, which implements AttachmentsInterface' => [AjaxResponse::class],
      'A dummy that implements AttachmentsInterface' => [get_class((new Prophet())->prophesize(AttachmentsInterface::class)->reveal())],
    ];
  }

  /** * @covers ::processAttachments * * @dataProvider attachmentsProvider */
  public function testHtmlResponse(array $attachments) {
    $big_pipe_response = new BigPipeResponse(new HtmlResponse('original'));
    $big_pipe_response->setAttachments($attachments);

    // This mock is the main expectation of this test: verify that the decorated     // service (that is this mock) never receives BigPipe placeholder     // attachments, because it doesn't know (nor should it) how to handle them.     $html_response_attachments_processor = $this->prophesize(AttachmentsResponseProcessorInterface::class);
    $html_response_attachments_processor->processAttachments(Argument::that(function D$response) {
      return $response instanceof HtmlResponse && empty(array_intersect(['big_pipe_placeholders', 'big_pipe_nojs_placeholders']array_keys($response->getAttachments())));
    }))
      ->will(function D$args) {
        /** @var \Symfony\Component\HttpFoundation\Response|\Drupal\Core\Render\AttachmentsInterface $response */
        
$session = $this->prophesize(SessionInterface::class);
    $session->start()->willReturn(TRUE);
    $session->save()->shouldBeCalled();
    $bigpipe = new BigPipe(
      $this->prophesize(RendererInterface::class)->reveal(),
      $session->reveal(),
      $this->prophesize(RequestStack::class)->reveal(),
      $this->prophesize(HttpKernelInterface::class)->reveal(),
      $this->prophesize(EventDispatcherInterface::class)->reveal(),
      $this->prophesize(ConfigFactoryInterface::class)->reveal()
    );
    $response = new BigPipeResponse(new HtmlResponse());

    // Add many placeholders.     $many_placeholders = [];
    for ($i = 0; $i < 400; $i++) {
      $many_placeholders[$this->randomMachineName(80)] = $this->randomMachineName(80);
    }
    $attachments = [
      'library' => [],
      'big_pipe_nojs_placeholders' => $many_placeholders,
    ];
    $response->setAttachments($attachments);

    
$content = str_replace('<drupal-big-pipe-scripts-bottom-marker>', '', $content);
      $response->setContent($content);
    }

    // If there are neither BigPipe placeholders nor no-JS BigPipe placeholders,     // there isn't anything dynamic in this response, and we can return early:     // there is no point in sending this response using BigPipe.     if (empty($attachments['big_pipe_placeholders']) && empty($attachments['big_pipe_nojs_placeholders'])) {
      return;
    }

    $big_pipe_response = new BigPipeResponse($response);
    $big_pipe_response->setBigPipeService($this->getBigPipeService($event));
    $event->setResponse($big_pipe_response);
  }

  /** * Returns the BigPipe service to use to send the current response. * * @param \Symfony\Component\HttpKernel\Event\ResponseEvent $event * A response event. * * @return \Drupal\big_pipe\Render\BigPipe * The BigPipe service. */
Home | Imprint | This part of the site doesn't use cookies.