Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modified locale tests to work in both linux and mac #1074

Merged
merged 2 commits into from
Jan 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 3 additions & 30 deletions test/functional/pdo_sqlsrv/pdo_1063_locale_configs.phpt
Original file line number Diff line number Diff line change
@@ -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--
Expand All @@ -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";
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
64 changes: 53 additions & 11 deletions test/functional/pdo_sqlsrv/pdo_1063_test_locale.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
<?php
// This test is invoked by pdo_1063_locale_configs.phpt

function dropTable($conn, $tableName)
{
$tsql = "IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'" . $tableName . "') AND type in (N'U')) DROP TABLE $tableName";
$conn->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'];

Expand All @@ -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;
Expand Down
4 changes: 1 addition & 3 deletions test/functional/sqlsrv/TC43_FetchData.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ Fetch Field Data Test verifies the data retrieved via sqlsrv_get_field
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?
require('skipif_versions_old.inc');
?>
<?php require('skipif_versions_old.inc'); ?>
--FILE--
<?php

Expand Down
4 changes: 1 addition & 3 deletions test/functional/sqlsrv/TC44_FetchArray.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ by checking all fetch type modes.
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?
require('skipif_versions_old.inc');
?>
<?php require('skipif_versions_old.inc'); ?>
--FILE--
<?php
require_once('MsCommon.inc');
Expand Down
4 changes: 1 addition & 3 deletions test/functional/sqlsrv/TC46_FetchNextResult.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ Verifies the functionality of "sqlsrv_next_result"
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?
require('skipif_versions_old.inc');
?>
<?php require('skipif_versions_old.inc'); ?>
--FILE--
<?php
require_once('MsCommon.inc');
Expand Down
4 changes: 1 addition & 3 deletions test/functional/sqlsrv/TC51_StreamRead.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ can be successfully retrieved as streams.
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?
require('skipif_versions_old.inc');
?>
<?php require('skipif_versions_old.inc'); ?>
--FILE--
<?php
require_once('MsCommon.inc');
Expand Down
4 changes: 1 addition & 3 deletions test/functional/sqlsrv/TC55_StreamScrollable.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ Verifies the streaming behavior with scrollable resultsets.
--ENV--
PHPT_EXEC=true
--SKIPIF--
<?
require('skipif_versions_old.inc');
?>
<?php require('skipif_versions_old.inc'); ?>
--FILE--
<?php
require_once('MsCommon.inc');
Expand Down
33 changes: 3 additions & 30 deletions test/functional/sqlsrv/srv_1063_locale_configs.phpt
Original file line number Diff line number Diff line change
@@ -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--
Expand All @@ -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__)."/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";
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
Loading