Annotation of embedaddon/php/ext/standard/tests/strings/setlocale_basic1.phpt, revision 1.1
1.1 ! misho 1: --TEST--
! 2: Test setlocale() function : basic functionality - setting system locale to a specific
! 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", "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) {
! 9: die('skip available locales not usable');
! 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 ,
! 17: * or FALSE if locale functinality is not implemented in this platform.
! 18: * Source code: ext/standard/string.c
! 19: */
! 20:
! 21: /* test setlocale by specifying a specific locale as input */
! 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 set one among them,
! 48: Check the currency settings in the new locale */
! 49: echo "*** Testing setlocale() : basic functionality - set to a specific locale ***\n";
! 50:
! 51: //set of locales to be used
! 52: $common_locales = array(
! 53: "english_US"=> "en_US.utf8",
! 54: "english_AU" => "en_AU.utf8",
! 55: "korean_KR" => "ko_KR.utf8",
! 56: "Chinese_zh" => "zh_CN.utf8",
! 57: "germen_DE" => "de_DE.utf8",
! 58: "spanish_es" => "es_EC.utf8",
! 59: "french_FR" => "fr_FR.utf8",
! 60: "japanees_JP" => "ja_JP.utf8",
! 61: "greek_GR" => "el_GR.utf8",
! 62: "dutch_NL" => "nl_NL.utf8"
! 63: );
! 64:
! 65: //set of currency symbol according to above list of locales
! 66: $currency_symbol = array(
! 67: "en_US.utf8" => "USD",
! 68: "en_AU.utf8" => "AUD",
! 69: "ko_KR.utf8" => "KRW",
! 70: "zh_CN.utf8" => "CNY",
! 71: "de_DE.utf8" => "EUR",
! 72: "es_EC.utf8" => "USD",
! 73: "fr_FR.utf8" => "EUR",
! 74: "ja_JP.utf8" => "JPY",
! 75: "el_GR.utf8" => "EUR",
! 76: "nl_NL.utf8" =>"EUR"
! 77: );
! 78:
! 79: // gather all the locales installed in the system
! 80: $all_system_locales = list_system_locales();
! 81:
! 82: // set the system locale to a locale, choose the right locale by
! 83: // finding a common locale in commonly used locale stored in
! 84: // $common_locales & locales that are available in the system, stored
! 85: // in $all_system_locales.
! 86: echo "Setting system locale(LC_ALL) to ";
! 87: foreach($common_locales as $value) {
! 88: // check if a commonly used locale is installed in the system
! 89: if(in_array($value, $all_system_locales)){
! 90: echo "$value\n"; // print, this is found
! 91: // set the found locale as current locale
! 92: var_dump(setlocale(LC_ALL, $value ));
! 93: // stop here
! 94: break;
! 95: }
! 96: else{
! 97: // continue to check if next commonly locale is installed in the system
! 98: continue;
! 99: }
! 100: }
! 101:
! 102: // check that new locale setting is effective
! 103: // use localeconv() to get the details of currently set locale
! 104: $locale_info = localeconv();
! 105:
! 106: //checking currency settings in the new locale to see if the setlocale() was effective
! 107: $new_currency = trim($locale_info['int_curr_symbol']);
! 108: echo "Checking currency settings in the new locale, expected: ".$currency_symbol[$value].", Found: ".$new_currency."\n";
! 109: echo "Test ";
! 110: if(trim($currency_symbol[$value]) == $new_currency){
! 111: echo "PASSED.";
! 112: } else {
! 113: echo "FAILED.";
! 114: }
! 115:
! 116: echo "\nDone\n";
! 117: ?>
! 118: --EXPECTF--
! 119: *** Testing setlocale() : basic functionality - set to a specific locale ***
! 120: Setting system locale(LC_ALL) to %s
! 121: string(%d) %s
! 122: Checking currency settings in the new locale, expected: %s, Found: %s
! 123: Test PASSED.
! 124: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>