1--TEST-- 2Test setlocale() function : usage variations - Setting all available locales in the platform 3--SKIPIF-- 4<?php 5if (substr(PHP_OS, 0, 3) == 'WIN') { 6 die('skip Not valid for windows'); 7} 8?> 9--FILE-- 10<?php 11/* Prototype : string setlocale (int $category , string $locale [,string $..] ) 12 : string setlocale(int $category , array $locale); 13 * Description: Sets locale information.Returns the new current locale , or FALSE 14 if locale functinality is not implemented in this platform. 15 * Source code: ext/standard/string.c 16*/ 17 18/* setlocale() to set all available locales in the system and check the success count */ 19echo "*** Testing setlocale() : usage variations ***\n"; 20 21function good_locale($locale) { 22 return $locale !== 'tt_RU@iqtelif.UTF-8'; 23} 24 25/* Prototype : array list_system_locales( void ) 26 * Description: To get the currently installed locle in this platform 27 * Arguments : Nil 28 * Returns : set of locale as array 29*/ 30function list_system_locales() { 31 // start the buffering of next command to internal output buffer 32 ob_start(); 33 34 // run the command 'locale -a' to fetch all locales available in the system 35 system('locale -a'); 36 37 // get the contents from the internal output buffer 38 $all_locales = ob_get_contents(); 39 40 // fflush and end the output buffering to internal output buffer 41 ob_end_clean(); 42 43 $system_locales = explode("\n", $all_locales); 44 45 // return all the locale found in the system, except for broken one 46 return array_filter($system_locales, 'good_locale'); 47} 48 49// gather all the locales installed in the system 50$all_system_locales = list_system_locales(); 51 52//try different locale names 53$failure_locale = array(); 54$success_count = 0; 55 56echo "-- Test setlocale() with all available locale in the system --\n"; 57// gather all locales installed in the system(stored $all_system_locales), 58// try n set each locale using setlocale() and keep track failures, if any 59foreach($all_system_locales as $value){ 60 //set locale to $value, if success, count increments 61 if(setlocale(LC_ALL,$value )){ 62 $success_count++; 63 } 64 else{ 65 //failure values are put in to an array $failure_locale 66 $failure_locale[] = $value; 67 } 68} 69 70echo "No of locales found on the machine = ".count($all_system_locales)."\n"; 71echo "No of setlocale() success = ".$success_count."\n"; 72echo "Expected no of failures = 0\n"; 73echo "Test "; 74// check if there were any failure of setlocale() function earlier, if any 75// failure then dump the list of failing locales 76if($success_count != count($all_system_locales)){ 77 echo "FAILED\n"; 78 echo "Names of locale() for which setlocale() failed ...\n"; 79 var_dump($failure_locale); 80} 81else{ 82 echo "PASSED\n"; 83} 84 85echo "Done\n"; 86?> 87--EXPECTF-- 88*** Testing setlocale() : usage variations *** 89-- Test setlocale() with all available locale in the system -- 90No of locales found on the machine = %d 91No of setlocale() success = %d 92Expected no of failures = 0 93Test PASSED 94Done 95