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

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:
Christophe Coevoet 2012-10-11 11:48:40 +02:00
parent 0247dd5237
commit 8c6b7a4912
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();