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