Commit a47dd7ad authored by alexpott's avatar alexpott

Issue #2568511 by Mile23, ianthomas_uk, Wim Leers: Fix broken test: KernelTestBase::render

parent e16b2b08
......@@ -151,49 +151,52 @@ public function processAttachments(AttachmentsInterface $response) {
throw new \LogicException(sprintf('You are not allowed to use %s in #attached.', implode(', ', $unsupported_types)));
}
// Get the placeholders from attached and then remove them.
$attachment_placeholders = $attached['html_response_attachment_placeholders'];
unset($attached['html_response_attachment_placeholders']);
$variables = $this->processAssetLibraries($attached, $attachment_placeholders);
// Since we can only replace content in the HTML head section if there's a
// placeholder for it, we can safely avoid processing the render array if
// it's not present.
if (!empty($attachment_placeholders['head'])) {
// 'feed' is a special case of 'html_head_link'. We process them into
// 'html_head_link' entries and merge them.
if (!empty($attached['feed'])) {
$attached = BubbleableMetadata::mergeAttachments(
$attached,
$this->processFeed($attached['feed'])
);
}
// 'html_head_link' is a special case of 'html_head' which can be present
// as a head element, but also as a Link: HTTP header depending on
// settings in the render array. Processing it can add to both the
// 'html_head' and 'http_header' keys of '#attached', so we must address
// it before 'html_head'.
if (!empty($attached['html_head_link'])) {
// Merge the processed 'html_head_link' into $attached so that its
// 'html_head' and 'http_header' values are present for further
// processing.
$attached = BubbleableMetadata::mergeAttachments(
$attached,
$this->processHtmlHeadLink($attached['html_head_link'])
);
// If we don't have any placeholders, there is no need to proceed.
if (!empty($attached['html_response_attachment_placeholders'])) {
// Get the placeholders from attached and then remove them.
$attachment_placeholders = $attached['html_response_attachment_placeholders'];
unset($attached['html_response_attachment_placeholders']);
$variables = $this->processAssetLibraries($attached, $attachment_placeholders);
// Since we can only replace content in the HTML head section if there's a
// placeholder for it, we can safely avoid processing the render array if
// it's not present.
if (!empty($attachment_placeholders['head'])) {
// 'feed' is a special case of 'html_head_link'. We process them into
// 'html_head_link' entries and merge them.
if (!empty($attached['feed'])) {
$attached = BubbleableMetadata::mergeAttachments(
$attached,
$this->processFeed($attached['feed'])
);
}
// 'html_head_link' is a special case of 'html_head' which can be present
// as a head element, but also as a Link: HTTP header depending on
// settings in the render array. Processing it can add to both the
// 'html_head' and 'http_header' keys of '#attached', so we must address
// it before 'html_head'.
if (!empty($attached['html_head_link'])) {
// Merge the processed 'html_head_link' into $attached so that its
// 'html_head' and 'http_header' values are present for further
// processing.
$attached = BubbleableMetadata::mergeAttachments(
$attached,
$this->processHtmlHeadLink($attached['html_head_link'])
);
}
// Now we can process 'html_head', which contains both 'feed' and
// 'html_head_link'.
if (!empty($attached['html_head'])) {
$variables['head'] = $this->processHtmlHead($attached['html_head']);
}
}
// Now we can process 'html_head', which contains both 'feed' and
// 'html_head_link'.
if (!empty($attached['html_head'])) {
$variables['head'] = $this->processHtmlHead($attached['html_head']);
}
// Now replace the attachment placeholders.
$this->renderHtmlResponseAttachmentPlaceholders($response, $attachment_placeholders, $variables);
}
// Now replace the attachment placeholders.
$this->renderHtmlResponseAttachmentPlaceholders($response, $attachment_placeholders, $variables);
// Set the HTTP headers and status code on the response if any bubbled.
if (!empty($attached['http_header'])) {
$this->setHeaders($response, $attached['http_header']);
......
......@@ -585,7 +585,14 @@ protected function registerStreamWrapper($scheme, $class, $type = StreamWrapperI
* The rendered string output (typically HTML).
*/
protected function render(array &$elements) {
$content = $this->container->get('renderer')->renderRoot($elements);
// Use the bare HTML page renderer to render our links.
$renderer = $this->container->get('bare_html_page_renderer');
$response = $renderer->renderBarePage(
$elements, '', $this->container->get('theme.manager')->getActiveTheme()->getName()
);
// Glean the content from the response object.
$content = $response->getContent();
$this->setRawContent($content);
$this->verbose('<pre style="white-space: pre-wrap">' . Html::escape($content));
return $content;
......
......@@ -46,7 +46,9 @@ function testThemeTableStickyHeaders() {
'#sticky' => TRUE,
);
$this->render($table);
$this->assertTrue(in_array('core/drupal.tableheader', $table['#attached']['library']), 'tableheader asset library found.');
// Make sure tableheader.js was attached.
$tableheader = $this->xpath("//script[contains(@src, 'tableheader.js')]");
$this->assertEqual(count($tableheader), 1);
$this->assertRaw('sticky-enabled');
}
......@@ -69,7 +71,9 @@ function testThemeTableNoStickyHeaders() {
'#sticky' => FALSE,
);
$this->render($table);
$this->assertFalse(in_array('core/drupal.tableheader', $table['#attached']['library']), 'tableheader asset library not found.');
// Make sure tableheader.js was not attached.
$tableheader = $this->xpath("//script[contains(@src, 'tableheader.js')]");
$this->assertEqual(count($tableheader), 0);
$this->assertNoRaw('sticky-enabled');
}
......
......@@ -907,11 +907,12 @@ protected function render(array &$elements) {
// Use the bare HTML page renderer to render our links.
$renderer = $this->container->get('bare_html_page_renderer');
$response = $renderer->renderBarePage(
$build, '', $this->container->get('theme.manager')->getActiveTheme()->getName()
$elements, '', $this->container->get('theme.manager')->getActiveTheme()->getName()
);
// Glean the content from the response object.
$this->setRawContent($response->getContent());
$content = $response->getContent();
$this->setRawContent($content);
$this->verbose('<pre style="white-space: pre-wrap">' . Html::escape($content));
return $content;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment