Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / vendor / symfony / http-kernel / Tests / Fragment / EsiFragmentRendererTest.php
1 <?php
2
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11
12 namespace Symfony\Component\HttpKernel\Tests\Fragment;
13
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\HttpKernel\Controller\ControllerReference;
16 use Symfony\Component\HttpKernel\Fragment\EsiFragmentRenderer;
17 use Symfony\Component\HttpKernel\HttpCache\Esi;
18 use Symfony\Component\HttpFoundation\Request;
19 use Symfony\Component\HttpKernel\UriSigner;
20
21 class EsiFragmentRendererTest extends TestCase
22 {
23     public function testRenderFallbackToInlineStrategyIfEsiNotSupported()
24     {
25         $strategy = new EsiFragmentRenderer(new Esi(), $this->getInlineStrategy(true));
26         $strategy->render('/', Request::create('/'));
27     }
28
29     /**
30      * @group legacy
31      * @expectedDeprecation Passing non-scalar values as part of URI attributes to the ESI and SSI rendering strategies is deprecated %s.
32      */
33     public function testRenderFallbackWithObjectAttributesIsDeprecated()
34     {
35         $strategy = new EsiFragmentRenderer(new Esi(), $this->getInlineStrategy(true), new UriSigner('foo'));
36         $request = Request::create('/');
37         $reference = new ControllerReference('main_controller', array('foo' => new \stdClass()), array());
38         $strategy->render($reference, $request);
39     }
40
41     public function testRenderFallbackWithScalarIsNotDeprecated()
42     {
43         $strategy = new EsiFragmentRenderer(new Esi(), $this->getInlineStrategy(true), new UriSigner('foo'));
44         $request = Request::create('/');
45         $reference = new ControllerReference('main_controller', array('foo' => array(true)), array());
46         $strategy->render($reference, $request);
47     }
48
49     public function testRender()
50     {
51         $strategy = new EsiFragmentRenderer(new Esi(), $this->getInlineStrategy());
52
53         $request = Request::create('/');
54         $request->setLocale('fr');
55         $request->headers->set('Surrogate-Capability', 'ESI/1.0');
56
57         $this->assertEquals('<esi:include src="/" />', $strategy->render('/', $request)->getContent());
58         $this->assertEquals("<esi:comment text=\"This is a comment\" />\n<esi:include src=\"/\" />", $strategy->render('/', $request, array('comment' => 'This is a comment'))->getContent());
59         $this->assertEquals('<esi:include src="/" alt="foo" />', $strategy->render('/', $request, array('alt' => 'foo'))->getContent());
60     }
61
62     public function testRenderControllerReference()
63     {
64         $signer = new UriSigner('foo');
65         $strategy = new EsiFragmentRenderer(new Esi(), $this->getInlineStrategy(), $signer);
66
67         $request = Request::create('/');
68         $request->setLocale('fr');
69         $request->headers->set('Surrogate-Capability', 'ESI/1.0');
70
71         $reference = new ControllerReference('main_controller', array(), array());
72         $altReference = new ControllerReference('alt_controller', array(), array());
73
74         $this->assertEquals(
75             '<esi:include src="/_fragment?_path=_format%3Dhtml%26_locale%3Dfr%26_controller%3Dmain_controller&_hash=Jz1P8NErmhKTeI6onI1EdAXTB85359MY3RIk5mSJ60w%3D" alt="/_fragment?_path=_format%3Dhtml%26_locale%3Dfr%26_controller%3Dalt_controller&_hash=iPJEdRoUpGrM1ztqByiorpfMPtiW%2FOWwdH1DBUXHhEc%3D" />',
76             $strategy->render($reference, $request, array('alt' => $altReference))->getContent()
77         );
78     }
79
80     /**
81      * @expectedException \LogicException
82      */
83     public function testRenderControllerReferenceWithoutSignerThrowsException()
84     {
85         $strategy = new EsiFragmentRenderer(new Esi(), $this->getInlineStrategy());
86
87         $request = Request::create('/');
88         $request->setLocale('fr');
89         $request->headers->set('Surrogate-Capability', 'ESI/1.0');
90
91         $strategy->render(new ControllerReference('main_controller'), $request);
92     }
93
94     /**
95      * @expectedException \LogicException
96      */
97     public function testRenderAltControllerReferenceWithoutSignerThrowsException()
98     {
99         $strategy = new EsiFragmentRenderer(new Esi(), $this->getInlineStrategy());
100
101         $request = Request::create('/');
102         $request->setLocale('fr');
103         $request->headers->set('Surrogate-Capability', 'ESI/1.0');
104
105         $strategy->render('/', $request, array('alt' => new ControllerReference('alt_controller')));
106     }
107
108     private function getInlineStrategy($called = false)
109     {
110         $inline = $this->getMockBuilder('Symfony\Component\HttpKernel\Fragment\InlineFragmentRenderer')->disableOriginalConstructor()->getMock();
111
112         if ($called) {
113             $inline->expects($this->once())->method('render');
114         }
115
116         return $inline;
117     }
118 }