setlocale_basic2.phpt [plain text]
--TEST--
Test setlocale() function : basic functionality - set locale using an array
--SKIPIF--
<?php
if (substr(PHP_OS, 0, 3) == 'WIN') {
die('skip Not valid for windows');
}
if (setlocale(LC_ALL, "en_US.utf8", "en_AU.utf8", "ko_KR.utf8", "zh_CN.utf8", "de_DE.utf8", "es_EC.utf8", "fr_FR.utf8", "ja_JP.utf8", "el_GR.utf8", "nl_NL.utf8") === false) {
die('skip available locales not usable');
}
?>
--FILE--
<?php
function list_system_locales() {
ob_start();
system('locale -a');
$all_locales = ob_get_contents();
ob_end_clean();
$system_locales = explode("\n", $all_locales);
return $system_locales;
}
echo "*** Testing setlocale() with an array containing list of locales ***\n";
$common_locales = array(
"english_US"=> "en_US.utf8",
"english_AU" => "en_AU.utf8",
"korean_KR" => "ko_KR.utf8",
"Chinese_zh" => "zh_CN.utf8",
"germen_DE" => "de_DE.utf8",
"spanish_es" => "es_EC.utf8",
"french_FR" => "fr_FR.utf8",
"japanees_JP" => "ja_JP.utf8",
"greek_GR" => "el_GR.utf8",
"dutch_NL" => "nl_NL.utf8"
);
$currency_symbol = array(
"en_US.utf8" => "USD",
"en_AU.utf8" => "AUD",
"ko_KR.utf8" => "KRW",
"zh_CN.utf8" => "CNY",
"de_DE.utf8" => "EUR",
"es_EC.utf8" => "USD",
"fr_FR.utf8" => "EUR",
"ja_JP.utf8" => "JPY",
"el_GR.utf8" => "EUR",
"nl_NL.utf8" =>"EUR"
);
$all_system_locales = list_system_locales();
$list_of_locales = array();
foreach($common_locales as $value) {
if( in_array($value, $all_system_locales) ) {
$list_of_locales[] = $value;
}
}
echo "-- Testing setlocale() : 'category' argument as LC_ALL & 'locale' argument as an array --\n";
if ( count($list_of_locales) > 0 ) {
$new_locale = setlocale(LC_ALL, $list_of_locales);
var_dump($new_locale);
$locale_info = localeconv();
$new_currency = trim($locale_info['int_curr_symbol']);
echo "Checking currency settings in the new locale, expected: ".$currency_symbol[$new_locale].", Found: ".$new_currency."\n";
echo "Test ";
if(trim($currency_symbol[$new_locale]) == $new_currency){
echo "PASSED.\n";
} else {
echo "FAILED.\n";
}
} else {
echo "Test FAILED.\n";
}
echo "Done\n";
?>
--EXPECTF--
*** Testing setlocale() with an array containing list of locales ***
-- Testing setlocale() : 'category' argument as LC_ALL & 'locale' argument as an array --
string(%d) "%s"
Checking currency settings in the new locale, expected: %s, Found: %s
Test PASSED.
Done