1--TEST--
2Test imap_fetchbody() function : usage variation - diff data types as $msg_no arg
3--SKIPIF--
4<?php
5require_once(dirname(__FILE__).'/skipif.inc');
6?>
7--FILE--
8<?php
9/* Prototype  : string imap_fetchbody(resource $stream_id, int $msg_no, string $section
10 *           [, int $options])
11 * Description: Get a specific body section
12 * Source code: ext/imap/php_imap.c
13 */
14
15/*
16 * Pass different data types as $msg_no argument to test behaviour of imap_fetchbody()
17 */
18
19echo "*** Testing imap_fetchbody() : usage variations ***\n";
20
21require_once(dirname(__FILE__).'/imap_include.inc');
22
23// Initialise function arguments not being substituted
24$stream_id = setup_test_mailbox('', 1); // set up temp mailbox with 1 simple msg
25$section = '1';
26
27//get an unset variable
28$unset_var = 10;
29unset ($unset_var);
30
31// get a class
32class classA
33{
34  public function __toString() {
35    return "Class A object";
36  }
37}
38
39// heredoc string
40$heredoc = <<<EOT
41hello world
42EOT;
43
44// unexpected values to be passed to $msg_no argument
45$inputs = array(
46
47       // int data
48/*1*/  0,
49       1,
50       12345,
51       -2345,
52
53       // float data
54/*5*/  10.5,
55       -10.5,
56       12.3456789000e10,
57       12.3456789000E-10,
58       .5,
59
60       // null data
61/*10*/ NULL,
62       null,
63
64       // boolean data
65/*12*/ true,
66       false,
67       TRUE,
68       FALSE,
69
70       // empty data
71/*16*/ "",
72       '',
73       array(),
74
75       // string data
76/*19*/ "string",
77       'string',
78       $heredoc,
79
80       // object data
81/*22*/ new classA(),
82
83       // undefined data
84/*23*/ @$undefined_var,
85
86       // unset data
87/*24*/ @$unset_var,
88);
89
90// loop through each element of $inputs to check the behavior of imap_fetchbody()
91$iterator = 1;
92foreach($inputs as $input) {
93  echo "\n-- Iteration $iterator --\n";
94  var_dump( imap_fetchbody($stream_id, $input, $section) );
95  $iterator++;
96};
97?>
98===DONE===
99--CLEAN--
100<?php
101require_once(dirname(__FILE__).'/clean.inc');
102?>
103--EXPECTF--
104*** Testing imap_fetchbody() : usage variations ***
105Create a temporary mailbox and add 1 msgs
106.. mailbox '{%s}%s' created
107
108-- Iteration 1 --
109
110Warning: imap_fetchbody(): Bad message number in %s on line %d
111bool(false)
112
113-- Iteration 2 --
114string(%d) "1: this is a test message, please ignore%a"
115
116-- Iteration 3 --
117
118Warning: imap_fetchbody(): Bad message number in %s on line %d
119bool(false)
120
121-- Iteration 4 --
122
123Warning: imap_fetchbody(): Bad message number in %s on line %d
124bool(false)
125
126-- Iteration 5 --
127
128Warning: imap_fetchbody(): Bad message number in %s on line %d
129bool(false)
130
131-- Iteration 6 --
132
133Warning: imap_fetchbody(): Bad message number in %s on line %d
134bool(false)
135
136-- Iteration 7 --
137
138Warning: imap_fetchbody(): Bad message number in %s on line %d
139bool(false)
140
141-- Iteration 8 --
142
143Warning: imap_fetchbody(): Bad message number in %s on line %d
144bool(false)
145
146-- Iteration 9 --
147
148Warning: imap_fetchbody(): Bad message number in %s on line %d
149bool(false)
150
151-- Iteration 10 --
152
153Warning: imap_fetchbody(): Bad message number in %s on line %d
154bool(false)
155
156-- Iteration 11 --
157
158Warning: imap_fetchbody(): Bad message number in %s on line %d
159bool(false)
160
161-- Iteration 12 --
162string(%d) "1: this is a test message, please ignore%a"
163
164-- Iteration 13 --
165
166Warning: imap_fetchbody(): Bad message number in %s on line %d
167bool(false)
168
169-- Iteration 14 --
170string(%d) "1: this is a test message, please ignore%a"
171
172-- Iteration 15 --
173
174Warning: imap_fetchbody(): Bad message number in %s on line %d
175bool(false)
176
177-- Iteration 16 --
178
179Warning: imap_fetchbody() expects parameter 2 to be integer, string given in %s on line %d
180NULL
181
182-- Iteration 17 --
183
184Warning: imap_fetchbody() expects parameter 2 to be integer, string given in %s on line %d
185NULL
186
187-- Iteration 18 --
188
189Warning: imap_fetchbody() expects parameter 2 to be integer, array given in %s on line %d
190NULL
191
192-- Iteration 19 --
193
194Warning: imap_fetchbody() expects parameter 2 to be integer, string given in %s on line %d
195NULL
196
197-- Iteration 20 --
198
199Warning: imap_fetchbody() expects parameter 2 to be integer, string given in %s on line %d
200NULL
201
202-- Iteration 21 --
203
204Warning: imap_fetchbody() expects parameter 2 to be integer, string given in %s on line %d
205NULL
206
207-- Iteration 22 --
208
209Warning: imap_fetchbody() expects parameter 2 to be integer, object given in %s on line %d
210NULL
211
212-- Iteration 23 --
213
214Warning: imap_fetchbody(): Bad message number in %s on line %d
215bool(false)
216
217-- Iteration 24 --
218
219Warning: imap_fetchbody(): Bad message number in %s on line %d
220bool(false)
221===DONE===
222