3 namespace Drupal\Tests\Core\Render;
5 use Drupal\Core\Render\MetadataBubblingUrlGenerator;
7 use Drupal\Tests\Core\Routing\UrlGeneratorTest;
10 * Confirm that the MetadataBubblingUrlGenerator is functioning properly.
12 * @coversDefaultClass \Drupal\Core\Render\MetadataBubblingUrlGenerator
16 class MetadataBubblingUrlGeneratorTest extends UrlGeneratorTest {
21 * @var \Drupal\Core\Render\RendererInterface|\PHPUnit_Framework_MockObject_MockObject
28 protected function setUp() {
31 $this->renderer = $this->getMock('\Drupal\Core\Render\RendererInterface');
32 $this->renderer->expects($this->any())
33 ->method('hasRenderContext')
36 $this->generator = new MetadataBubblingUrlGenerator($this->generator, $this->renderer);
40 * Tests bubbling of cacheable metadata for URLs.
42 * @param bool $collect_bubbleable_metadata
43 * Whether bubbleable metadata should be collected.
44 * @param int $invocations
45 * The expected amount of invocations for the ::bubble() method.
46 * @param array $options
51 * @dataProvider providerUrlBubbleableMetadataBubbling
53 public function testUrlBubbleableMetadataBubbling($collect_bubbleable_metadata, $invocations, array $options) {
56 $this->renderer->expects($this->exactly($invocations))
58 ->willReturnCallback(function ($build) use ($self) {
59 $self->assertTrue(!empty($build['#cache']));
62 $url = new Url('test_1', [], $options);
63 $url->setUrlGenerator($this->generator);
64 $url->toString($collect_bubbleable_metadata);
68 * Data provider for ::testUrlBubbleableMetadataBubbling().
70 public function providerUrlBubbleableMetadataBubbling() {
72 // No bubbling when bubbleable metadata is collected.
74 // Bubbling when bubbleable metadata is not collected.