merged branch stof/request_intl_locale (PR #5727)

This PR was merged into the 2.1 branch.

Commits
-------

8c6b7a4 Fixed the handling of the intl locale when setting the default locale

Discussion
----------

Fixed the handling of the intl locale when setting the default locale

Bug fix: yes
Feature addition: no
Backwards compatibility break: no
Symfony2 tests pass: yes
Fixes the following tickets: none

Calling setDefaultLocale was replacing the intl locale even if the locale
was already set in the Request, thus leading to a different value than the
request locale.
This commit is contained in:
Fabien Potencier 2012-10-11 14:22:40 +02:00
commit 593b845912
2 changed files with 26 additions and 1 deletions

View File

@ -1055,7 +1055,11 @@ class Request
*/
public function setDefaultLocale($locale)
{
$this->setPhpDefaultLocale($this->defaultLocale = $locale);
$this->defaultLocale = $locale;
if (null === $this->locale) {
$this->setPhpDefaultLocale($locale);
}
}
/**

View File

@ -900,6 +900,27 @@ class RequestTest extends \PHPUnit_Framework_TestCase
$this->assertFalse($request->isXmlHttpRequest());
}
public function testIntlLocale()
{
if (!extension_loaded('intl')) {
$this->markTestSkipped('The intl extension is needed to run this test.');
}
$request = new Request();
$request->setDefaultLocale('fr');
$this->assertEquals('fr', $request->getLocale());
$this->assertEquals('fr', \Locale::getDefault());
$request->setLocale('en');
$this->assertEquals('en', $request->getLocale());
$this->assertEquals('en', \Locale::getDefault());
$request->setDefaultLocale('de');
$this->assertEquals('en', $request->getLocale());
$this->assertEquals('en', \Locale::getDefault());
}
public function testGetCharsets()
{
$request = new Request();