From 62944347efe3ecd07d1135d9cd2c86a1f72d0171 Mon Sep 17 00:00:00 2001 From: Jenny Tam Date: Fri, 29 Dec 2017 12:00:00 -0800 Subject: [PATCH] Fix tests with locales --- test/functional/sqlsrv/MsCommon.inc | 10 ++++++++++ test/functional/sqlsrv/TC34_PrepAndExec.phpt | 9 ++------- test/functional/sqlsrv/TC42_FetchField.phpt | 9 ++------- test/functional/sqlsrv/TC43_FetchData.phpt | 9 ++------- test/functional/sqlsrv/TC44_FetchArray.phpt | 10 ++-------- test/functional/sqlsrv/TC45_FetchObject.phpt | 9 ++------- test/functional/sqlsrv/TC46_FetchNextResult.phpt | 10 ++-------- test/functional/sqlsrv/TC48_FetchScrollable.phpt | 9 ++------- test/functional/sqlsrv/TC51_StreamRead.phpt | 9 ++------- test/functional/sqlsrv/TC55_StreamScrollable.phpt | 10 ++-------- test/functional/sqlsrv/test_stream_large_data.phpt | 9 ++------- 11 files changed, 30 insertions(+), 73 deletions(-) diff --git a/test/functional/sqlsrv/MsCommon.inc b/test/functional/sqlsrv/MsCommon.inc index e01802e1..db7b3e10 100644 --- a/test/functional/sqlsrv/MsCommon.inc +++ b/test/functional/sqlsrv/MsCommon.inc @@ -442,6 +442,16 @@ function handleErrors() } } +function setUSLocale() +{ + if (!isWindows()) { + // macOS the locale names are different in Linux or macOS + $locale = strtoupper(PHP_OS) === 'LINUX' ? "en_US.ISO-8859-1" : "en_US.ISO8859-1"; + + setlocale(LC_ALL, $locale); + } +} + // non-UTF8 locale support in ODBC 17 and above only // if AE enabled, only supported in Windows (AE limitations) function isLocaleSupported() diff --git a/test/functional/sqlsrv/TC34_PrepAndExec.phpt b/test/functional/sqlsrv/TC34_PrepAndExec.phpt index d77fef2c..06d2f14a 100644 --- a/test/functional/sqlsrv/TC34_PrepAndExec.phpt +++ b/test/functional/sqlsrv/TC34_PrepAndExec.phpt @@ -8,9 +8,7 @@ PHPT_EXEC=true --SKIPIF-- --FILE-- @@ -90,10 +88,7 @@ function prepareAndExecute($noPasses) } // locale must be set before 1st connection -if (!isWindows()) { - setlocale(LC_ALL, "en_US.ISO-8859-1"); -} - +setUSLocale(); $testName = "Statement - Prepare and Execute"; // test ansi only if windows or non-UTF8 locales are supported (ODBC 17 and above) diff --git a/test/functional/sqlsrv/TC42_FetchField.phpt b/test/functional/sqlsrv/TC42_FetchField.phpt index dc715b19..ef030b16 100644 --- a/test/functional/sqlsrv/TC42_FetchField.phpt +++ b/test/functional/sqlsrv/TC42_FetchField.phpt @@ -8,9 +8,7 @@ PHPT_EXEC=true --SKIPIF-- --FILE-- @@ -68,10 +66,7 @@ function fetchFields() } // locale must be set before 1st connection -if (!isWindows()) { - setlocale(LC_ALL, "en_US.ISO-8859-1"); -} - +setUSLocale(); $testName = "Fetch - Field"; // test ansi only if windows or non-UTF8 locales are supported (ODBC 17 and above) diff --git a/test/functional/sqlsrv/TC43_FetchData.phpt b/test/functional/sqlsrv/TC43_FetchData.phpt index 5e03407c..6e8e60f3 100644 --- a/test/functional/sqlsrv/TC43_FetchData.phpt +++ b/test/functional/sqlsrv/TC43_FetchData.phpt @@ -5,9 +5,7 @@ PHPT_EXEC=true --SKIPIF-- --FILE-- @@ -97,10 +95,7 @@ function checkData($col, $actual, $expected) return ($success); } -if (!isWindows()) { - setlocale(LC_ALL, "en_US.ISO-8859-1"); -} - +setUSLocale(); $testName = "Fetch - Field Data"; // test ansi only if windows or non-UTF8 locales are supported (ODBC 17 and above) diff --git a/test/functional/sqlsrv/TC44_FetchArray.phpt b/test/functional/sqlsrv/TC44_FetchArray.phpt index 556bd562..ab7e88c8 100644 --- a/test/functional/sqlsrv/TC44_FetchArray.phpt +++ b/test/functional/sqlsrv/TC44_FetchArray.phpt @@ -8,9 +8,7 @@ PHPT_EXEC=true --SKIPIF-- --FILE-- @@ -153,11 +151,7 @@ function checkData($row, $stmt, $index, $mode) } // locale must be set before 1st connection -if (!isWindows()) { - setlocale(LC_ALL, "en_US.ISO-8859-1"); -} - -global $testName; +setUSLocale(); $testName = "Fetch - Array"; // test ansi only if windows or non-UTF8 locales are supported (ODBC 17 and above) diff --git a/test/functional/sqlsrv/TC45_FetchObject.phpt b/test/functional/sqlsrv/TC45_FetchObject.phpt index 1c4e8f30..588620c5 100644 --- a/test/functional/sqlsrv/TC45_FetchObject.phpt +++ b/test/functional/sqlsrv/TC45_FetchObject.phpt @@ -7,9 +7,7 @@ PHPT_EXEC=true --SKIPIF-- --FILE-- @@ -128,10 +126,7 @@ function checkData($rows, $fields, $actualValues, $expectedValues) } // locale must be set before 1st connection -if (!isWindows()) { - setlocale(LC_ALL, "en_US.ISO-8859-1"); -} - +setUSLocale(); $testName = "Fetch - Object"; // test ansi only if windows or non-UTF8 locales are supported (ODBC 17 and above) diff --git a/test/functional/sqlsrv/TC46_FetchNextResult.phpt b/test/functional/sqlsrv/TC46_FetchNextResult.phpt index bcd5e9e8..58d8fdfa 100644 --- a/test/functional/sqlsrv/TC46_FetchNextResult.phpt +++ b/test/functional/sqlsrv/TC46_FetchNextResult.phpt @@ -7,9 +7,7 @@ PHPT_EXEC=true --SKIPIF-- --FILE-- @@ -86,11 +84,7 @@ function fetchFields() } // locale must be set before 1st connection -if (!isWindows()) { - setlocale(LC_ALL, "en_US.ISO-8859-1"); -} - -global $testName; +setUSLocale(); $testName = "Fetch - Next Result"; // test ansi only if windows or non-UTF8 locales are supported (ODBC 17 and above) diff --git a/test/functional/sqlsrv/TC48_FetchScrollable.phpt b/test/functional/sqlsrv/TC48_FetchScrollable.phpt index 09012e67..b8b32a5b 100644 --- a/test/functional/sqlsrv/TC48_FetchScrollable.phpt +++ b/test/functional/sqlsrv/TC48_FetchScrollable.phpt @@ -7,9 +7,7 @@ PHPT_EXEC=true --SKIPIF-- --FILE-- @@ -137,10 +135,7 @@ function checkData($rows, $fields, $actualValues, $expectedValues) } // locale must be set before 1st connection -if (!isWindows()) { - setlocale(LC_ALL, "en_US.ISO-8859-1"); -} - +setUSLocale(); $testName = "Fetch - Scrollable"; // test ansi only if windows or non-UTF8 locales are supported (ODBC 17 and above) diff --git a/test/functional/sqlsrv/TC51_StreamRead.phpt b/test/functional/sqlsrv/TC51_StreamRead.phpt index 6268bceb..4d6e79bc 100644 --- a/test/functional/sqlsrv/TC51_StreamRead.phpt +++ b/test/functional/sqlsrv/TC51_StreamRead.phpt @@ -7,9 +7,7 @@ can be successfully retrieved as streams. PHPT_EXEC=true --SKIPIF-- --FILE-- @@ -126,10 +124,7 @@ function checkData($col, $actual, $expected) } // locale must be set before 1st connection -if (!isWindows()) { - setlocale(LC_ALL, "en_US.ISO-8859-1"); -} - +setUSLocale(); global $testName; $testName = "Stream - Read"; diff --git a/test/functional/sqlsrv/TC55_StreamScrollable.phpt b/test/functional/sqlsrv/TC55_StreamScrollable.phpt index 14d8b345..6df4f3a7 100644 --- a/test/functional/sqlsrv/TC55_StreamScrollable.phpt +++ b/test/functional/sqlsrv/TC55_StreamScrollable.phpt @@ -7,9 +7,7 @@ PHPT_EXEC=true --SKIPIF-- --FILE-- @@ -163,11 +161,7 @@ function checkData($col, $actual, $expected) } // locale must be set before 1st connection -if (!isWindows()) { - setlocale(LC_ALL, "en_US.ISO-8859-1"); -} - -global $testName; +setUSLocale(); $testName = "Stream - Scrollable"; // error message expected with AE enabled diff --git a/test/functional/sqlsrv/test_stream_large_data.phpt b/test/functional/sqlsrv/test_stream_large_data.phpt index d5a26070..1cf59696 100644 --- a/test/functional/sqlsrv/test_stream_large_data.phpt +++ b/test/functional/sqlsrv/test_stream_large_data.phpt @@ -3,10 +3,7 @@ streaming large amounts of data into a database and getting it out as a string e --SKIPIF-- --FILE-- @@ -254,9 +251,7 @@ function CompareLengths($filesizes, $lens1, $lens2, $count, $useUTF8) } // locale must be set before 1st connection -if (!isWindows()) { - setlocale(LC_ALL, "en_US.ISO-8859-1"); -} +setUSLocale(); // test ansi only if windows or non-UTF8 locales are supported (ODBC 17 and above) if (isLocaleSupported()) {