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