fix overwriting of request's locale if attribute _locale is missing
This commit is contained in:
parent
324686cf25
commit
da156d3f94
@ -50,7 +50,7 @@ class LocaleListener implements EventSubscriberInterface
|
|||||||
$request = $event->getRequest();
|
$request = $event->getRequest();
|
||||||
|
|
||||||
$request->setDefaultLocale($this->defaultLocale);
|
$request->setDefaultLocale($this->defaultLocale);
|
||||||
$this->setLocale($request, $request->attributes->get('_locale', $this->defaultLocale));
|
$this->setLocale($request, $request->attributes->get('_locale', $request->getLocale()));
|
||||||
|
|
||||||
array_unshift($this->locales, $request->getLocale());
|
array_unshift($this->locales, $request->getLocale());
|
||||||
}
|
}
|
||||||
|
@ -68,6 +68,17 @@ class LocaleListenerTest extends \PHPUnit_Framework_TestCase
|
|||||||
$listener->onKernelRequest($this->getEvent($request));
|
$listener->onKernelRequest($this->getEvent($request));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testRequestLocaleIsNotOverridden()
|
||||||
|
{
|
||||||
|
$request = Request::create('/');
|
||||||
|
$request->setLocale('de');
|
||||||
|
$listener = new LocaleListener('fr');
|
||||||
|
$event = $this->getEvent($request);
|
||||||
|
|
||||||
|
$listener->onKernelRequest($event);
|
||||||
|
$this->assertEquals('de', $request->getLocale());
|
||||||
|
}
|
||||||
|
|
||||||
private function getEvent(Request $request)
|
private function getEvent(Request $request)
|
||||||
{
|
{
|
||||||
return new GetResponseEvent($this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface'), $request, HttpKernelInterface::MASTER_REQUEST);
|
return new GetResponseEvent($this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface'), $request, HttpKernelInterface::MASTER_REQUEST);
|
||||||
|
Reference in New Issue
Block a user