merged branch hason/translationrequest (PR #4650)
Commits -------8ae0fa2
[FrameworkBundle] Fixed locale detection from request Discussion ---------- [FrameworkBundle] Fixed locale detection from request --------------------------------------------------------------------------- by travisbot at 2012-06-25T10:09:24Z This pull request [passes](http://travis-ci.org/symfony/symfony/builds/1699743) (merged8ae0fa21
into03c8d4d2
).
This commit is contained in:
commit
84e619c016
@ -80,6 +80,46 @@ class TranslatorTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertEquals('no translation', $translator->trans('no translation'));
|
||||
}
|
||||
|
||||
public function testGetLocale()
|
||||
{
|
||||
$request = $this->getMock('Symfony\Component\HttpFoundation\Request');
|
||||
|
||||
$request
|
||||
->expects($this->once())
|
||||
->method('getLocale')
|
||||
->will($this->returnValue('en'))
|
||||
;
|
||||
|
||||
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
|
||||
|
||||
$container
|
||||
->expects($this->exactly(2))
|
||||
->method('isScopeActive')
|
||||
->with('request')
|
||||
->will($this->onConsecutiveCalls(false, true))
|
||||
;
|
||||
|
||||
$container
|
||||
->expects($this->once())
|
||||
->method('has')
|
||||
->with('request')
|
||||
->will($this->returnValue(true))
|
||||
;
|
||||
|
||||
$container
|
||||
->expects($this->once())
|
||||
->method('get')
|
||||
->with('request')
|
||||
->will($this->returnValue($request))
|
||||
;
|
||||
|
||||
$translator = new Translator($container, new MessageSelector());
|
||||
|
||||
$this->assertNull($translator->getLocale());
|
||||
$this->assertSame('en', $translator->getLocale());
|
||||
$this->assertSame('en', $translator->getLocale());
|
||||
}
|
||||
|
||||
protected function getCatalogue($locale, $messages)
|
||||
{
|
||||
$catalogue = new MessageCatalogue($locale);
|
||||
|
@ -65,7 +65,7 @@ class Translator extends BaseTranslator
|
||||
*/
|
||||
public function getLocale()
|
||||
{
|
||||
if (null === $this->locale && $this->container->isScopeActive('request')) {
|
||||
if (null === $this->locale && $this->container->isScopeActive('request') && $this->container->has('request')) {
|
||||
$this->locale = $this->container->get('request')->getLocale();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user