Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
[HttpFoundation] added Request::getLanguage test
  • Loading branch information
jfsimon committed Mar 18, 2013
commit f8c69d5b63063183513abfb80e00ee50e9b4c934
8 changes: 6 additions & 2 deletions src/Symfony/Component/HttpFoundation/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -1309,7 +1309,9 @@ public function getLanguages()
for ($i = 0, $max = count($codes); $i < $max; $i++) {
if ($i == 0) {
$lang = strtolower($codes[0]);
if(!in_array($lang, $this->languages) {
// First segment of compound language codes
// is added to supported languages list
if (!in_array($lang, $this->languages)) {
$this->languages[] = $lang;
}
} else {
Expand All @@ -1319,7 +1321,9 @@ public function getLanguages()
}
}

$this->languages[] = $lang;
if (!in_array($lang, $this->languages)) {
$this->languages[] = $lang;
}
}

return $this->languages;
Expand Down
8 changes: 6 additions & 2 deletions src/Symfony/Component/HttpFoundation/Tests/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -951,8 +951,8 @@ public function testGetLanguages()

$request = new Request();
$request->headers->set('Accept-language', 'zh, en-us; q=0.8, en; q=0.6');
$this->assertEquals(array('zh', 'en_US', 'en'), $request->getLanguages());
$this->assertEquals(array('zh', 'en_US', 'en'), $request->getLanguages());
$this->assertEquals(array('zh', 'en', 'en_US'), $request->getLanguages());
$this->assertEquals(array('zh', 'en', 'en_US'), $request->getLanguages());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jfsimon This is a BC break as en would now be preferred over en_US here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stof oh, good one! I have not thought about the order...


$request = new Request();
$request->headers->set('Accept-language', 'zh, en-us; q=0.6, en; q=0.8');
Expand All @@ -969,6 +969,10 @@ public function testGetLanguages()
$request = new Request();
$request->headers->set('Accept-language', 'zh, i-cherokee; q=0.6');
$this->assertEquals(array('zh', 'cherokee'), $request->getLanguages());

$request = new Request();
$request->headers->set('Accept-language', 'en-us');
$this->assertEquals(array('en', 'en_US'), $request->getLanguages());
}

public function testGetRequestFormat()
Expand Down