Annotation of embedaddon/php/ext/standard/tests/strings/setlocale_variation1.phpt, revision 1.1.1.2
1.1 misho 1: --TEST--
2: Test setlocale() function : usage variations - passing multiple valid/invlaid 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: /* Prototype : string setlocale (int $category , string $locale [,string $..] )
15: : string setlocale(int $category , array $locale);
16: * Description: Sets locale information.Returns the new current locale , or FALSE
1.1.1.2 ! misho 17: if locale functionality is not implemented in this platform.
1.1 misho 18: * Source code: ext/standard/string.c
19: */
20:
21: /* Test the setlocale() when multiple valid/invalid locales are provided as argument */
22:
23: /* Prototype : array list_system_locales( void )
24: Description: To get the currently installed locle in this platform
25: Arguments : Nil
26: Returns : set of locale as array
27: */
28: function list_system_locales() {
29: // start the buffering of next command to internal output buffer
30: ob_start();
31:
32: // run the command 'locale -a' to fetch all locales available in the system
33: system('locale -a');
34:
35: // get the contents from the internal output buffer
36: $all_locales = ob_get_contents();
37:
38: // fflush and end the output buffering to internal output buffer
39: ob_end_clean();
40:
41: $system_locales = explode("\n", $all_locales);
42:
43: // return all the locale found in the system
44: return $system_locales;
45: }
46:
47: /* Collect existing system locales and get 2 valid locales that can be use to
48: pass as argument to setlocale(), pass 2 invalid arguments along with two valid arguments*/
49: echo "*** Testing setlocale() by passing multiple valid/invalid locales as argument ***\n";
50:
51: //set of currency symbol according to above list of locales
52: $currency_symbol = array(
53: "en_US.utf8" => "USD",
54: "en_AU.utf8" => "AUD",
55: "ko_KR.utf8" => "KRW",
56: "zh_CN.utf8" => "CNY",
57: "de_DE.utf8" => "EUR",
58: "es_EC.utf8" => "USD",
59: "fr_FR.utf8" => "EUR",
60: "ja_JP.utf8" => "JPY",
61: "el_GR.utf8" => "EUR",
62: "nl_NL.utf8" =>"EUR"
63: );
64:
65: // gather all the locales installed in the system
66: $all_system_locales = list_system_locales();
67:
68: // Now check for three locales that is present in the system and use that as argument to setlocale()
69: if( in_array("en_US.utf8",$all_system_locales) ||
70: in_array("Ko_KR.utf8",$all_system_locales) ||
71: in_array("zh_CN.utf8",$all_system_locales) ) {
72: echo "-- Testing setlocale() by giving 'category' as LC_ALL & multiple locales(en_US.invalid, en_US.utf8, Ko_KR.utf8, KO_KR.invalid, zh_CN.utf8) --\n";
73:
74: // call setlocale()
75: $new_locale = setlocale(LC_ALL, "en_US.invalid", "en_US.utf8", "Ko_KR.utf8", "KO_KR.invalid", "zh_CN.utf8");
76:
77: // dump the name of the new locale set by setlocale()
78: var_dump($new_locale);
79:
80: // check that new locale setting is effective
81: // use localeconv() to get the details of currently set locale
82: $locale_info = localeconv();
83: $new_currency = trim($locale_info['int_curr_symbol']);
84:
85: echo "Checking currency settings in the new locale, expected: ".$currency_symbol[$new_locale].", Found: ".$new_currency."\n";
86: echo "Test ";
87: if( trim($currency_symbol[$new_locale]) == $new_currency) {
88: echo "PASSED.\n";
89: } else {
90: echo "FAILED.\n";
91: }
92: }
93:
94: echo "Done\n";
95: ?>
96: --EXPECTF--
97: *** Testing setlocale() by passing multiple valid/invalid locales as argument ***
98: -- Testing setlocale() by giving 'category' as LC_ALL & multiple locales(en_US.invalid, en_US.utf8, Ko_KR.utf8, KO_KR.invalid, zh_CN.utf8) --
99: string(%d) "%s"
100: Checking currency settings in the new locale, expected: %s, Found: %s
101: Test PASSED.
102: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>