renderer = $this->getMock('\Drupal\Core\Render\RendererInterface'); $this->renderer->expects($this->any()) ->method('hasRenderContext') ->willReturn(TRUE); $this->generator = new MetadataBubblingUrlGenerator($this->generator, $this->renderer); } /** * Tests bubbling of cacheable metadata for URLs. * * @param bool $collect_bubbleable_metadata * Whether bubbleable metadata should be collected. * @param int $invocations * The expected amount of invocations for the ::bubble() method. * @param array $options * The URL options. * * @covers ::bubble * * @dataProvider providerUrlBubbleableMetadataBubbling */ public function testUrlBubbleableMetadataBubbling($collect_bubbleable_metadata, $invocations, array $options) { $self = $this; $this->renderer->expects($this->exactly($invocations)) ->method('render') ->willReturnCallback(function ($build) use ($self) { $self->assertTrue(!empty($build['#cache'])); }); $url = new Url('test_1', [], $options); $url->setUrlGenerator($this->generator); $url->toString($collect_bubbleable_metadata); } /** * Data provider for ::testUrlBubbleableMetadataBubbling(). */ public function providerUrlBubbleableMetadataBubbling() { return [ // No bubbling when bubbleable metadata is collected. [TRUE, 0, []], // Bubbling when bubbleable metadata is not collected. [FALSE, 1, []], ]; } }