|
15 | 15 | use Symfony\Component\HttpKernel\Fragment\EsiFragmentRenderer;
|
16 | 16 | use Symfony\Component\HttpKernel\HttpCache\Esi;
|
17 | 17 | use Symfony\Component\HttpFoundation\Request;
|
| 18 | +use Symfony\Component\HttpKernel\UriSigner; |
18 | 19 |
|
19 | 20 | class EsiFragmentRendererTest extends \PHPUnit_Framework_TestCase
|
20 | 21 | {
|
@@ -48,7 +49,52 @@ public function testRender()
|
48 | 49 | $this->assertEquals('<esi:include src="/" />', $strategy->render('/', $request)->getContent());
|
49 | 50 | $this->assertEquals("<esi:comment text=\"This is a comment\" />\n<esi:include src=\"/\" />", $strategy->render('/', $request, array('comment' => 'This is a comment'))->getContent());
|
50 | 51 | $this->assertEquals('<esi:include src="/" alt="foo" />', $strategy->render('/', $request, array('alt' => 'foo'))->getContent());
|
51 |
| - $this->assertEquals('<esi:include src="/_fragment?_path=_format%3Dhtml%26_locale%3Dfr%26_controller%3Dmain_controller" alt="/_fragment?_path=_format%3Dhtml%26_locale%3Dfr%26_controller%3Dalt_controller" />', $strategy->render(new ControllerReference('main_controller', array(), array()), $request, array('alt' => new ControllerReference('alt_controller', array(), array())))->getContent()); |
| 52 | + } |
| 53 | + |
| 54 | + public function testRenderControllerReference() |
| 55 | + { |
| 56 | + $signer = new UriSigner('foo'); |
| 57 | + $strategy = new EsiFragmentRenderer(new Esi(), $this->getInlineStrategy(), $signer); |
| 58 | + |
| 59 | + $request = Request::create('/'); |
| 60 | + $request->setLocale('fr'); |
| 61 | + $request->headers->set('Surrogate-Capability', 'ESI/1.0'); |
| 62 | + |
| 63 | + $reference = new ControllerReference('main_controller', array(), array()); |
| 64 | + $altReference = new ControllerReference('alt_controller', array(), array()); |
| 65 | + |
| 66 | + $this->assertEquals( |
| 67 | + '<esi:include src="/_fragment?_path=_format%3Dhtml%26_locale%3Dfr%26_controller%3Dmain_controller&_hash=wDaFy1WsZUOWrrMdRMgJ1cOskFo%3D" alt="/_fragment?_path=_format%3Dhtml%26_locale%3Dfr%26_controller%3Dalt_controller&_hash=56ycnRUlgaremRQVStZsGbVhIv8%3D" />', |
| 68 | + $strategy->render($reference, $request, array('alt' => $altReference))->getContent() |
| 69 | + ); |
| 70 | + } |
| 71 | + |
| 72 | + /** |
| 73 | + * @expectedException \LogicException |
| 74 | + */ |
| 75 | + public function testRenderControllerReferenceWithoutSignerThrowsException() |
| 76 | + { |
| 77 | + $strategy = new EsiFragmentRenderer(new Esi(), $this->getInlineStrategy()); |
| 78 | + |
| 79 | + $request = Request::create('/'); |
| 80 | + $request->setLocale('fr'); |
| 81 | + $request->headers->set('Surrogate-Capability', 'ESI/1.0'); |
| 82 | + |
| 83 | + $strategy->render(new ControllerReference('main_controller'), $request); |
| 84 | + } |
| 85 | + |
| 86 | + /** |
| 87 | + * @expectedException \LogicException |
| 88 | + */ |
| 89 | + public function testRenderAltControllerReferenceWithoutSignerThrowsException() |
| 90 | + { |
| 91 | + $strategy = new EsiFragmentRenderer(new Esi(), $this->getInlineStrategy()); |
| 92 | + |
| 93 | + $request = Request::create('/'); |
| 94 | + $request->setLocale('fr'); |
| 95 | + $request->headers->set('Surrogate-Capability', 'ESI/1.0'); |
| 96 | + |
| 97 | + $strategy->render('/', $request, array('alt' => new ControllerReference('alt_controller'))); |
52 | 98 | }
|
53 | 99 |
|
54 | 100 | private function getInlineStrategy($called = false)
|
|
0 commit comments