Fixed issue #6932 - Inconsistent locale handling in subrequests
The fix consists in passing the locale in the controller reference, inside the routablefragment renderer.
This commit is contained in:
parent
b3c31593c7
commit
05fdb12ad9
@ -50,6 +50,10 @@ abstract class RoutableFragmentRenderer implements FragmentRendererInterface
|
|||||||
$reference->attributes['_format'] = $request->getRequestFormat();
|
$reference->attributes['_format'] = $request->getRequestFormat();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!isset($reference->attributes['_locale'])) {
|
||||||
|
$reference->attributes['_locale'] = $request->getLocale();
|
||||||
|
}
|
||||||
|
|
||||||
$reference->attributes['_controller'] = $reference->controller;
|
$reference->attributes['_controller'] = $reference->controller;
|
||||||
|
|
||||||
$reference->query['_path'] = http_build_query($reference->attributes, '', '&');
|
$reference->query['_path'] = http_build_query($reference->attributes, '', '&');
|
||||||
|
@ -42,12 +42,13 @@ class EsiFragmentRendererTest extends \PHPUnit_Framework_TestCase
|
|||||||
$strategy = new EsiFragmentRenderer(new Esi(), $this->getInlineStrategy());
|
$strategy = new EsiFragmentRenderer(new Esi(), $this->getInlineStrategy());
|
||||||
|
|
||||||
$request = Request::create('/');
|
$request = Request::create('/');
|
||||||
|
$request->setLocale('fr');
|
||||||
$request->headers->set('Surrogate-Capability', 'ESI/1.0');
|
$request->headers->set('Surrogate-Capability', 'ESI/1.0');
|
||||||
|
|
||||||
$this->assertEquals('<esi:include src="/" />', $strategy->render('/', $request)->getContent());
|
$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: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="/" 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());
|
$this->assertEquals('<esi:include src="http://localhost/_fragment?_path=_format%3Dhtml%26_locale%3Dfr%26_controller%3Dmain_controller" alt="http://localhost/_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());
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getInlineStrategy($called = false)
|
private function getInlineStrategy($called = false)
|
||||||
|
@ -38,7 +38,7 @@ class HIncludeFragmentRendererTest extends \PHPUnit_Framework_TestCase
|
|||||||
{
|
{
|
||||||
$strategy = new HIncludeFragmentRenderer(null, new UriSigner('foo'));
|
$strategy = new HIncludeFragmentRenderer(null, new UriSigner('foo'));
|
||||||
|
|
||||||
$this->assertEquals('<hx:include src="http://localhost/_fragment?_path=_format%3Dhtml%26_controller%3Dmain_controller&_hash=VI25qJj8J0qveB3bGKPhsJtexKg%3D"></hx:include>', $strategy->render(new ControllerReference('main_controller', array(), array()), Request::create('/'))->getContent());
|
$this->assertEquals('<hx:include src="http://localhost/_fragment?_path=_format%3Dhtml%26_locale%3Den%26_controller%3Dmain_controller&_hash=g4b3vtCnhkZBFKrciEFwG7fucVo%3D"></hx:include>', $strategy->render(new ControllerReference('main_controller', array(), array()), Request::create('/'))->getContent());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testRenderWithUri()
|
public function testRenderWithUri()
|
||||||
|
@ -51,6 +51,8 @@ class InlineFragmentRendererTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
$subRequest = Request::create('/_fragment?_path=_format%3Dhtml%26_controller%3Dmain_controller');
|
$subRequest = Request::create('/_fragment?_path=_format%3Dhtml%26_controller%3Dmain_controller');
|
||||||
$subRequest->attributes->replace(array('object' => $object, '_format' => 'html', '_controller' => 'main_controller'));
|
$subRequest->attributes->replace(array('object' => $object, '_format' => 'html', '_controller' => 'main_controller'));
|
||||||
|
$subRequest = Request::create('/_fragment?_path=_format%3Dhtml%26_locale%3Den%26_controller%3Dmain_controller');
|
||||||
|
$subRequest->attributes->replace(array('object' => $object, '_format' => 'html', '_controller' => 'main_controller', '_locale' => 'en'));
|
||||||
|
|
||||||
$kernel = $this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface');
|
$kernel = $this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface');
|
||||||
$kernel
|
$kernel
|
||||||
|
@ -28,11 +28,11 @@ class RoutableFragmentRendererTest extends \PHPUnit_Framework_TestCase
|
|||||||
public function getGenerateFragmentUriData()
|
public function getGenerateFragmentUriData()
|
||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
array('http://localhost/_fragment?_path=_format%3Dhtml%26_controller%3Dcontroller', new ControllerReference('controller', array(), array())),
|
array('http://localhost/_fragment?_path=_format%3Dhtml%26_locale%3Den%26_controller%3Dcontroller', new ControllerReference('controller', array(), array())),
|
||||||
array('http://localhost/_fragment?_path=_format%3Dxml%26_controller%3Dcontroller', new ControllerReference('controller', array('_format' => 'xml'), array())),
|
array('http://localhost/_fragment?_path=_format%3Dxml%26_locale%3Den%26_controller%3Dcontroller', new ControllerReference('controller', array('_format' => 'xml'), array())),
|
||||||
array('http://localhost/_fragment?_path=foo%3Dfoo%26_format%3Djson%26_controller%3Dcontroller', new ControllerReference('controller', array('foo' => 'foo', '_format' => 'json'), array())),
|
array('http://localhost/_fragment?_path=foo%3Dfoo%26_format%3Djson%26_locale%3Den%26_controller%3Dcontroller', new ControllerReference('controller', array('foo' => 'foo', '_format' => 'json'), array())),
|
||||||
array('http://localhost/_fragment?bar=bar&_path=foo%3Dfoo%26_format%3Dhtml%26_controller%3Dcontroller', new ControllerReference('controller', array('foo' => 'foo'), array('bar' => 'bar'))),
|
array('http://localhost/_fragment?bar=bar&_path=foo%3Dfoo%26_format%3Dhtml%26_locale%3Den%26_controller%3Dcontroller', new ControllerReference('controller', array('foo' => 'foo'), array('bar' => 'bar'))),
|
||||||
array('http://localhost/_fragment?foo=foo&_path=_format%3Dhtml%26_controller%3Dcontroller', new ControllerReference('controller', array(), array('foo' => 'foo'))),
|
array('http://localhost/_fragment?foo=foo&_path=_format%3Dhtml%26_locale%3Den%26_controller%3Dcontroller', new ControllerReference('controller', array(), array('foo' => 'foo'))),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -40,9 +40,10 @@ class RoutableFragmentRendererTest extends \PHPUnit_Framework_TestCase
|
|||||||
{
|
{
|
||||||
$request = Request::create('/');
|
$request = Request::create('/');
|
||||||
$request->attributes->set('_format', 'json');
|
$request->attributes->set('_format', 'json');
|
||||||
|
$request->setLocale('fr');
|
||||||
$controller = new ControllerReference('controller', array(), array());
|
$controller = new ControllerReference('controller', array(), array());
|
||||||
|
|
||||||
$this->assertEquals('http://localhost/_fragment?_path=_format%3Djson%26_controller%3Dcontroller', $this->getRenderer()->doGenerateFragmentUri($controller, $request));
|
$this->assertEquals('http://localhost/_fragment?_path=_format%3Djson%26_locale%3Dfr%26_controller%3Dcontroller', $this->getRenderer()->doGenerateFragmentUri($controller, $request));
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getRenderer()
|
private function getRenderer()
|
||||||
|
Reference in New Issue
Block a user