1--TEST--
2Test date_parse() function : usage variation - Passing unexpected values to first argument $date.
3--FILE--
4<?php
5/* Prototype  : array date_parse  ( string $date  )
6 * Description: Returns associative array with detailed info about given date.
7 * Source code: ext/date/php_date.c
8 */
9
10echo "*** Testing date_parse() : usage variation -  unexpected values to first argument \$date***\n";
11
12//Set the default time zone
13date_default_timezone_set("Europe/London");
14
15//get an unset variable
16$unset_var = 10;
17unset ($unset_var);
18
19// define some classes
20class classWithToString
21{
22	public function __toString() {
23		return "Class A object";
24	}
25}
26
27class classWithoutToString
28{
29}
30
31// heredoc string
32$heredoc = <<<EOT
33hello world
34EOT;
35
36// add arrays
37$index_array = array (1, 2, 3);
38$assoc_array = array ('one' => 1, 'two' => 2);
39
40// resource
41$file_handle = fopen(__FILE__, 'r');
42
43//array of values to iterate over
44$inputs = array(
45
46      // int data
47      'int 0' => 0,
48      'int 1' => 1,
49      'int 12345' => 12345,
50      'int -12345' => -12345,
51
52      // float data
53      'float 10.5' => 10.5,
54      'float -10.5' => -10.5,
55      'float .5' => .5,
56
57      // array data
58      'empty array' => array(),
59      'int indexed array' => $index_array,
60      'associative array' => $assoc_array,
61      'nested arrays' => array('foo', $index_array, $assoc_array),
62
63      // null data
64      'uppercase NULL' => NULL,
65      'lowercase null' => null,
66
67      // boolean data
68      'lowercase true' => true,
69      'lowercase false' =>false,
70      'uppercase TRUE' =>TRUE,
71      'uppercase FALSE' =>FALSE,
72
73      // empty data
74      'empty string DQ' => "",
75      'empty string SQ' => '',
76
77      // string data
78      'string DQ' => "string",
79      'string SQ' => 'string',
80      'mixed case string' => "sTrInG",
81      'heredoc' => $heredoc,
82
83      // object data
84      'instance of classWithToString' => new classWithToString(),
85      'instance of classWithoutToString' => new classWithoutToString(),
86
87      // undefined data
88      'undefined var' => @$undefined_var,
89
90      // unset data
91      'unset var' => @$unset_var,
92
93      // resource
94      'resource' => $file_handle
95);
96
97foreach($inputs as $variation =>$date) {
98      echo "\n-- $variation --\n";
99      $result = date_parse($date);
100      if (is_array($result)) {
101      	  var_dump($result["errors"]);
102      } else {
103      	  var_dump($result);
104      }
105};
106
107// closing the resource
108fclose( $file_handle );
109
110?>
111===DONE===
112--EXPECTF--
113*** Testing date_parse() : usage variation -  unexpected values to first argument $date***
114
115-- int 0 --
116array(1) {
117  [0]=>
118  string(20) "Unexpected character"
119}
120
121-- int 1 --
122array(1) {
123  [0]=>
124  string(20) "Unexpected character"
125}
126
127-- int 12345 --
128array(1) {
129  [4]=>
130  string(20) "Unexpected character"
131}
132
133-- int -12345 --
134array(1) {
135  [5]=>
136  string(20) "Unexpected character"
137}
138
139-- float 10.5 --
140array(0) {
141}
142
143-- float -10.5 --
144array(1) {
145  [4]=>
146  string(20) "Unexpected character"
147}
148
149-- float .5 --
150array(0) {
151}
152
153-- empty array --
154
155Warning: date_parse() expects parameter 1 to be string, array given in %s on line %d
156bool(false)
157
158-- int indexed array --
159
160Warning: date_parse() expects parameter 1 to be string, array given in %s on line %d
161bool(false)
162
163-- associative array --
164
165Warning: date_parse() expects parameter 1 to be string, array given in %s on line %d
166bool(false)
167
168-- nested arrays --
169
170Warning: date_parse() expects parameter 1 to be string, array given in %s on line %d
171bool(false)
172
173-- uppercase NULL --
174array(1) {
175  [0]=>
176  string(12) "Empty string"
177}
178
179-- lowercase null --
180array(1) {
181  [0]=>
182  string(12) "Empty string"
183}
184
185-- lowercase true --
186array(1) {
187  [0]=>
188  string(20) "Unexpected character"
189}
190
191-- lowercase false --
192array(1) {
193  [0]=>
194  string(12) "Empty string"
195}
196
197-- uppercase TRUE --
198array(1) {
199  [0]=>
200  string(20) "Unexpected character"
201}
202
203-- uppercase FALSE --
204array(1) {
205  [0]=>
206  string(12) "Empty string"
207}
208
209-- empty string DQ --
210array(1) {
211  [0]=>
212  string(12) "Empty string"
213}
214
215-- empty string SQ --
216array(1) {
217  [0]=>
218  string(12) "Empty string"
219}
220
221-- string DQ --
222array(1) {
223  [0]=>
224  string(47) "The timezone could not be found in the database"
225}
226
227-- string SQ --
228array(1) {
229  [0]=>
230  string(47) "The timezone could not be found in the database"
231}
232
233-- mixed case string --
234array(1) {
235  [0]=>
236  string(47) "The timezone could not be found in the database"
237}
238
239-- heredoc --
240array(1) {
241  [0]=>
242  string(47) "The timezone could not be found in the database"
243}
244
245-- instance of classWithToString --
246array(2) {
247  [0]=>
248  string(47) "The timezone could not be found in the database"
249  [8]=>
250  string(29) "Double timezone specification"
251}
252
253-- instance of classWithoutToString --
254
255Warning: date_parse() expects parameter 1 to be string, object given in %s on line %d
256bool(false)
257
258-- undefined var --
259array(1) {
260  [0]=>
261  string(12) "Empty string"
262}
263
264-- unset var --
265array(1) {
266  [0]=>
267  string(12) "Empty string"
268}
269
270-- resource --
271
272Warning: date_parse() expects parameter 1 to be string, resource given in %s on line %d
273bool(false)
274===DONE===
275