imap_close_variation4.phpt 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. --TEST--
  2. Test imap_close() function : usage variations - different ints 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 integers as $options arg to imap_close() to test which are
  15. * recognised as CL_EXPUNGE option
  16. */
  17. echo "*** Testing imap_close() : usage variations ***\n";
  18. require_once(dirname(__FILE__).'/imap_include.inc');
  19. $inputs = array (0, 3.2768e4, -32768, PHP_INT_MAX, -PHP_INT_MAX);
  20. $stream_id = setup_test_mailbox('', 3, $mailbox); // set up temp mailbox with 3 messages
  21. // loop through each element of $inputs to check the behavior of imap_close()
  22. $iterator = 1;
  23. foreach($inputs as $input) {
  24. // mark added messages for deletion
  25. for ($i = 1; $i < 4; $i++) {
  26. imap_delete($stream_id, $i);
  27. }
  28. echo "\n-- Iteration $iterator --\n";
  29. var_dump( $check = imap_close($stream_id, $input) );
  30. // check that imap_close was successful, if not call imap_close and explicitly set CL_EXPUNGE
  31. if(false === $check) {
  32. imap_close($stream_id, CL_EXPUNGE);
  33. } else {
  34. // if imap_close was successful test whether CL_EXPUNGE was set by doing a message count
  35. $imap_stream = imap_open($mailbox, $username, $password);
  36. $num_msg = imap_num_msg($imap_stream);
  37. if ($num_msg != 0) {
  38. echo "CL_EXPUNGE was not set, $num_msg msgs in mailbox\n";
  39. } else {
  40. echo "CL_EXPUNGE was set\n";
  41. }
  42. // call imap_close with CL_EXPUNGE explicitly set in case mailbox not empty
  43. imap_close($imap_stream, CL_EXPUNGE);
  44. }
  45. $iterator++;
  46. // get $stream_id for next iteration
  47. $stream_id = imap_open($mailbox, $username, $password);
  48. populate_mailbox($stream_id, $mailbox, 3);
  49. };
  50. ?>
  51. ===DONE===
  52. --CLEAN--
  53. <?php
  54. require_once(dirname(__FILE__).'/clean.inc');
  55. ?>
  56. --EXPECTF--
  57. *** Testing imap_close() : usage variations ***
  58. Create a temporary mailbox and add 3 msgs
  59. .. mailbox '{%s}%s' created
  60. -- Iteration 1 --
  61. bool(true)
  62. CL_EXPUNGE was not set, 3 msgs in mailbox
  63. -- Iteration 2 --
  64. bool(true)
  65. CL_EXPUNGE was set
  66. -- Iteration 3 --
  67. Warning: imap_close(): invalid value for the flags parameter in %s on line %d
  68. bool(false)
  69. -- Iteration 4 --
  70. Warning: imap_close(): invalid value for the flags parameter in %s on line %d
  71. bool(false)
  72. -- Iteration 5 --
  73. Warning: imap_close(): invalid value for the flags parameter in %s on line %d
  74. bool(false)
  75. ===DONE===