mb_decode_mimeheader_variation1.phpt 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. --TEST--
  2. Test mb_decode_mimeheader() function : usage variation
  3. --CREDITS--
  4. D. Kesley
  5. --SKIPIF--
  6. <?php
  7. extension_loaded('mbstring') or die('skip');
  8. function_exists('mb_decode_mimeheader') or die("skip mb_decode_mimeheader() is not available in this build");
  9. ?>
  10. --FILE--
  11. <?php
  12. /* Prototype : string mb_decode_mimeheader(string string)
  13. * Description: Decodes the MIME "encoded-word" in the string
  14. * Source code: ext/mbstring/mbstring.c
  15. * Alias to functions:
  16. */
  17. echo "*** Testing mb_decode_mimeheader() : usage variation ***\n";
  18. // Define error handler
  19. function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) {
  20. if (error_reporting() != 0) {
  21. // report non-silenced errors
  22. echo "Error: $err_no - $err_msg, $filename($linenum)\n";
  23. }
  24. }
  25. set_error_handler('test_error_handler');
  26. // Initialise function arguments not being substituted (if any)
  27. //get an unset variable
  28. $unset_var = 10;
  29. unset ($unset_var);
  30. // define some classes
  31. class classWithToString
  32. {
  33. public function __toString() {
  34. return "Class A object";
  35. }
  36. }
  37. class classWithoutToString
  38. {
  39. }
  40. // heredoc string
  41. $heredoc = <<<EOT
  42. hello world
  43. EOT;
  44. // get a resource variable
  45. $fp = fopen(__FILE__, "r");
  46. // add arrays
  47. $index_array = array (1, 2, 3);
  48. $assoc_array = array ('one' => 1, 'two' => 2);
  49. //array of values to iterate over
  50. $inputs = array(
  51. // int data
  52. 'int 0' => 0,
  53. 'int 1' => 1,
  54. 'int 12345' => 12345,
  55. 'int -12345' => -2345,
  56. // float data
  57. 'float 10.5' => 10.5,
  58. 'float -10.5' => -10.5,
  59. 'float 12.3456789000e10' => 12.3456789000e10,
  60. 'float -12.3456789000e10' => -12.3456789000e10,
  61. 'float .5' => .5,
  62. // array data
  63. 'empty array' => array(),
  64. 'int indexed array' => $index_array,
  65. 'associative array' => $assoc_array,
  66. 'nested arrays' => array('foo', $index_array, $assoc_array),
  67. // null data
  68. 'uppercase NULL' => NULL,
  69. 'lowercase null' => null,
  70. // boolean data
  71. 'lowercase true' => true,
  72. 'lowercase false' =>false,
  73. 'uppercase TRUE' =>TRUE,
  74. 'uppercase FALSE' =>FALSE,
  75. // empty data
  76. 'empty string DQ' => "",
  77. 'empty string SQ' => '',
  78. // object data
  79. 'instance of classWithToString' => new classWithToString(),
  80. 'instance of classWithoutToString' => new classWithoutToString(),
  81. // undefined data
  82. 'undefined var' => @$undefined_var,
  83. // unset data
  84. 'unset var' => @$unset_var,
  85. // resource variable
  86. 'resource' => $fp
  87. );
  88. // loop through each element of the array for string
  89. foreach($inputs as $key =>$value) {
  90. echo "\n--$key--\n";
  91. var_dump( mb_decode_mimeheader($value) );
  92. };
  93. fclose($fp);
  94. ?>
  95. ===DONE===
  96. --EXPECTF--
  97. *** Testing mb_decode_mimeheader() : usage variation ***
  98. --int 0--
  99. string(1) "0"
  100. --int 1--
  101. string(1) "1"
  102. --int 12345--
  103. string(5) "12345"
  104. --int -12345--
  105. string(5) "-2345"
  106. --float 10.5--
  107. string(4) "10.5"
  108. --float -10.5--
  109. string(5) "-10.5"
  110. --float 12.3456789000e10--
  111. string(12) "123456789000"
  112. --float -12.3456789000e10--
  113. string(13) "-123456789000"
  114. --float .5--
  115. string(3) "0.5"
  116. --empty array--
  117. Error: 2 - mb_decode_mimeheader() expects parameter 1 to be string, array given, %s(%d)
  118. NULL
  119. --int indexed array--
  120. Error: 2 - mb_decode_mimeheader() expects parameter 1 to be string, array given, %s(%d)
  121. NULL
  122. --associative array--
  123. Error: 2 - mb_decode_mimeheader() expects parameter 1 to be string, array given, %s(%d)
  124. NULL
  125. --nested arrays--
  126. Error: 2 - mb_decode_mimeheader() expects parameter 1 to be string, array given, %s(%d)
  127. NULL
  128. --uppercase NULL--
  129. string(0) ""
  130. --lowercase null--
  131. string(0) ""
  132. --lowercase true--
  133. string(1) "1"
  134. --lowercase false--
  135. string(0) ""
  136. --uppercase TRUE--
  137. string(1) "1"
  138. --uppercase FALSE--
  139. string(0) ""
  140. --empty string DQ--
  141. string(0) ""
  142. --empty string SQ--
  143. string(0) ""
  144. --instance of classWithToString--
  145. string(14) "Class A object"
  146. --instance of classWithoutToString--
  147. Error: 2 - mb_decode_mimeheader() expects parameter 1 to be string, object given, %s(%d)
  148. NULL
  149. --undefined var--
  150. string(0) ""
  151. --unset var--
  152. string(0) ""
  153. --resource--
  154. Error: 2 - mb_decode_mimeheader() expects parameter 1 to be string, resource given, %s(%d)
  155. NULL
  156. ===DONE===