imap_close_variation4.phpt 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. --TEST--
  2. Test imap_close() function : usage variations - different ints as $flags arg
  3. --EXTENSIONS--
  4. imap
  5. --SKIPIF--
  6. <?php
  7. require_once(__DIR__.'/setup/skipif.inc');
  8. ?>
  9. --FILE--
  10. <?php
  11. /*
  12. * Pass different integers as $flags arg to imap_close() to test which are
  13. * recognised as CL_EXPUNGE option
  14. */
  15. echo "*** Testing imap_close() : usage variations ***\n";
  16. require_once(__DIR__.'/setup/imap_include.inc');
  17. $inputs = array (0, 3.2768e4, -32768, PHP_INT_MAX, -PHP_INT_MAX);
  18. $stream_id = setup_test_mailbox('imapclosevar4', 3, $mailbox); // set up temp mailbox with 3 messages
  19. // loop through each element of $inputs to check the behavior of imap_close()
  20. $iterator = 1;
  21. foreach($inputs as $input) {
  22. // mark added messages for deletion
  23. for ($i = 1; $i < 4; $i++) {
  24. imap_delete($stream_id, $i);
  25. }
  26. echo "\n-- Iteration $iterator --\n";
  27. try {
  28. var_dump( $check = imap_close($stream_id, $input) );
  29. } catch (\ValueError $e) {
  30. echo $e->getMessage() . \PHP_EOL;
  31. $check = false;
  32. }
  33. // check that imap_close was successful, if not call imap_close and explicitly set CL_EXPUNGE
  34. if(false === $check) {
  35. imap_close($stream_id, CL_EXPUNGE);
  36. } else {
  37. // if imap_close was successful test whether CL_EXPUNGE was set by doing a message count
  38. $imap_stream = imap_open($mailbox, IMAP_MAILBOX_USERNAME, IMAP_MAILBOX_PASSWORD);
  39. $num_msg = imap_num_msg($imap_stream);
  40. if ($num_msg != 0) {
  41. echo "CL_EXPUNGE was not set, $num_msg msgs in mailbox\n";
  42. } else {
  43. echo "CL_EXPUNGE was set\n";
  44. }
  45. // call imap_close with CL_EXPUNGE explicitly set in case mailbox not empty
  46. imap_close($imap_stream, CL_EXPUNGE);
  47. }
  48. $iterator++;
  49. // get $stream_id for next iteration
  50. $stream_id = imap_open($mailbox, IMAP_MAILBOX_USERNAME, IMAP_MAILBOX_PASSWORD);
  51. populate_mailbox($stream_id, $mailbox, 3);
  52. };
  53. ?>
  54. --CLEAN--
  55. <?php
  56. $mailbox_suffix = 'imapclosevar4';
  57. require_once(__DIR__.'/setup/clean.inc');
  58. ?>
  59. --EXPECT--
  60. *** Testing imap_close() : usage variations ***
  61. Create a temporary mailbox and add 3 msgs
  62. New mailbox created
  63. -- Iteration 1 --
  64. bool(true)
  65. CL_EXPUNGE was not set, 3 msgs in mailbox
  66. -- Iteration 2 --
  67. bool(true)
  68. CL_EXPUNGE was set
  69. -- Iteration 3 --
  70. imap_close(): Argument #2 ($flags) must be CL_EXPUNGE or 0
  71. -- Iteration 4 --
  72. imap_close(): Argument #2 ($flags) must be CL_EXPUNGE or 0
  73. -- Iteration 5 --
  74. imap_close(): Argument #2 ($flags) must be CL_EXPUNGE or 0