1--TEST--
2Test iconv_mime_decode() function : usage variations - Pass different data types to charset arg
3--SKIPIF--
4<?php
5extension_loaded('iconv') or die('skip');
6function_exists('iconv_mime_decode') or die("skip iconv_mime_decode() is not available in this build");
7?>
8--FILE--
9<?php
10/* Prototype  : string iconv_mime_decode(string encoded_string [, int mode, string charset])
11 * Description: Decodes a mime header field
12 * Source code: ext/iconv/iconv.c
13 */
14
15/*
16 * Pass different data types to $str argument to see how iconv_mime_decode() behaves
17 */
18
19echo "*** Testing iconv_mime_decode() : usage variations ***\n";
20
21// Initialise function arguments not being substituted
22// Some of the parameters actually passed to charset will request to use
23// a default charset determined by the platform. In order for this test to
24// run on both linux and windows, the subject will have to be ascii only.
25$header = 'Subject: =?UTF-8?B?QSBTYW1wbGUgVGVzdA==?=';
26$mode = ICONV_MIME_DECODE_CONTINUE_ON_ERROR;
27$charset = 'UTF-8';
28
29
30//get an unset variable
31$unset_var = 10;
32unset ($unset_var);
33
34// get a class
35class classA
36{
37  public function __toString() {
38    return "Class A object";
39  }
40}
41
42// heredoc string
43$heredoc = <<<EOT
44hello world
45EOT;
46
47// get a resource variable
48$fp = fopen(__FILE__, "r");
49
50// unexpected values to be passed to $str argument
51$inputs = array(
52
53       // int data
54/*1*/  0,
55       1,
56       12345,
57       -2345,
58
59       // float data
60/*5*/  10.5,
61       -10.5,
62       12.3456789000e10,
63       12.3456789000E-10,
64       .5,
65
66       // null data
67/*10*/ NULL,
68       null,
69
70       // boolean data
71/*12*/ true,
72       false,
73       TRUE,
74       FALSE,
75
76       // empty data
77/*16*/ "",
78       '',
79
80       // string data
81/*18*/ "string",
82       'string',
83       $heredoc,
84
85       // object data
86/*21*/ new classA(),
87
88       // undefined data
89/*22*/ @$undefined_var,
90
91       // unset data
92/*23*/ @$unset_var,
93
94       // resource variable
95/*24*/ $fp
96);
97
98// loop through each element of $inputs to check the behavior of iconv_mime_decode()
99$iterator = 1;
100foreach($inputs as $input) {
101  echo "\n-- Iteration $iterator --\n";
102  $res = iconv_mime_decode($header, $mode, $input);
103  if ($res !== false) {
104  	 var_dump(bin2hex($res));
105  }
106  else {
107     var_dump($res);
108  }
109  $iterator++;
110};
111
112fclose($fp);
113
114echo "Done";
115?>
116--EXPECTF--
117*** Testing iconv_mime_decode() : usage variations ***
118
119-- Iteration 1 --
120
121Notice: iconv_mime_decode(): Wrong charset, conversion from `???' to `0' is not allowed in %s on line %d
122bool(false)
123
124-- Iteration 2 --
125
126Notice: iconv_mime_decode(): Wrong charset, conversion from `???' to `1' is not allowed in %s on line %d
127bool(false)
128
129-- Iteration 3 --
130
131Notice: iconv_mime_decode(): Wrong charset, conversion from `???' to `12345' is not allowed in %s on line %d
132bool(false)
133
134-- Iteration 4 --
135
136Notice: iconv_mime_decode(): Wrong charset, conversion from `???' to `-2345' is not allowed in %s on line %d
137bool(false)
138
139-- Iteration 5 --
140
141Notice: iconv_mime_decode(): Wrong charset, conversion from `???' to `10.5' is not allowed in %s on line %d
142bool(false)
143
144-- Iteration 6 --
145
146Notice: iconv_mime_decode(): Wrong charset, conversion from `???' to `-10.5' is not allowed in %s on line %d
147bool(false)
148
149-- Iteration 7 --
150
151Notice: iconv_mime_decode(): Wrong charset, conversion from `???' to `123456789000' is not allowed in %s on line %d
152bool(false)
153
154-- Iteration 8 --
155
156Notice: iconv_mime_decode(): Wrong charset, conversion from `???' to `1.23456789E-9' is not allowed in %s on line %d
157bool(false)
158
159-- Iteration 9 --
160
161Notice: iconv_mime_decode(): Wrong charset, conversion from `???' to `0.5' is not allowed in %s on line %d
162bool(false)
163
164-- Iteration 10 --
165string(44) "5375626a6563743a20412053616d706c652054657374"
166
167-- Iteration 11 --
168string(44) "5375626a6563743a20412053616d706c652054657374"
169
170-- Iteration 12 --
171
172Notice: iconv_mime_decode(): Wrong charset, conversion from `???' to `1' is not allowed in %s on line %d
173bool(false)
174
175-- Iteration 13 --
176string(44) "5375626a6563743a20412053616d706c652054657374"
177
178-- Iteration 14 --
179
180Notice: iconv_mime_decode(): Wrong charset, conversion from `???' to `1' is not allowed in %s on line %d
181bool(false)
182
183-- Iteration 15 --
184string(44) "5375626a6563743a20412053616d706c652054657374"
185
186-- Iteration 16 --
187string(44) "5375626a6563743a20412053616d706c652054657374"
188
189-- Iteration 17 --
190string(44) "5375626a6563743a20412053616d706c652054657374"
191
192-- Iteration 18 --
193
194Notice: iconv_mime_decode(): Wrong charset, conversion from `???' to `string' is not allowed in %s on line %d
195bool(false)
196
197-- Iteration 19 --
198
199Notice: iconv_mime_decode(): Wrong charset, conversion from `???' to `string' is not allowed in %s on line %d
200bool(false)
201
202-- Iteration 20 --
203
204Notice: iconv_mime_decode(): Wrong charset, conversion from `???' to `hello world' is not allowed in %s on line %d
205bool(false)
206
207-- Iteration 21 --
208
209Notice: iconv_mime_decode(): Wrong charset, conversion from `???' to `Class A object' is not allowed in %s on line %d
210bool(false)
211
212-- Iteration 22 --
213string(44) "5375626a6563743a20412053616d706c652054657374"
214
215-- Iteration 23 --
216string(44) "5375626a6563743a20412053616d706c652054657374"
217
218-- Iteration 24 --
219
220Warning: iconv_mime_decode() expects parameter 3 to be string, resource given in %s on line %d
221bool(false)
222Done
223