Browse Source

Add other unit tests and fix a bug which caused COPS to be in english on a french IE11

master
Sébastien Lucas 9 years ago
parent
commit
c5c9ffc3b0
2 changed files with 12 additions and 3 deletions
  1. +6
    -1
      base.php
  2. +6
    -2
      test/baseTest.php

+ 6
- 1
base.php View File

@@ -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();


+ 6
- 2
test/baseTest.php View File

@@ -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"),
);


Loading…
Cancel
Save