|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the Symfony package. |
| 5 | + * |
| 6 | + * (c) Fabien Potencier <[email protected]> |
| 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\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\Controller; |
| 13 | + |
| 14 | +use Symfony\Component\HttpFoundation\Request; |
| 15 | +use Symfony\Component\HttpFoundation\Response; |
| 16 | +use Symfony\Component\DependencyInjection\ContainerAware; |
| 17 | +use Symfony\Component\HttpKernel\Controller\ControllerReference; |
| 18 | + |
| 19 | +class SubRequestController extends ContainerAware |
| 20 | +{ |
| 21 | + public function indexAction() |
| 22 | + { |
| 23 | + $handler = $this->container->get('fragment.handler'); |
| 24 | + |
| 25 | + $errorUrl = $this->generateUrl('subrequest_fragment_error', array('_locale' => 'fr', '_format' => 'json')); |
| 26 | + $altUrl = $this->generateUrl('subrequest_fragment', array('_locale' => 'fr', '_format' => 'json')); |
| 27 | + |
| 28 | + // simulates a failure during the rendering of a fragment... |
| 29 | + // should render fr/json |
| 30 | + $content = $handler->render($errorUrl, 'inline', array('alt' => $altUrl)); |
| 31 | + |
| 32 | + // ...to check that the FragmentListener still references the right Request |
| 33 | + // when rendering another fragment after the error occured |
| 34 | + // should render en/html instead of fr/json |
| 35 | + $content .= $handler->render(new ControllerReference('TestBundle:SubRequest:fragment')); |
| 36 | + |
| 37 | + // forces the LocaleListener to set fr for the locale... |
| 38 | + // should render fr/json |
| 39 | + $content .= $handler->render($altUrl); |
| 40 | + |
| 41 | + // ...and check that after the rendering, the original Request is back |
| 42 | + // and en is used as a locale |
| 43 | + // should use en/html instead of fr/json |
| 44 | + $content .= '--'.$this->generateUrl('subrequest_fragment'); |
| 45 | + |
| 46 | + // The RouterListener is also tested as if it does not keep the right |
| 47 | + // Request in the context, a 301 would be generated |
| 48 | + |
| 49 | + return new Response($content); |
| 50 | + } |
| 51 | + |
| 52 | + public function fragmentAction(Request $request) |
| 53 | + { |
| 54 | + return new Response('--'.$request->getLocale().'/'.$request->getRequestFormat()); |
| 55 | + } |
| 56 | + |
| 57 | + public function fragmentErrorAction() |
| 58 | + { |
| 59 | + throw new \RuntimeException('error'); |
| 60 | + } |
| 61 | + |
| 62 | + protected function generateUrl($name, $arguments = array()) |
| 63 | + { |
| 64 | + return $this->container->get('router')->generate($name, $arguments); |
| 65 | + } |
| 66 | +} |
0 commit comments