/**
  * Ensure cache metadata is bubbled when using theme_render_and_autoescape().
  */
 public function testBubblingMetadata()
 {
     $link = new GeneratedLink();
     $link->setGeneratedLink('<a href="http://example.com"></a>');
     $link->addCacheTags(['foo']);
     $link->addAttachments(['library' => ['system/base']]);
     $context = new RenderContext();
     // Use a closure here since we need to render with a render context.
     $theme_render_and_autoescape = function () use($link) {
         return theme_render_and_autoescape($link);
     };
     /** @var \Drupal\Core\Render\RendererInterface $renderer */
     $renderer = \Drupal::service('renderer');
     $output = $renderer->executeInRenderContext($context, $theme_render_and_autoescape);
     $this->assertEquals('<a href="http://example.com"></a>', $output);
     /** @var \Drupal\Core\Render\BubbleableMetadata $metadata */
     $metadata = $context->pop();
     $this->assertEquals(['foo'], $metadata->getCacheTags());
     $this->assertEquals(['library' => ['system/base']], $metadata->getAttachments());
 }
Пример #2
0
 /**
  * @covers ::renderVar
  * @covers ::bubbleArgMetadata
  */
 public function testRenderVarWithGeneratedLink()
 {
     $renderer = $this->prophesize(RendererInterface::class);
     $twig_extension = new TwigExtension($renderer->reveal());
     $link = new GeneratedLink();
     $link->setGeneratedLink('<a href="http://example.com"></a>');
     $link->addCacheTags(['foo']);
     $link->addAttachments(['library' => ['system/base']]);
     $result = $twig_extension->renderVar($link);
     $renderer->render(["#cache" => ["contexts" => [], "tags" => ["foo"], "max-age" => -1], "#attached" => ['library' => ['system/base']]])->shouldHaveBeenCalled();
     $this->assertEquals('<a href="http://example.com"></a>', $result);
 }