4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\HttpKernel\Tests\Fragment;
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;
21 class EsiFragmentRendererTest extends TestCase
23 public function testRenderFallbackToInlineStrategyIfEsiNotSupported()
25 $strategy = new EsiFragmentRenderer(new Esi(), $this->getInlineStrategy(true));
26 $strategy->render('/', Request::create('/'));
31 * @expectedDeprecation Passing non-scalar values as part of URI attributes to the ESI and SSI rendering strategies is deprecated %s.
33 public function testRenderFallbackWithObjectAttributesIsDeprecated()
35 $strategy = new EsiFragmentRenderer(new Esi(), $this->getInlineStrategy(true), new UriSigner('foo'));
36 $request = Request::create('/');
37 $reference = new ControllerReference('main_controller', array('foo' => array('a' => array(), 'b' => new \stdClass())), array());
38 $strategy->render($reference, $request);
41 public function testRender()
43 $strategy = new EsiFragmentRenderer(new Esi(), $this->getInlineStrategy());
45 $request = Request::create('/');
46 $request->setLocale('fr');
47 $request->headers->set('Surrogate-Capability', 'ESI/1.0');
49 $this->assertEquals('<esi:include src="/" />', $strategy->render('/', $request)->getContent());
50 $this->assertEquals("<esi:comment text=\"This is a comment\" />\n<esi:include src=\"/\" />", $strategy->render('/', $request, array('comment' => 'This is a comment'))->getContent());
51 $this->assertEquals('<esi:include src="/" alt="foo" />', $strategy->render('/', $request, array('alt' => 'foo'))->getContent());
54 public function testRenderControllerReference()
56 $signer = new UriSigner('foo');
57 $strategy = new EsiFragmentRenderer(new Esi(), $this->getInlineStrategy(), $signer);
59 $request = Request::create('/');
60 $request->setLocale('fr');
61 $request->headers->set('Surrogate-Capability', 'ESI/1.0');
63 $reference = new ControllerReference('main_controller', array(), array());
64 $altReference = new ControllerReference('alt_controller', array(), array());
67 '<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" />',
68 $strategy->render($reference, $request, array('alt' => $altReference))->getContent()
73 * @expectedException \LogicException
75 public function testRenderControllerReferenceWithoutSignerThrowsException()
77 $strategy = new EsiFragmentRenderer(new Esi(), $this->getInlineStrategy());
79 $request = Request::create('/');
80 $request->setLocale('fr');
81 $request->headers->set('Surrogate-Capability', 'ESI/1.0');
83 $strategy->render(new ControllerReference('main_controller'), $request);
87 * @expectedException \LogicException
89 public function testRenderAltControllerReferenceWithoutSignerThrowsException()
91 $strategy = new EsiFragmentRenderer(new Esi(), $this->getInlineStrategy());
93 $request = Request::create('/');
94 $request->setLocale('fr');
95 $request->headers->set('Surrogate-Capability', 'ESI/1.0');
97 $strategy->render('/', $request, array('alt' => new ControllerReference('alt_controller')));
100 private function getInlineStrategy($called = false)
102 $inline = $this->getMockBuilder('Symfony\Component\HttpKernel\Fragment\InlineFragmentRenderer')->disableOriginalConstructor()->getMock();
105 $inline->expects($this->once())->method('render');