imap_close_variation2.phpt 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. --TEST--
  2. Test imap_close() function : usage variations - different data types as $options arg
  3. --SKIPIF--
  4. <?php
  5. require_once(dirname(__FILE__).'/skipif.inc');
  6. ?>
  7. --FILE--
  8. <?php
  9. /* Prototype : bool imap_close(resource $stream_id [, int $options])
  10. * Description: Close an IMAP stream
  11. * Source code: ext/imap/php_imap.c
  12. */
  13. /*
  14. * Pass different data types as $options argument to test behaviour of imap_close()
  15. */
  16. echo "*** Testing imap_close() : usage variations ***\n";
  17. // include file for imap_stream
  18. require_once(dirname(__FILE__).'/imap_include.inc');
  19. // create mailbox to test whether options has been set to CL_EXPUNGE
  20. $stream_id = setup_test_mailbox('', 3, $mailbox);
  21. //get an unset variable
  22. $unset_var = 10;
  23. unset ($unset_var);
  24. // heredoc string
  25. $heredoc = <<<EOT
  26. 32768
  27. EOT;
  28. // unexpected values to be passed to $options argument
  29. $inputs = array(
  30. // int data
  31. /*1*/ 0,
  32. 1,
  33. 32768,
  34. -2345,
  35. // float data
  36. /*5*/ 10.5,
  37. -10.5,
  38. 12.3456789000e10,
  39. 12.3456789000E-10,
  40. .5,
  41. // null data
  42. /*10*/ NULL,
  43. null,
  44. // boolean data
  45. /*12*/ true,
  46. false,
  47. TRUE,
  48. FALSE,
  49. // empty data
  50. /*16*/ "",
  51. '',
  52. array(),
  53. // string data
  54. /*19*/ "32768",
  55. '32768',
  56. $heredoc,
  57. // undefined data
  58. /*22*/ @$undefined_var,
  59. // unset data
  60. /*23*/ @$unset_var,
  61. );
  62. // loop through each element of $inputs to check the behavior of imap_close()
  63. $iterator = 1;
  64. foreach($inputs as $input) {
  65. // mark added messages for deletion
  66. for ($i = 1; $i < 4; $i++) {
  67. imap_delete($stream_id, $i);
  68. }
  69. echo "\n-- Iteration $iterator --\n";
  70. var_dump( $check = imap_close($stream_id, $input) );
  71. // check that imap_close was successful, if not call imap_close and explicitly set CL_EXPUNGE
  72. if(false === $check) {
  73. imap_close($stream_id, CL_EXPUNGE);
  74. } else {
  75. // if imap_close was successful test whether CL_EXPUNGE was set by doing a message count
  76. $imap_stream = imap_open($mailbox, $username, $password);
  77. $num_msg = imap_num_msg($imap_stream);
  78. if ($num_msg != 0) {
  79. echo "CL_EXPUNGE was not set, $num_msg msgs in mailbox\n";
  80. } else {
  81. echo "CL_EXPUNGE was set\n";
  82. }
  83. // call imap_close with CL_EXPUNGE explicitly set in case mailbox not empty
  84. imap_close($imap_stream, CL_EXPUNGE);
  85. }
  86. $iterator++;
  87. // get $stream_id for next iteration
  88. $stream_id = imap_open($mailbox, $username, $password);
  89. populate_mailbox($stream_id, $mailbox, 3);
  90. };
  91. ?>
  92. ===DONE===
  93. --CLEAN--
  94. <?php
  95. require_once(dirname(__FILE__).'/clean.inc');
  96. ?>
  97. --EXPECTF--
  98. *** Testing imap_close() : usage variations ***
  99. Create a temporary mailbox and add 3 msgs
  100. .. mailbox '{%s}%s' created
  101. -- Iteration 1 --
  102. bool(true)
  103. CL_EXPUNGE was not set, 3 msgs in mailbox
  104. -- Iteration 2 --
  105. Warning: imap_close(): invalid value for the flags parameter in %s on line %d
  106. bool(false)
  107. -- Iteration 3 --
  108. bool(true)
  109. CL_EXPUNGE was set
  110. -- Iteration 4 --
  111. Warning: imap_close(): invalid value for the flags parameter in %s on line %d
  112. bool(false)
  113. -- Iteration 5 --
  114. Warning: imap_close(): invalid value for the flags parameter in %s on line %d
  115. bool(false)
  116. -- Iteration 6 --
  117. Warning: imap_close(): invalid value for the flags parameter in %s on line %d
  118. bool(false)
  119. -- Iteration 7 --
  120. Warning: imap_close(): invalid value for the flags parameter in %s on line %d
  121. bool(false)
  122. -- Iteration 8 --
  123. bool(true)
  124. CL_EXPUNGE was not set, 3 msgs in mailbox
  125. -- Iteration 9 --
  126. bool(true)
  127. CL_EXPUNGE was not set, 3 msgs in mailbox
  128. -- Iteration 10 --
  129. bool(true)
  130. CL_EXPUNGE was not set, 3 msgs in mailbox
  131. -- Iteration 11 --
  132. bool(true)
  133. CL_EXPUNGE was not set, 3 msgs in mailbox
  134. -- Iteration 12 --
  135. Warning: imap_close(): invalid value for the flags parameter in %s on line %d
  136. bool(false)
  137. -- Iteration 13 --
  138. bool(true)
  139. CL_EXPUNGE was not set, 3 msgs in mailbox
  140. -- Iteration 14 --
  141. Warning: imap_close(): invalid value for the flags parameter in %s on line %d
  142. bool(false)
  143. -- Iteration 15 --
  144. bool(true)
  145. CL_EXPUNGE was not set, 3 msgs in mailbox
  146. -- Iteration 16 --
  147. Warning: imap_close() expects parameter 2 to be long, %unicode_string_optional% given in %s on line %d
  148. NULL
  149. CL_EXPUNGE was not set, 3 msgs in mailbox
  150. -- Iteration 17 --
  151. Warning: imap_close() expects parameter 2 to be long, %unicode_string_optional% given in %s on line %d
  152. NULL
  153. CL_EXPUNGE was not set, 3 msgs in mailbox
  154. -- Iteration 18 --
  155. Warning: imap_close() expects parameter 2 to be long, array given in %s on line %d
  156. NULL
  157. CL_EXPUNGE was not set, 3 msgs in mailbox
  158. -- Iteration 19 --
  159. bool(true)
  160. CL_EXPUNGE was set
  161. -- Iteration 20 --
  162. bool(true)
  163. CL_EXPUNGE was set
  164. -- Iteration 21 --
  165. bool(true)
  166. CL_EXPUNGE was set
  167. -- Iteration 22 --
  168. bool(true)
  169. CL_EXPUNGE was not set, 3 msgs in mailbox
  170. -- Iteration 23 --
  171. bool(true)
  172. CL_EXPUNGE was not set, 3 msgs in mailbox
  173. ===DONE===