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