mb_encode_mimeheader_variation2.phpt 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. --TEST--
  2. Test mb_encode_mimeheader() function : usage variations - Pass different data types to $charset arg
  3. --SKIPIF--
  4. <?php
  5. extension_loaded('mbstring') or die('skip');
  6. function_exists('mb_encode_mimeheader') or die("skip mb_encode_mimeheader() is not available in this build");
  7. ?>
  8. --FILE--
  9. <?php
  10. /* Prototype : string mb_encode_mimeheader
  11. * (string $str [, string $charset [, string $transfer_encoding [, string $linefeed [, int $indent]]]])
  12. * Description: Converts the string to MIME "encoded-word" in the format of =?charset?(B|Q)?encoded_string?=
  13. * Source code: ext/mbstring/mbstring.c
  14. */
  15. /*
  16. * Pass different data types to $charset argument to see how mb_encode_mimeheader() behaves
  17. */
  18. echo "*** Testing mb_encode_mimeheader() : usage variations ***\n";
  19. mb_internal_encoding('utf-8');
  20. // Initialise function arguments not being substituted
  21. $str = base64_decode('5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CC');
  22. $transfer_encoding = 'B';
  23. $linefeed = "\r\n";
  24. $indent = 2;
  25. //get an unset variable
  26. $unset_var = 10;
  27. unset ($unset_var);
  28. // get a class
  29. class classA
  30. {
  31. public function __toString() {
  32. return "UTF-8";
  33. }
  34. }
  35. // heredoc string
  36. $heredoc = <<<EOT
  37. utf-8
  38. EOT;
  39. // get a resource variable
  40. $fp = fopen(__FILE__, "r");
  41. // unexpected values to be passed to $charset argument
  42. $inputs = array(
  43. // int data
  44. /*1*/ 0,
  45. 1,
  46. 12345,
  47. -2345,
  48. // float data
  49. /*5*/ 10.5,
  50. -10.5,
  51. 12.3456789000e10,
  52. 12.3456789000E-10,
  53. .5,
  54. // null data
  55. /*10*/ NULL,
  56. null,
  57. // boolean data
  58. /*12*/ true,
  59. false,
  60. TRUE,
  61. FALSE,
  62. // empty data
  63. /*16*/ "",
  64. '',
  65. // string data
  66. /*18*/ "utf-8",
  67. 'utf-8',
  68. $heredoc,
  69. // object data
  70. /*21*/ new classA(),
  71. // undefined data
  72. /*22*/ @$undefined_var,
  73. // unset data
  74. /*23*/ @$unset_var,
  75. // resource variable
  76. /*24*/ $fp
  77. );
  78. // loop through each element of $inputs to check the behavior of mb_encode_mimeheader()
  79. $iterator = 1;
  80. foreach($inputs as $input) {
  81. echo "\n-- Iteration $iterator --\n";
  82. var_dump( mb_encode_mimeheader($str, $input, $transfer_encoding, $linefeed, $indent));
  83. $iterator++;
  84. };
  85. fclose($fp);
  86. echo "Done";
  87. ?>
  88. --EXPECTF--
  89. *** Testing mb_encode_mimeheader() : usage variations ***
  90. -- Iteration 1 --
  91. Warning: mb_encode_mimeheader(): Unknown encoding "0" in %s on line %d
  92. bool(false)
  93. -- Iteration 2 --
  94. Warning: mb_encode_mimeheader(): Unknown encoding "1" in %s on line %d
  95. bool(false)
  96. -- Iteration 3 --
  97. Warning: mb_encode_mimeheader(): Unknown encoding "12345" in %s on line %d
  98. bool(false)
  99. -- Iteration 4 --
  100. Warning: mb_encode_mimeheader(): Unknown encoding "-2345" in %s on line %d
  101. bool(false)
  102. -- Iteration 5 --
  103. Warning: mb_encode_mimeheader(): Unknown encoding "10.5" in %s on line %d
  104. bool(false)
  105. -- Iteration 6 --
  106. Warning: mb_encode_mimeheader(): Unknown encoding "-10.5" in %s on line %d
  107. bool(false)
  108. -- Iteration 7 --
  109. Warning: mb_encode_mimeheader(): Unknown encoding "123456789000" in %s on line %d
  110. bool(false)
  111. -- Iteration 8 --
  112. Warning: mb_encode_mimeheader(): Unknown encoding "1.23456789E-9" in %s on line %d
  113. bool(false)
  114. -- Iteration 9 --
  115. Warning: mb_encode_mimeheader(): Unknown encoding "0.5" in %s on line %d
  116. bool(false)
  117. -- Iteration 10 --
  118. Warning: mb_encode_mimeheader(): Unknown encoding "" in %s on line %d
  119. bool(false)
  120. -- Iteration 11 --
  121. Warning: mb_encode_mimeheader(): Unknown encoding "" in %s on line %d
  122. bool(false)
  123. -- Iteration 12 --
  124. Warning: mb_encode_mimeheader(): Unknown encoding "1" in %s on line %d
  125. bool(false)
  126. -- Iteration 13 --
  127. Warning: mb_encode_mimeheader(): Unknown encoding "" in %s on line %d
  128. bool(false)
  129. -- Iteration 14 --
  130. Warning: mb_encode_mimeheader(): Unknown encoding "1" in %s on line %d
  131. bool(false)
  132. -- Iteration 15 --
  133. Warning: mb_encode_mimeheader(): Unknown encoding "" in %s on line %d
  134. bool(false)
  135. -- Iteration 16 --
  136. Warning: mb_encode_mimeheader(): Unknown encoding "" in %s on line %d
  137. bool(false)
  138. -- Iteration 17 --
  139. Warning: mb_encode_mimeheader(): Unknown encoding "" in %s on line %d
  140. bool(false)
  141. -- Iteration 18 --
  142. string(52) "=?UTF-8?B?5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CC?="
  143. -- Iteration 19 --
  144. string(52) "=?UTF-8?B?5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CC?="
  145. -- Iteration 20 --
  146. string(52) "=?UTF-8?B?5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CC?="
  147. -- Iteration 21 --
  148. string(52) "=?UTF-8?B?5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CC?="
  149. -- Iteration 22 --
  150. Warning: mb_encode_mimeheader(): Unknown encoding "" in %s on line %d
  151. bool(false)
  152. -- Iteration 23 --
  153. Warning: mb_encode_mimeheader(): Unknown encoding "" in %s on line %d
  154. bool(false)
  155. -- Iteration 24 --
  156. Warning: mb_encode_mimeheader() expects parameter 2 to be string, resource given in %s on line %d
  157. NULL
  158. Done