Skip to content

Commit

Permalink
Fixed the handling of the intl locale when setting the default locale
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
stof committed Oct 11, 2012
1 parent 0247dd5 commit 8c6b7a4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Symfony/Component/HttpFoundation/Request.php
Expand Up @@ -1055,7 +1055,11 @@ public function getContentType()
*/
public function setDefaultLocale($locale)
{
$this->setPhpDefaultLocale($this->defaultLocale = $locale);
$this->defaultLocale = $locale;

if (null === $this->locale) {
$this->setPhpDefaultLocale($locale);
}
}

/**
Expand Down
21 changes: 21 additions & 0 deletions src/Symfony/Component/HttpFoundation/Tests/RequestTest.php
Expand Up @@ -900,6 +900,27 @@ public function testIsXmlHttpRequest()
$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();
Expand Down

0 comments on commit 8c6b7a4

Please sign in to comment.