1--TEST--
2Test imap_fetchheader() function : usage variations - diff data types for $msg_no arg
3--SKIPIF--
4<?php
5require_once(dirname(__FILE__).'/skipif.inc');
6?>
7--FILE--
8<?php
9/* Prototype  : string imap_fetchheader(resource $stream_id, int $msg_no [, int $options])
10 * Description: Get the full unfiltered header for a message
11 * Source code: ext/imap/php_imap.c
12 */
13
14/*
15 * Pass different data types as $msg_no argument to test behaviour of imap_fetchheader()
16 */
17
18echo "*** Testing imap_fetchheader() : usage variations ***\n";
19require_once(dirname(__FILE__).'/imap_include.inc');
20
21// Initialise function arguments not being substituted
22$stream_id = setup_test_mailbox('', 1, $mailbox, 'notSimple'); // set up temp mailbox with 1 msg
23
24//get an unset variable
25$unset_var = 10;
26unset ($unset_var);
27
28// get a class
29class classA
30{
31  public function __toString() {
32    return "Class A object";
33  }
34}
35
36// heredoc string
37$heredoc = <<<EOT
38hello world
39EOT;
40
41$index_array = array (1, 2, 3);
42$assoc_array = array ('one' => 1, 'two' => 2);
43
44// get a resource variable
45$fp = fopen(__FILE__, "r");
46
47// unexpected values to be passed to $msg_no argument
48$inputs = array(
49
50       // int data
51/*1*/  0,
52       1,
53       12345,
54       -2345,
55
56       // float data
57/*5*/  10.5,
58       -10.5,
59       12.3456789000e10,
60       12.3456789000E-10,
61       .5,
62
63       // null data
64/*10*/ NULL,
65       null,
66
67       // boolean data
68/*12*/ true,
69       false,
70       TRUE,
71       FALSE,
72
73       // empty data
74/*16*/ "",
75       '',
76
77       // string data
78/*18*/ "string",
79       'string',
80       $heredoc,
81
82       // array data
83/*21*/ array(),
84       $index_array,
85       $assoc_array,
86       array('foo', $index_array, $assoc_array),
87
88
89       // object data
90/*25*/ new classA(),
91
92       // undefined data
93/*26*/ @$undefined_var,
94
95       // unset data
96/*27*/ @$unset_var,
97
98       // resource variable
99/*28*/ $fp
100);
101
102// loop through each element of $inputs to check the behavior of imap_fetchheader()
103$iterator = 1;
104foreach($inputs as $input) {
105  echo "\n-- Iteration $iterator --\n";
106  var_dump( imap_fetchheader($stream_id, $input) );
107  $iterator++;
108};
109
110fclose($fp);
111?>
112===DONE===
113--CLEAN--
114<?php
115require_once(dirname(__FILE__).'/clean.inc');
116?>
117===DONE===
118--EXPECTF--
119*** Testing imap_fetchheader() : usage variations ***
120Create a temporary mailbox and add 1 msgs
121.. mailbox '{%s}%s' created
122
123-- Iteration 1 --
124
125Warning: imap_fetchheader(): Bad message number in %s on line %d
126bool(false)
127
128-- Iteration 2 --
129%unicode|string%(%d) "From: foo@anywhere.com
130Subject: Test msg 1
131To: %s
132MIME-Version: 1.0
133Content-Type: MULTIPART/mixed; BOUNDARY="%s"
134
135"
136
137-- Iteration 3 --
138
139Warning: imap_fetchheader(): Bad message number in %s on line %d
140bool(false)
141
142-- Iteration 4 --
143
144Warning: imap_fetchheader(): Bad message number in %s on line %d
145bool(false)
146
147-- Iteration 5 --
148
149Warning: imap_fetchheader(): Bad message number in %s on line %d
150bool(false)
151
152-- Iteration 6 --
153
154Warning: imap_fetchheader(): Bad message number in %s on line %d
155bool(false)
156
157-- Iteration 7 --
158
159Warning: imap_fetchheader(): Bad message number in %s on line %d
160bool(false)
161
162-- Iteration 8 --
163
164Warning: imap_fetchheader(): Bad message number in %s on line %d
165bool(false)
166
167-- Iteration 9 --
168
169Warning: imap_fetchheader(): Bad message number in %s on line %d
170bool(false)
171
172-- Iteration 10 --
173
174Warning: imap_fetchheader(): Bad message number in %s on line %d
175bool(false)
176
177-- Iteration 11 --
178
179Warning: imap_fetchheader(): Bad message number in %s on line %d
180bool(false)
181
182-- Iteration 12 --
183%unicode|string%(%d) "From: foo@anywhere.com
184Subject: Test msg 1
185To: %s
186MIME-Version: 1.0
187Content-Type: MULTIPART/mixed; BOUNDARY="%s"
188
189"
190
191-- Iteration 13 --
192
193Warning: imap_fetchheader(): Bad message number in %s on line %d
194bool(false)
195
196-- Iteration 14 --
197%unicode|string%(%d) "From: foo@anywhere.com
198Subject: Test msg 1
199To: %s
200MIME-Version: 1.0
201Content-Type: MULTIPART/mixed; BOUNDARY="%s"
202
203"
204
205-- Iteration 15 --
206
207Warning: imap_fetchheader(): Bad message number in %s on line %d
208bool(false)
209
210-- Iteration 16 --
211
212Warning: imap_fetchheader() expects parameter 2 to be long, %unicode_string_optional% given in %s on line %d
213NULL
214
215-- Iteration 17 --
216
217Warning: imap_fetchheader() expects parameter 2 to be long, %unicode_string_optional% given in %s on line %d
218NULL
219
220-- Iteration 18 --
221
222Warning: imap_fetchheader() expects parameter 2 to be long, %unicode_string_optional% given in %s on line %d
223NULL
224
225-- Iteration 19 --
226
227Warning: imap_fetchheader() expects parameter 2 to be long, %unicode_string_optional% given in %s on line %d
228NULL
229
230-- Iteration 20 --
231
232Warning: imap_fetchheader() expects parameter 2 to be long, %unicode_string_optional% given in %s on line %d
233NULL
234
235-- Iteration 21 --
236
237Warning: imap_fetchheader() expects parameter 2 to be long, array given in %s on line %d
238NULL
239
240-- Iteration 22 --
241
242Warning: imap_fetchheader() expects parameter 2 to be long, array given in %s on line %d
243NULL
244
245-- Iteration 23 --
246
247Warning: imap_fetchheader() expects parameter 2 to be long, array given in %s on line %d
248NULL
249
250-- Iteration 24 --
251
252Warning: imap_fetchheader() expects parameter 2 to be long, array given in %s on line %d
253NULL
254
255-- Iteration 25 --
256
257Warning: imap_fetchheader() expects parameter 2 to be long, object given in %s on line %d
258NULL
259
260-- Iteration 26 --
261
262Warning: imap_fetchheader(): Bad message number in %s on line %d
263bool(false)
264
265-- Iteration 27 --
266
267Warning: imap_fetchheader(): Bad message number in %s on line %d
268bool(false)
269
270-- Iteration 28 --
271
272Warning: imap_fetchheader() expects parameter 2 to be long, resource given in %s on line %d
273NULL
274===DONE===
275