diff --git a/test/functional/pdo_sqlsrv/pdo_1063_locale_configs.phpt b/test/functional/pdo_sqlsrv/pdo_1063_locale_configs.phpt index 8438cb7f4..32c35f7a4 100644 --- a/test/functional/pdo_sqlsrv/pdo_1063_locale_configs.phpt +++ b/test/functional/pdo_sqlsrv/pdo_1063_locale_configs.phpt @@ -1,7 +1,7 @@ --TEST-- GitHub issue 1063 - make setting locale info configurable --DESCRIPTION-- -This test verifies that the users can configure using ini file to set application locale using the system locale or not. This test is valid for Linux and macOS systems only. +This test assumes LC_ALL is 'en_US.UTF-8' and verifies that the users can configure using ini file to set application locale using the system locale or not. This test is valid for Linux and macOS systems only. --ENV-- PHPT_EXEC=true --SKIPIF-- @@ -12,8 +12,8 @@ function runTest($val, $file, $locale) { print("\n***sqlsrv.SetLocaleInfo = $val\npdo_sqlsrv.set_locale_info = $val***\n\n"); shell_exec("echo 'sqlsrv.SetLocaleInfo = $val\npdo_sqlsrv.set_locale_info = $val' > $file"); - print_r(shell_exec(PHP_BINARY." ".dirname(__FILE__)."/pdo_1063_test_locale.php ")); - print_r(shell_exec(PHP_BINARY." ".dirname(__FILE__)."/pdo_1063_test_locale.php $locale")); + print_r(shell_exec(PHP_BINARY." ".dirname(__FILE__)."/pdo_1063_test_locale.php $val")); + print_r(shell_exec(PHP_BINARY." ".dirname(__FILE__)."/pdo_1063_test_locale.php $val $locale")); } $inifile = PHP_CONFIG_FILE_SCAN_DIR."/99-overrides.ini"; @@ -31,21 +31,12 @@ runTest(2, $inifile, $locale2); pdo_sqlsrv.set_locale_info = 0*** **Begin** -Current LC_MONETARY: C -Current LC_CTYPE: en_US.UTF-8 -Currency symbol: -Thousands_sep: Amount formatted: 10000.99 Friday December 3.14159 **End** **Begin** -Current LC_MONETARY: C -Current LC_CTYPE: en_US.UTF-8 -Setting LC_ALL: en_US.ISO-8859-1 -Currency symbol: $ -Thousands_sep: , Amount formatted: $10,000.99 Friday December @@ -56,21 +47,12 @@ December pdo_sqlsrv.set_locale_info = 1*** **Begin** -Current LC_MONETARY: C -Current LC_CTYPE: en_US.UTF-8 -Currency symbol: -Thousands_sep: Amount formatted: 10000.99 Friday December 3.14159 **End** **Begin** -Current LC_MONETARY: C -Current LC_CTYPE: en_US.UTF-8 -Setting LC_ALL: de_DE.UTF-8 -Currency symbol: € -Thousands_sep: . Amount formatted: 10.000,99 € Freitag Dezember @@ -81,21 +63,12 @@ Dezember pdo_sqlsrv.set_locale_info = 2*** **Begin** -Current LC_MONETARY: en_US.UTF-8 -Current LC_CTYPE: en_US.UTF-8 -Currency symbol: $ -Thousands_sep: , Amount formatted: $10,000.99 Friday December 3.14159 **End** **Begin** -Current LC_MONETARY: en_US.UTF-8 -Current LC_CTYPE: en_US.UTF-8 -Setting LC_ALL: de_DE.UTF-8 -Currency symbol: € -Thousands_sep: . Amount formatted: 10.000,99 € Freitag Dezember diff --git a/test/functional/pdo_sqlsrv/pdo_1063_test_locale.php b/test/functional/pdo_sqlsrv/pdo_1063_test_locale.php index 58be4d0dc..b37174494 100644 --- a/test/functional/pdo_sqlsrv/pdo_1063_test_locale.php +++ b/test/functional/pdo_sqlsrv/pdo_1063_test_locale.php @@ -1,4 +1,5 @@ exec($tsql); } -function printMoney($amt) +function printMoney($amt, $info) { // The money_format() function is deprecated in PHP 7.4, so use intl NumberFormatter - $info = localeconv(); - echo "Currency symbol: " . $info['currency_symbol'] . PHP_EOL; - echo "Thousands_sep: " . $info['thousands_sep'] . PHP_EOL; - $loc = setlocale(LC_MONETARY, 0); $symbol = $info['int_curr_symbol']; @@ -28,22 +25,67 @@ function printMoney($amt) echo PHP_EOL; } -// This test is invoked by pdo_1063_locale_configs.phpt require_once('MsSetup.inc'); -$locale = ($_SERVER['argv'][1] ?? ''); +$setLocaleInfo = ($_SERVER['argv'][1]); +$locale = ($_SERVER['argv'][2] ?? ''); echo "**Begin**" . PHP_EOL; -echo "Current LC_MONETARY: " . setlocale(LC_MONETARY, 0) . PHP_EOL; -echo "Current LC_CTYPE: " . setlocale(LC_CTYPE, 0) . PHP_EOL; +// Assuming LC_ALL is 'en_US.UTF-8', so is LC_CTYPE +// But default LC_MONETARY varies +$ctype = 'en_US.UTF-8'; +switch ($setLocaleInfo) { + case 0: + case 1: + $m = 'C'; $symbol = ''; $sep = ''; + break; + case 2: + $m = 'en_US.UTF-8'; $symbol = '$'; $sep = ','; + break; + default: + die("Unexpected $setLocaleInfo\n"); + break; +} + +$m1 = setlocale(LC_MONETARY, 0); +if ($m !== $m1) { + echo "Unexpected LC_MONETARY: $m1" . PHP_EOL; +} +$c1 = setlocale(LC_CTYPE, 0); +if ($ctype !== $c1) { + echo "Unexpected LC_CTYPE: $c1" . PHP_EOL; +} + +// Set a different locale, if the input is not empty if (!empty($locale)) { $loc = setlocale(LC_ALL, $locale); - echo "Setting LC_ALL: " . $loc . PHP_EOL; + if ($loc !== $locale) { + echo "Unexpected $loc for LC_ALL " . PHP_EOL; + } + + // Currency symbol and thousands separator in Linux and macOS may be different + if ($loc === 'de_DE.UTF-8') { + $symbol = strtoupper(PHP_OS) === 'LINUX' ? '€' : 'Eu'; + $sep = strtoupper(PHP_OS) === 'LINUX' ? '.' : ''; + } else { + $symbol = '$'; + $sep = ','; + } +} + +$info = localeconv(); +if ($symbol !== $info['currency_symbol']) { + echo "$locale: Expected currency symbol '$symbol' but get '" . $info['currency_symbol'] . "'"; + echo PHP_EOL; +} +if ($sep !== $info['thousands_sep']) { + echo "$locale: Expected thousands separator '$sep' but get '" . $info['currency_symbol'] . "'"; + echo PHP_EOL; } $n1 = 10000.98765; -printMoney($n1); +printMoney($n1, $info); echo strftime("%A", strtotime("12/25/2020")) . PHP_EOL; echo strftime("%B", strtotime("12/25/2020")) . PHP_EOL; diff --git a/test/functional/sqlsrv/TC43_FetchData.phpt b/test/functional/sqlsrv/TC43_FetchData.phpt index 7228d2d4c..ad446f0c9 100644 --- a/test/functional/sqlsrv/TC43_FetchData.phpt +++ b/test/functional/sqlsrv/TC43_FetchData.phpt @@ -3,9 +3,7 @@ Fetch Field Data Test verifies the data retrieved via sqlsrv_get_field --ENV-- PHPT_EXEC=true --SKIPIF-- - + --FILE-- + --FILE-- + --FILE-- + --FILE-- + --FILE-- $file"); - print_r(shell_exec(PHP_BINARY." ".dirname(__FILE__)."/srv_1063_test_locale.php ")); - print_r(shell_exec(PHP_BINARY." ".dirname(__FILE__)."/srv_1063_test_locale.php $locale")); + print_r(shell_exec(PHP_BINARY." ".dirname(__FILE__)."/srv_1063_test_locale.php $val")); + print_r(shell_exec(PHP_BINARY." ".dirname(__FILE__)."/srv_1063_test_locale.php $val $locale")); } $inifile = PHP_CONFIG_FILE_SCAN_DIR."/99-overrides.ini"; @@ -31,21 +31,12 @@ runTest(2, $inifile, $locale2); pdo_sqlsrv.set_locale_info = 0*** **Begin** -Current LC_MONETARY: C -Current LC_CTYPE: en_US.UTF-8 -Currency symbol: -Thousands_sep: Amount formatted: 10000.99 Friday December 3.14159 **End** **Begin** -Current LC_MONETARY: C -Current LC_CTYPE: en_US.UTF-8 -Setting LC_ALL: en_US.ISO-8859-1 -Currency symbol: $ -Thousands_sep: , Amount formatted: $10,000.99 Friday December @@ -56,21 +47,12 @@ December pdo_sqlsrv.set_locale_info = 1*** **Begin** -Current LC_MONETARY: C -Current LC_CTYPE: en_US.UTF-8 -Currency symbol: -Thousands_sep: Amount formatted: 10000.99 Friday December 3.14159 **End** **Begin** -Current LC_MONETARY: C -Current LC_CTYPE: en_US.UTF-8 -Setting LC_ALL: de_DE.UTF-8 -Currency symbol: € -Thousands_sep: . Amount formatted: 10.000,99 € Freitag Dezember @@ -81,21 +63,12 @@ Dezember pdo_sqlsrv.set_locale_info = 2*** **Begin** -Current LC_MONETARY: en_US.UTF-8 -Current LC_CTYPE: en_US.UTF-8 -Currency symbol: $ -Thousands_sep: , Amount formatted: $10,000.99 Friday December 3.14159 **End** **Begin** -Current LC_MONETARY: en_US.UTF-8 -Current LC_CTYPE: en_US.UTF-8 -Setting LC_ALL: de_DE.UTF-8 -Currency symbol: € -Thousands_sep: . Amount formatted: 10.000,99 € Freitag Dezember diff --git a/test/functional/sqlsrv/srv_1063_test_locale.php b/test/functional/sqlsrv/srv_1063_test_locale.php index 7efe524e5..06ab387da 100644 --- a/test/functional/sqlsrv/srv_1063_test_locale.php +++ b/test/functional/sqlsrv/srv_1063_test_locale.php @@ -1,4 +1,5 @@ setTextAttribute(NumberFormatter::CURRENCY_CODE, $symbol); $fmt->setAttribute(NumberFormatter::FRACTION_DIGITS, 2); - echo $fmt->format($amt); + echo $fmt->format($amt) . PHP_EOL; } - echo PHP_EOL; } -// This test is invoked by srv_1063_locale_configs.phpt require_once('MsSetup.inc'); -$locale = ($_SERVER['argv'][1] ?? ''); +$setLocaleInfo = ($_SERVER['argv'][1]); +$locale = ($_SERVER['argv'][2] ?? ''); echo "**Begin**" . PHP_EOL; -echo "Current LC_MONETARY: " . setlocale(LC_MONETARY, 0) . PHP_EOL; -echo "Current LC_CTYPE: " . setlocale(LC_CTYPE, 0) . PHP_EOL; +// Assuming LC_ALL is 'en_US.UTF-8', so is LC_CTYPE +// But default LC_MONETARY varies +$ctype = 'en_US.UTF-8'; +switch ($setLocaleInfo) { + case 0: + case 1: + $m = 'C'; $symbol = ''; $sep = ''; + break; + case 2: + $m = 'en_US.UTF-8'; $symbol = '$'; $sep = ','; + break; + default: + fatalError("Unexpected $setLocaleInfo\n"); + break; +} + +$m1 = setlocale(LC_MONETARY, 0); +if ($m !== $m1) { + echo "Unexpected LC_MONETARY: $m1" . PHP_EOL; +} +$c1 = setlocale(LC_CTYPE, 0); +if ($ctype !== $c1) { + echo "Unexpected LC_CTYPE: $c1" . PHP_EOL; +} + +// Set a different locale, if the input is not empty if (!empty($locale)) { $loc = setlocale(LC_ALL, $locale); - echo "Setting LC_ALL: " . $loc . PHP_EOL; + if ($loc !== $locale) { + echo "Unexpected $loc for LC_ALL " . PHP_EOL; + } + + // Currency symbol and thousands separator in Linux and macOS may be different + if ($loc === 'de_DE.UTF-8') { + $symbol = strtoupper(PHP_OS) === 'LINUX' ? '€' : 'Eu'; + $sep = strtoupper(PHP_OS) === 'LINUX' ? '.' : ''; + } else { + $symbol = '$'; + $sep = ','; + } +} + +$info = localeconv(); + +if ($symbol !== $info['currency_symbol']) { + echo "$locale: Expected currency symbol '$symbol' but get '" . $info['currency_symbol'] . "'"; + echo PHP_EOL; +} +if ($sep !== $info['thousands_sep']) { + echo "$locale: Expected thousands separator '$sep' but get '" . $info['currency_symbol'] . "'"; + echo PHP_EOL; } $n1 = 10000.98765; -printMoney($n1); +printMoney($n1, $info); echo strftime("%A", strtotime("12/25/2020")) . PHP_EOL; echo strftime("%B", strtotime("12/25/2020")) . PHP_EOL; diff --git a/test/functional/sqlsrv/test_stream_large_data.phpt b/test/functional/sqlsrv/test_stream_large_data.phpt index 414baa225..f73594e40 100644 --- a/test/functional/sqlsrv/test_stream_large_data.phpt +++ b/test/functional/sqlsrv/test_stream_large_data.phpt @@ -1,9 +1,7 @@ --TEST-- streaming large amounts of data into a database and getting it out as a string exactly the same. --SKIPIF-- - + --FILE--