1--TEST-- 2Test setlocale() function : usage variations - setting system locale = 0 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') === false) { 9 die('skip en_US.utf8 locale 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 17 * if locale functinality is not implemented in this platform. 18 * Source code: ext/standard/string.c 19*/ 20 21/* If locale is "0", the locale setting is not affected, only the current setting is returned */ 22 23echo "*** Testing setlocale() : usage variations - setting system locale = 0 ***\n"; 24$locale_info_before = array(); 25$locale_info_after = array(); 26 27//initially giving the locale 28setlocale(LC_ALL,"en_US.utf8"); 29 30echo "Locale info, before setting the locale\n"; 31//returns current locale,before executing setlocale(). 32$locale_info_before = localeconv(); 33 34var_dump($locale_info_before); 35 36//Testing setlocale() by giving locale = 0 37echo "Setting system locale, category = LC_ALL and locale = 0\n"; 38setlocale(LC_ALL, 0); 39 40echo "Locale info, after setting the locale\n"; 41//returns current locale,after executing setlocale(). 42$locale_info_after = localeconv(); 43 44var_dump($locale_info_after); 45 46echo "Checking locale in the system, Expected : no change in the existing locale\n"; 47echo "Test "; 48if($locale_info_before == $locale_info_after){ 49 echo "PASSED."; 50} else { 51 echo "FAILED."; 52} 53 54echo "\nDone\n"; 55?> 56--EXPECTF-- 57*** Testing setlocale() : usage variations - setting system locale = 0 *** 58Locale info, before setting the locale 59array(18) { 60 ["decimal_point"]=> 61 string(1) "." 62 ["thousands_sep"]=> 63 string(1) "," 64 ["int_curr_symbol"]=> 65 string(4) "USD " 66 ["currency_symbol"]=> 67 string(1) "$" 68 ["mon_decimal_point"]=> 69 string(1) "." 70 ["mon_thousands_sep"]=> 71 string(1) "," 72 ["positive_sign"]=> 73 string(0) "" 74 ["negative_sign"]=> 75 string(1) "-" 76 ["int_frac_digits"]=> 77 int(2) 78 ["frac_digits"]=> 79 int(2) 80 ["p_cs_precedes"]=> 81 int(1) 82 ["p_sep_by_space"]=> 83 int(0) 84 ["n_cs_precedes"]=> 85 int(1) 86 ["n_sep_by_space"]=> 87 int(0) 88 ["p_sign_posn"]=> 89 int(1) 90 ["n_sign_posn"]=> 91 int(1) 92 ["grouping"]=> 93 array(2) { 94 [0]=> 95 int(3) 96 [1]=> 97 int(3) 98 } 99 ["mon_grouping"]=> 100 array(2) { 101 [0]=> 102 int(3) 103 [1]=> 104 int(3) 105 } 106} 107Setting system locale, category = LC_ALL and locale = 0 108Locale info, after setting the locale 109array(18) { 110 ["decimal_point"]=> 111 string(1) "." 112 ["thousands_sep"]=> 113 string(1) "," 114 ["int_curr_symbol"]=> 115 string(4) "USD " 116 ["currency_symbol"]=> 117 string(1) "$" 118 ["mon_decimal_point"]=> 119 string(1) "." 120 ["mon_thousands_sep"]=> 121 string(1) "," 122 ["positive_sign"]=> 123 string(0) "" 124 ["negative_sign"]=> 125 string(1) "-" 126 ["int_frac_digits"]=> 127 int(2) 128 ["frac_digits"]=> 129 int(2) 130 ["p_cs_precedes"]=> 131 int(1) 132 ["p_sep_by_space"]=> 133 int(0) 134 ["n_cs_precedes"]=> 135 int(1) 136 ["n_sep_by_space"]=> 137 int(0) 138 ["p_sign_posn"]=> 139 int(1) 140 ["n_sign_posn"]=> 141 int(1) 142 ["grouping"]=> 143 array(2) { 144 [0]=> 145 int(3) 146 [1]=> 147 int(3) 148 } 149 ["mon_grouping"]=> 150 array(2) { 151 [0]=> 152 int(3) 153 [1]=> 154 int(3) 155 } 156} 157Checking locale in the system, Expected : no change in the existing locale 158Test PASSED. 159Done 160