1--TEST--
2Test imap_close() function : usage variations - different ints as $options arg
3--SKIPIF--
4<?php
5require_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/*
15 * Pass different integers as $options arg to imap_close() to test which are
16 * recognised as CL_EXPUNGE option
17 */
18
19echo "*** Testing imap_close() : usage variations ***\n";
20
21require_once(dirname(__FILE__).'/imap_include.inc');
22
23$inputs = array (0, 3.2768e4, -32768, PHP_INT_MAX, -PHP_INT_MAX);
24
25$stream_id = setup_test_mailbox('', 3, $mailbox); // set up temp mailbox with 3 messages
26
27// loop through each element of $inputs to check the behavior of imap_close()
28$iterator = 1;
29foreach($inputs as $input) {
30
31	// mark added messages for deletion
32	for ($i = 1; $i < 4; $i++) {
33		imap_delete($stream_id, $i);
34	}
35	echo "\n-- Iteration $iterator --\n";
36	var_dump( $check = imap_close($stream_id, $input) );
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, $username, $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, $username, $password);
57	populate_mailbox($stream_id, $mailbox, 3);
58
59};
60?>
61===DONE===
62--CLEAN--
63<?php
64require_once(dirname(__FILE__).'/clean.inc');
65?>
66--EXPECTF--
67*** Testing imap_close() : usage variations ***
68Create a temporary mailbox and add 3 msgs
69.. mailbox '{%s}%s' 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 --
80
81Warning: imap_close(): invalid value for the flags parameter in %s on line %d
82bool(false)
83
84-- Iteration 4 --
85
86Warning: imap_close(): invalid value for the flags parameter in %s on line %d
87bool(false)
88
89-- Iteration 5 --
90
91Warning: imap_close(): invalid value for the flags parameter in %s on line %d
92bool(false)
93===DONE===
94