mb_strtoupper_variation2.phpt 4.3 KB

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