1--TEST--
2Test imap_fetchbody() function : usage variation - diff data types as $section 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 $section 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$msg_no = 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 $section 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, $msg_no, $input) );
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.phpttest' created
107
108-- Iteration 1 --
109string(71) "From: %s
110To: %s
111Subject: test1
112
113"
114
115-- Iteration 2 --
116string(%d) "1: this is a test message, please ignore%a"
117
118-- Iteration 3 --
119string(0) ""
120
121-- Iteration 4 --
122string(0) ""
123
124-- Iteration 5 --
125string(0) ""
126
127-- Iteration 6 --
128string(0) ""
129
130-- Iteration 7 --
131string(0) ""
132
133-- Iteration 8 --
134string(0) ""
135
136-- Iteration 9 --
137string(0) ""
138
139-- Iteration 10 --
140string(%d) "From: %s
141To: %s
142Subject: test1
143
1441: this is a test message, please ignore%a"
145
146-- Iteration 11 --
147string(%d) "From: %s
148To: %s
149Subject: test1
150
1511: this is a test message, please ignore%a"
152
153-- Iteration 12 --
154string(%d) "1: this is a test message, please ignore%a"
155
156-- Iteration 13 --
157string(%d) "From: %s
158To: %s
159Subject: test1
160
1611: this is a test message, please ignore%a"
162
163-- Iteration 14 --
164string(%d) "1: this is a test message, please ignore%a"
165
166-- Iteration 15 --
167string(%d) "From: %s
168To: %s
169Subject: test1
170
1711: this is a test message, please ignore%a"
172
173-- Iteration 16 --
174string(%d) "From: %s
175To: %s
176Subject: test1
177
1781: this is a test message, please ignore%a"
179
180-- Iteration 17 --
181string(%d) "From: %s
182To: %s
183Subject: test1
184
1851: this is a test message, please ignore%a"
186
187-- Iteration 18 --
188
189Warning: imap_fetchbody() expects parameter 3 to be string, array given in %s on line 87
190NULL
191
192-- Iteration 19 --
193string(0) ""
194
195-- Iteration 20 --
196string(0) ""
197
198-- Iteration 21 --
199string(0) ""
200
201-- Iteration 22 --
202string(0) ""
203
204-- Iteration 23 --
205string(%d) "From: %s
206To: %s
207Subject: test1
208
2091: this is a test message, please ignore%a"
210
211-- Iteration 24 --
212string(%d) "From: %s
213To: %s
214Subject: test1
215
2161: this is a test message, please ignore%a"
217===DONE===
218