From c5c9ffc3b00106b6255f35edec2d2493118d8429 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Lucas?= Date: Fri, 6 Feb 2015 20:55:02 +0100 Subject: [PATCH] Add other unit tests and fix a bug which caused COPS to be in english on a french IE11 --- base.php | 7 ++++++- test/baseTest.php | 8 ++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/base.php b/base.php index bae8407..6f3eeaa 100644 --- a/base.php +++ b/base.php @@ -197,7 +197,12 @@ function getAcceptLanguages() { if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { // break up string into pieces (languages and q factors) - preg_match_all('/([a-z]{1,8}(-[a-z]{1,8})?)\s*(;\s*q\s*=\s*(1|0\.[0-9]+))?/i', $_SERVER['HTTP_ACCEPT_LANGUAGE'], $lang_parse); + $accept = $_SERVER['HTTP_ACCEPT_LANGUAGE']; + if (preg_match('/^(\w{2})-\w{2}$/', $accept, $matches)) { + // Special fix for IE11 which send fr-FR and nothing else + $accept = $accept . "," . $matches[1] . ";q=0.8"; + } + preg_match_all('/([a-z]{1,8}(-[a-z]{1,8})?)\s*(;\s*q\s*=\s*(1|0\.[0-9]+))?/i', $accept, $lang_parse); if (count($lang_parse[1])) { $langs = array(); diff --git a/test/baseTest.php b/test/baseTest.php index 5a8947e..4b46443 100644 --- a/test/baseTest.php +++ b/test/baseTest.php @@ -106,7 +106,10 @@ class BaseTest extends PHPUnit_Framework_TestCase return array ( array ("en", "en"), array ("fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3", "fr"), + array ("fr-FR", "fr"), array ("pt,en-us;q=0.7,en;q=0.3", "en"), + array ("pt-br,pt;q=0.8,en-us;q=0.5,en;q=0.3", "pt_BR"), + array ("pt-pt,pt;q=0.8,en;q=0.5,en-us;q=0.3", "pt_PT"), array ("zl", "en"), ); } @@ -129,8 +132,9 @@ class BaseTest extends PHPUnit_Framework_TestCase return array ( array ("en", "en"), array ("en-US", "en_US"), - array ("fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3", "fr"), - array ("fr-fr,fr;q=0.8,en-us;q=0.5,en;q=0.3", "fr_FR"), + array ("fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3", "fr"), // French locale with Firefox + array ("fr-FR,fr;q=0.8,en-US;q=0.6,en;q=0.4", "fr_FR"), // French locale with Chrome + array ("fr-FR", "fr_FR"), // French locale with IE11 array ("pt-br,pt;q=0.8,en-us;q=0.5,en;q=0.3", "pt_BR"), array ("zl", "zl"), );