setlocale_basic3.phpt 2.9 KB

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