Upgraded drupal core with security updates
[yaffs-website] / web / core / tests / Drupal / Tests / Core / Render / MetadataBubblingUrlGeneratorTest.php
1 <?php
2
3 namespace Drupal\Tests\Core\Render;
4
5 use Drupal\Core\Render\MetadataBubblingUrlGenerator;
6 use Drupal\Core\Url;
7 use Drupal\Tests\Core\Routing\UrlGeneratorTest;
8
9 /**
10  * Confirm that the MetadataBubblingUrlGenerator is functioning properly.
11  *
12  * @coversDefaultClass \Drupal\Core\Render\MetadataBubblingUrlGenerator
13  *
14  * @group Render
15  */
16 class MetadataBubblingUrlGeneratorTest extends UrlGeneratorTest {
17
18   /**
19    * The renderer.
20    *
21    * @var \Drupal\Core\Render\RendererInterface|\PHPUnit_Framework_MockObject_MockObject
22    */
23   protected $renderer;
24
25   /**
26    * {@inheritdoc}
27    */
28   protected function setUp() {
29     parent::setUp();
30
31     $this->renderer = $this->getMock('\Drupal\Core\Render\RendererInterface');
32     $this->renderer->expects($this->any())
33       ->method('hasRenderContext')
34       ->willReturn(TRUE);
35
36     $this->generator = new MetadataBubblingUrlGenerator($this->generator, $this->renderer);
37   }
38
39   /**
40    * Tests bubbling of cacheable metadata for URLs.
41    *
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
47    *   The URL options.
48    *
49    * @covers ::bubble
50    *
51    * @dataProvider providerUrlBubbleableMetadataBubbling
52    */
53   public function testUrlBubbleableMetadataBubbling($collect_bubbleable_metadata, $invocations, array $options) {
54     $self = $this;
55
56     $this->renderer->expects($this->exactly($invocations))
57       ->method('render')
58       ->willReturnCallback(function ($build) use ($self) {
59         $self->assertTrue(!empty($build['#cache']));
60       });
61
62     $url = new Url('test_1', [], $options);
63     $url->setUrlGenerator($this->generator);
64     $url->toString($collect_bubbleable_metadata);
65   }
66
67   /**
68    * Data provider for ::testUrlBubbleableMetadataBubbling().
69    */
70   public function providerUrlBubbleableMetadataBubbling() {
71     return [
72       // No bubbling when bubbleable metadata is collected.
73       [TRUE, 0, []],
74       // Bubbling when bubbleable metadata is not collected.
75       [FALSE, 1, []],
76     ];
77   }
78
79 }