Added right locales and updated locale tests to handle errors (#1168)

This commit is contained in:
Jenny Tam 2020-07-29 10:43:00 -07:00 committed by GitHub
parent e9090a4c2b
commit cb489c3e69
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 76 additions and 22 deletions

View file

@ -45,6 +45,8 @@ RUN sed -i 's/# en_US ISO-8859-1/en_US ISO-8859-1/g' /etc/locale.gen
RUN sed -i 's/# fr_FR@euro ISO-8859-15/fr_FR@euro ISO-8859-15/g' /etc/locale.gen
RUN sed -i 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/g' /etc/locale.gen
RUN sed -i 's/# de_DE.UTF-8 UTF-8/de_DE.UTF-8 UTF-8/g' /etc/locale.gen
RUN sed -i 's/# zh_CN GB2312/zh_CN GB2312/g' /etc/locale.gen
RUN sed -i 's/# zh_CN.GB18030 GB18030/zh_CN.GB18030 GB18030/g' /etc/locale.gen
RUN locale-gen
# set locale to utf-8

View file

@ -114,6 +114,8 @@ jobs:
sudo sed -i 's/# fr_FR@euro ISO-8859-15/fr_FR@euro ISO-8859-15/g' /etc/locale.gen
sudo sed -i 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/g' /etc/locale.gen
sudo sed -i 's/# de_DE.UTF-8 UTF-8/de_DE.UTF-8 UTF-8/g' /etc/locale.gen
sudo sed -i 's/# zh_CN GB2312/zh_CN GB2312/g' /etc/locale.gen
sudo sed -i 's/# zh_CN.GB18030 GB18030/zh_CN.GB18030 GB18030/g' /etc/locale.gen
sudo locale-gen
export LANG='en_US.UTF-8'
export LANGUAGE='en_US:en'

View file

@ -1,8 +1,8 @@
--TEST--
Test Chinese locale in Linux
--DESCRIPTION--
This test will invoke another php scirpt that is saved as GB2312(Simplified Chinese) ANSI format,
namely pdo_test_gb18030.php.
This test requires ODBC Driver 17.6 or above and will invoke another php script that
is saved as GB2312(Simplified Chinese) ANSI format, namely pdo_test_gb18030.php.
To run this test, create a temporary database first with the correct collation
CREATE DATABASE [GB18030test]
COLLATE Chinese_PRC_CI_AS
@ -19,6 +19,28 @@ $loc = setlocale(LC_ALL, 'zh_CN.gb18030');
if (empty($loc)) {
die("skip required gb18030 locale not available");
}
require_once('MsSetup.inc');
try {
$conn = new PDO("sqlsrv:server=$server", $uid, $pwd);
$msodbcsqlVer = $conn->getAttribute(PDO::ATTR_CLIENT_VERSION)['DriverVer'];
$version = explode(".", $msodbcsqlVer);
$msodbcsqlMaj = $version[0];
$msodbcsqlMin = $version[1];
if ($msodbcsqlMaj < 17) {
die("skip Unsupported ODBC driver version");
}
if ($msodbcsqlMaj == 17 && $msodbcsqlMin < 6) {
die("skip Unsupported ODBC driver version");
}
} catch (PDOException $e) {
die("skip Something went wrong during SKIPIF.");
}
?>
--FILE--
<?php
function runTest($conn, $tempDB)
@ -43,9 +65,11 @@ try {
} catch (PDOException $e) {
echo $e->getMessage() . PHP_EOL;
} finally {
$query = "DROP DATABASE $tempDB";
$conn->exec($query);
unset($conn);
if ($conn) {
$query = "DROP DATABASE $tempDB";
$conn->exec($query);
unset($conn);
}
}
?>

View file

@ -1,8 +1,8 @@
--TEST--
Test Chinese locale in Linux
--DESCRIPTION--
This test will invoke another php scirpt that is saved as GB2312(Simplified Chinese) ANSI format,
namely sqlsrv_test_gb18030.php.
This test requires ODBC Driver 17.6 or above and will invoke another php script that
is saved as GB2312(Simplified Chinese) ANSI format, namely sqlsrv_test_gb18030.php.
To run this test, create a temporary database first with the correct collation
CREATE DATABASE [GB18030test]
COLLATE Chinese_PRC_CI_AS
@ -14,41 +14,67 @@ Drop the temporary database when the test is finished.
PHPT_EXEC=true
--SKIPIF--
<?php
require('skipif_unix_ansitests.inc');
require_once('skipif_unix_ansitests.inc');
$loc = setlocale(LC_ALL, 'zh_CN.gb18030');
if (empty($loc)) {
die("skip required gb18030 locale not available");
}
require_once('MsSetup.inc');
$connectionInfo = array("UID"=>$userName, "PWD"=>$userPassword);
$conn = sqlsrv_connect($server, $connectionInfo);
if ($conn === false) {
die("skip Could not connect during SKIPIF.");
}
$msodbcsqlVer = sqlsrv_client_info($conn)["DriverVer"];
$msodbcsqlMaj = explode(".", $msodbcsqlVer)[0];
$msodbcsqlMin = explode(".", $msodbcsqlVer)[1];
if ($msodbcsqlMaj < 17) {
die("skip Unsupported ODBC driver version");
}
if ($msodbcsqlMaj == 17 && $msodbcsqlMin < 6) {
die("skip Unsupported ODBC driver version");
}
?>
--FILE--
<?php
function runTest()
{
require_once('MsSetup.inc');
require_once('MsSetup.inc');
try {
$options = array("Database"=>"master", "UID"=>$userName, "PWD"=>$userPassword);
$conn = sqlsrv_connect($server, $options);
if( $conn === false ) {
die(print_r(sqlsrv_errors(), true));
throw new Error("Failed to connect");
}
$tempDB = 'GB18030test' . rand(1, 100);
$query = "CREATE DATABASE $tempDB COLLATE Chinese_PRC_CI_AS";
$stmt = sqlsrv_query($conn, $query);
if ($stmt === false) {
echo "Failed to create the database $tempDB\n";
throw new Error("Failed to create the database $tempDB");
}
shell_exec("export LC_ALL=zh_CN.gb18030");
shell_exec("iconv -c -f GB2312 -t GB18030 sqlsrv_test_gb18030.php > test_gb18030.php");
print_r(shell_exec(PHP_BINARY." ".dirname(__FILE__)."/test_gb18030.php $tempDB"));
$query = "DROP DATABASE $tempDB";
sqlsrv_query($conn, $query);
sqlsrv_close($conn);
}
runTest();
print_r(shell_exec(PHP_BINARY." ".dirname(__FILE__)."/test_gb18030.php $tempDB"));
} catch (Error $err) {
echo $err->getMessage() . PHP_EOL;
print_r(sqlsrv_errors());
} finally {
if ($conn) {
if (!empty($tempDB)) {
$query = "DROP DATABASE $tempDB";
sqlsrv_query($conn, $query);
}
sqlsrv_close($conn);
}
}
?>
--EXPECT--