imap_fetchbody_variation3.phpt 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. --TEST--
  2. Test imap_fetchbody() function : usage variation - diff data types as $section arg
  3. --SKIPIF--
  4. <?php
  5. require_once(dirname(__FILE__).'/skipif.inc');
  6. ?>
  7. --FILE--
  8. <?php
  9. /* Prototype : string imap_fetchbody(resource $stream_id, int $msg_no, string $section
  10. * [, int $options])
  11. * Description: Get a specific body section
  12. * Source code: ext/imap/php_imap.c
  13. */
  14. /*
  15. * Pass different data types as $section argument to test behaviour of imap_fetchbody()
  16. */
  17. echo "*** Testing imap_fetchbody() : usage variations ***\n";
  18. require_once(dirname(__FILE__).'/imap_include.inc');
  19. // Initialise function arguments not being substituted
  20. $stream_id = setup_test_mailbox('', 1); // set up temp mailbox with 1 simple msg
  21. $msg_no = 1;
  22. //get an unset variable
  23. $unset_var = 10;
  24. unset ($unset_var);
  25. // get a class
  26. class classA
  27. {
  28. public function __toString() {
  29. return "Class A object";
  30. }
  31. }
  32. // heredoc string
  33. $heredoc = <<<EOT
  34. hello world
  35. EOT;
  36. // unexpected values to be passed to $section argument
  37. $inputs = array(
  38. // int data
  39. /*1*/ 0,
  40. 1,
  41. 12345,
  42. -2345,
  43. // float data
  44. /*5*/ 10.5,
  45. -10.5,
  46. 12.3456789000e10,
  47. 12.3456789000E-10,
  48. .5,
  49. // null data
  50. /*10*/ NULL,
  51. null,
  52. // boolean data
  53. /*12*/ true,
  54. false,
  55. TRUE,
  56. FALSE,
  57. // empty data
  58. /*16*/ "",
  59. '',
  60. array(),
  61. // string data
  62. /*19*/ "string",
  63. 'string',
  64. $heredoc,
  65. // object data
  66. /*22*/ new classA(),
  67. // undefined data
  68. /*23*/ @$undefined_var,
  69. // unset data
  70. /*24*/ @$unset_var,
  71. );
  72. // loop through each element of $inputs to check the behavior of imap_fetchbody()
  73. $iterator = 1;
  74. foreach($inputs as $input) {
  75. echo "\n-- Iteration $iterator --\n";
  76. var_dump( imap_fetchbody($stream_id, $msg_no, $input) );
  77. $iterator++;
  78. };
  79. ?>
  80. ===DONE===
  81. --CLEAN--
  82. <?php
  83. require_once(dirname(__FILE__).'/clean.inc');
  84. ?>
  85. --EXPECTF--
  86. *** Testing imap_fetchbody() : usage variations ***
  87. Create a temporary mailbox and add 1 msgs
  88. .. mailbox '%s.phpttest' created
  89. -- Iteration 1 --
  90. string(%d) "From: %s
  91. To: %s
  92. Subject: test1
  93. "
  94. -- Iteration 2 --
  95. string(%d) "1: this is a test message, please ignore%a"
  96. -- Iteration 3 --
  97. string(0) ""
  98. -- Iteration 4 --
  99. string(0) ""
  100. -- Iteration 5 --
  101. string(0) ""
  102. -- Iteration 6 --
  103. string(0) ""
  104. -- Iteration 7 --
  105. string(0) ""
  106. -- Iteration 8 --
  107. string(0) ""
  108. -- Iteration 9 --
  109. string(0) ""
  110. -- Iteration 10 --
  111. string(%d) "From: %s
  112. To: %s
  113. Subject: test1
  114. 1: this is a test message, please ignore%a"
  115. -- Iteration 11 --
  116. string(%d) "From: %s
  117. To: %s
  118. Subject: test1
  119. 1: this is a test message, please ignore%a"
  120. -- Iteration 12 --
  121. string(%d) "1: this is a test message, please ignore%a"
  122. -- Iteration 13 --
  123. string(%d) "From: %s
  124. To: %s
  125. Subject: test1
  126. 1: this is a test message, please ignore%a"
  127. -- Iteration 14 --
  128. string(%d) "1: this is a test message, please ignore%a"
  129. -- Iteration 15 --
  130. string(%d) "From: %s
  131. To: %s
  132. Subject: test1
  133. 1: this is a test message, please ignore%a"
  134. -- Iteration 16 --
  135. string(%d) "From: %s
  136. To: %s
  137. Subject: test1
  138. 1: this is a test message, please ignore%a"
  139. -- Iteration 17 --
  140. string(%d) "From: %s
  141. To: %s
  142. Subject: test1
  143. 1: this is a test message, please ignore%a"
  144. -- Iteration 18 --
  145. Warning: imap_fetchbody() expects parameter 3 to be string, array given in %s on line 87
  146. NULL
  147. -- Iteration 19 --
  148. string(0) ""
  149. -- Iteration 20 --
  150. string(0) ""
  151. -- Iteration 21 --
  152. string(0) ""
  153. -- Iteration 22 --
  154. string(0) ""
  155. -- Iteration 23 --
  156. string(%d) "From: %s
  157. To: %s
  158. Subject: test1
  159. 1: this is a test message, please ignore%a"
  160. -- Iteration 24 --
  161. string(%d) "From: %s
  162. To: %s
  163. Subject: test1
  164. 1: this is a test message, please ignore%a"
  165. ===DONE===