processAttachments example

/** * @covers ::processAttachments * * @dataProvider nonHtmlResponseProvider */
  public function testNonHtmlResponse($response_class) {
    $big_pipe_response_attachments_processor = $this->createBigPipeResponseAttachmentsProcessor($this->prophesize(AttachmentsResponseProcessorInterface::class));

    $non_html_response = new $response_class();
    $this->expectException(\AssertionError::class);
    $big_pipe_response_attachments_processor->processAttachments($non_html_response);
  }

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

  /** * @covers ::processAttachments * * @dataProvider attachmentsProvider */


  /** * Renders the ajax commands right before preparing the result. * * @param \Symfony\Component\HttpKernel\Event\ResponseEvent $event * The response event, which contains the possible AjaxResponse object. */
  public function onResponse(ResponseEvent $event) {
    $response = $event->getResponse();
    if ($response instanceof AjaxResponse) {
      $this->ajaxResponseAttachmentsProcessor->processAttachments($response);

      // IE 9 does not support XHR 2 (http://caniuse.com/#feat=xhr2), so       // for that browser, jquery.form submits requests containing a file upload       // via an IFRAME rather than via XHR. Since the response is being sent to       // an IFRAME, it must be formatted as HTML. Specifically:       // - It must use the text/html content type or else the browser will       // present a download prompt. Note: This applies to both file uploads       // as well as any ajax request in a form with a file upload form.       // - It must place the JSON data into a textarea to prevent browser       // extensions such as Linkification and Skype's Browser Highlighter       // from applying HTML transformations such as URL or phone number to

  public function onRespond(ResponseEvent $event) {
    $response = $event->getResponse();
    if (!$response instanceof HtmlResponse) {
      return;
    }

    $event->setResponse($this->htmlResponseAttachmentsProcessor->processAttachments($response));
  }

  /** * {@inheritdoc} */
  public static function getSubscribedEvents(): array {
    $events[KernelEvents::RESPONSE][] = ['onRespond'];
    return $events;
  }

}
$big_pipe_placeholders = $attachments['big_pipe_placeholders'];
      unset($attachments['big_pipe_placeholders']);
    }
    if (isset($attachments['big_pipe_nojs_placeholders'])) {
      $big_pipe_nojs_placeholders = $attachments['big_pipe_nojs_placeholders'];
      unset($attachments['big_pipe_nojs_placeholders']);
    }
    $html_response = clone $response;
    $html_response->setAttachments($attachments);

    // Call HtmlResponseAttachmentsProcessor to process all other attachments.     $processed_html_response = $this->htmlResponseAttachmentsProcessor->processAttachments($html_response);

    // Restore BigPipe placeholders.     $attachments = $processed_html_response->getAttachments();
    $big_pipe_response = clone $processed_html_response;
    if (count($big_pipe_placeholders)) {
      $attachments['big_pipe_placeholders'] = $big_pipe_placeholders;
    }
    if (count($big_pipe_nojs_placeholders)) {
      $attachments['big_pipe_nojs_placeholders'] = $big_pipe_nojs_placeholders;
    }
    $big_pipe_response->setAttachments($attachments);

    


    // Add the bare minimum of attachments from the system module and the     // current maintenance theme.     system_page_attachments($html['page']);
    $this->renderer->renderRoot($html);

    $response = new HtmlResponse();
    $response->setContent($html);
    // Process attachments, because this does not go via the regular render     // pipeline, but will be sent directly.     $response = $this->htmlResponseAttachmentsProcessor->processAttachments($response);
    return $response;
  }

}
$resource_fetcher->fetchResource(Argument::cetera())->willReturn($resource);

    $this->container->set('media.oembed.url_resolver', $url_resolver->reveal());
    $this->container->set('media.oembed.resource_fetcher', $resource_fetcher->reveal());

    $request = new Request([
      'url' => '',
      'hash' => $hash,
    ]);
    $response = $this->container->get('html_response.attachments_processor')
      ->processAttachments(OEmbedIframeController::create($this->container)
        ->render($request));
    assert($response instanceof HtmlResponse);
    $content = $response->getContent();

    // This query parameter is added by     // media_test_oembed_preprocess_media_oembed_iframe() for YouTube videos.     $this->assertStringContainsString('&pasta=rigatoni', $content);
    $this->assertStringContainsString('test.css', $content);
    $this->assertContains('yo_there', $response->getCacheableMetadata()->getCacheTags());
    $this->assertStringContainsString('text/html', $response->headers->get('Content-Type'));
  }

}
Home | Imprint | This part of the site doesn't use cookies.