1--TEST-- 2Test setlocale() function : basic functionality - passing multiple locales as argument 3--SKIPIF-- 4<?php 5if (setlocale(LC_ALL, 'invalid') === 'invalid') { die('skip setlocale() is broken /w musl'); } 6if (substr(PHP_OS, 0, 3) == 'WIN') { 7 die('skip Not valid for windows'); 8} 9if (setlocale(LC_ALL, "en_US.utf8", "Ko_KR.utf8", "zh_CN.utf8") === false) { 10 die('skip en_US.utf8/Ko_KR.utf8/zh_CN.utf8 locales not available'); 11} 12?> 13--FILE-- 14<?php 15/* Test the setlocale() when multiple locales are provided as argument */ 16 17function list_system_locales() { 18 // start the buffering of next command to internal output buffer 19 ob_start(); 20 21 // run the command 'locale -a' to fetch all locales available in the system 22 system('locale -a'); 23 24 // get the contents from the internal output buffer 25 $all_locales = ob_get_contents(); 26 27 // fflush and end the output buffering to internal output buffer 28 ob_end_clean(); 29 30 $system_locales = explode("\n", $all_locales); 31 32 // return all the locale found in the system 33 return $system_locales; 34} 35 36/* Collect existing system locales and get three locales that can be use to 37 pass as argument to setlocale() */ 38echo "*** Testing setlocale() by passing multiple locales as argument ***\n"; 39 40 41//set of currency symbol according to above list of locales 42$currency_symbol = array( 43 "en_US.utf8" => "USD", 44 "en_AU.utf8" => "AUD", 45 "ko_KR.utf8" => "KRW", 46 "zh_CN.utf8" => "CNY", 47 "de_DE.utf8" => "EUR", 48 "es_EC.utf8" => "USD", 49 "fr_FR.utf8" => "EUR", 50 "ja_JP.utf8" => "JPY", 51 "el_GR.utf8" => "EUR", 52 "nl_NL.utf8" =>"EUR" 53); 54 55// gather all the locales installed in the system 56$all_system_locales = list_system_locales(); 57 58// Now check for three locales that is present in the system and use that as argument to setlocale() 59if( in_array("en_US.utf8",$all_system_locales) || 60 in_array("Ko_KR.utf8",$all_system_locales) || 61 in_array("zh_CN.utf8",$all_system_locales) ) { 62 echo "-- Testing setlocale() by giving 'category' as LC_ALL & multiple locales(en_US.utf8, Ko_KR.utf8, zh_CN.utf8) --\n"; 63 64 // call setlocale() 65 $new_locale = setlocale(LC_ALL, "en_US.utf8", "Ko_KR.utf8", "zh_CN.utf8"); 66 67 // dump the name of the new locale set by setlocale() 68 var_dump($new_locale); 69 70 // check that new locale setting is effective 71 // use localeconv() to get the details of currently set locale 72 $locale_info = localeconv(); 73 $new_currency = trim($locale_info['int_curr_symbol']); 74 75 echo "Checking currency settings in the new locale, expected: ".$currency_symbol[$new_locale].", Found: ".$new_currency."\n"; 76 echo "Test "; 77 if( trim($currency_symbol[$new_locale]) == $new_currency) { 78 echo "PASSED.\n"; 79 } else { 80 echo "FAILED.\n"; 81 } 82} 83 84echo "Done\n"; 85?> 86--EXPECTF-- 87*** Testing setlocale() by passing multiple locales as argument *** 88-- Testing setlocale() by giving 'category' as LC_ALL & multiple locales(en_US.utf8, Ko_KR.utf8, zh_CN.utf8) -- 89string(%d) "%s" 90Checking currency settings in the new locale, expected: %s, Found: %s 91Test PASSED. 92Done 93