Skip to content

Commit

Permalink
merged branch stof/request_intl_locale (PR #5727)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
fabpot committed Oct 11, 2012
2 parents 0247dd5 + 8c6b7a4 commit 593b845
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 593b845

Please sign in to comment.