public function testRender()
 {
     $strategy = new EsiFragmentRenderer(new Esi(), $this->getInlineStrategy());
     $request = Request::create('/');
     $request->headers->set('Surrogate-Capability', 'ESI/1.0');
     $this->assertEquals('<esi:include src="/" />', $strategy->render('/', $request)->getContent());
     $this->assertEquals("<esi:comment text=\"This is a comment\" />\n<esi:include src=\"/\" />", $strategy->render('/', $request, array('comment' => 'This is a comment'))->getContent());
     $this->assertEquals('<esi:include src="/" alt="foo" />', $strategy->render('/', $request, array('alt' => 'foo'))->getContent());
     $this->assertEquals('<esi:include src="http://localhost/_fragment?_path=_format%3Dhtml%26_controller%3Dmain_controller" alt="http://localhost/_fragment?_path=_format%3Dhtml%26_controller%3Dalt_controller" />', $strategy->render(new ControllerReference('main_controller', array(), array()), $request, array('alt' => new ControllerReference('alt_controller', array(), array())))->getContent());
 }
Ejemplo n.º 2
0
 public function renderEsi($params, $template = null)
 {
     $path = $this->getParam($params, 'path');
     $alt = $this->getParam($params, 'alt');
     $ignore_errors = $this->getParam($params, 'ignore_errors');
     $comment = $this->getParam($params, 'comment');
     if (null === $path) {
         return;
     }
     $response = $this->esiFragmentRender->render($path, $this->requestStack->getCurrentRequest(), array('alt' => $alt, 'ignore_errors' => $ignore_errors, 'comment' => $comment));
     if (!$response->isSuccessful()) {
         return null;
     }
     return $response->getContent();
 }
 /**
  * @expectedException \LogicException
  */
 public function testRenderAltControllerReferenceWithoutSignerThrowsException()
 {
     $strategy = new EsiFragmentRenderer(new Esi(), $this->getInlineStrategy());
     $request = Request::create('/');
     $request->setLocale('fr');
     $request->headers->set('Surrogate-Capability', 'ESI/1.0');
     $strategy->render('/', $request, array('alt' => new ControllerReference('alt_controller')));
 }