Skip to content

Commit d0eaa59

Browse files
author
Sanjay Mantoor
committed
New testcases for gmdate function
1 parent 29c885c commit d0eaa59

16 files changed

+1175
-0
lines changed

ext/date/tests/gmdate_basic.phpt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
--TEST--
2+
Test gmdate() function : basic functionality
3+
--FILE--
4+
<?php
5+
/* Prototype : string gmdate(string format [, long timestamp])
6+
* Description: Format a GMT date/time
7+
* Source code: ext/date/php_date.c
8+
* Alias to functions:
9+
*/
10+
11+
echo "*** Testing gmdate() : basic functionality ***\n";
12+
13+
// Initialise all required variables
14+
date_default_timezone_set('UTC');
15+
$format = DATE_ISO8601;
16+
$timestamp = mktime(8, 8, 8, 8, 8, 2008);
17+
18+
// Calling gmdate() with all possible arguments
19+
var_dump( gmdate($format, $timestamp) );
20+
21+
// Calling gmdate() with mandatory arguments
22+
var_dump( gmdate($format) );
23+
24+
?>
25+
===DONE===
26+
--EXPECTF--
27+
*** Testing gmdate() : basic functionality ***
28+
string(24) "2008-08-08T08:08:08+0000"
29+
string(%d) "%s"
30+
===DONE===

ext/date/tests/gmdate_error.phpt

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
--TEST--
2+
Test gmdate() function : error conditions
3+
--FILE--
4+
<?php
5+
/* Prototype : string gmdate(string format [, long timestamp])
6+
* Description: Format a GMT date/time
7+
* Source code: ext/date/php_date.c
8+
* Alias to functions:
9+
*/
10+
11+
echo "*** Testing gmdate() : error conditions ***\n";
12+
13+
// Initialise all required variables
14+
date_default_timezone_set('UTC');
15+
$format = DATE_ISO8601;
16+
$timestamp = mktime(8, 8, 8, 8, 8, 2008);
17+
18+
// Zero arguments
19+
echo "\n-- Testing gmdate() function with Zero arguments --\n";
20+
var_dump( gmdate() );
21+
22+
//Test gmdate with one more than the expected number of arguments
23+
echo "\n-- Testing gmdate() function with more than expected no. of arguments --\n";
24+
$extra_arg = 10;
25+
var_dump( gmdate($format, $timestamp, $extra_arg) );
26+
27+
?>
28+
===DONE===
29+
--EXPECTF--
30+
*** Testing gmdate() : error conditions ***
31+
32+
-- Testing gmdate() function with Zero arguments --
33+
34+
Warning: gmdate() expects at least 1 parameter, 0 given in %s on line %d
35+
bool(false)
36+
37+
-- Testing gmdate() function with more than expected no. of arguments --
38+
39+
Warning: gmdate() expects at most 2 parameters, 3 given in %s on line %d
40+
bool(false)
41+
===DONE===

ext/date/tests/gmdate_variation1.phpt

Lines changed: 221 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,221 @@
1+
--TEST--
2+
Test gmdate() function : usage variation - Passing unexpected values to format argument.
3+
--FILE--
4+
<?php
5+
/* Prototype : string gmdate(string format [, long timestamp])
6+
* Description: Format a GMT date/time
7+
* Source code: ext/date/php_date.c
8+
* Alias to functions:
9+
*/
10+
11+
echo "*** Testing gmdate() : usage variation ***\n";
12+
13+
// Initialise all required variables
14+
date_default_timezone_set('UTC');
15+
$timestamp = mktime(8, 8, 8, 8, 8, 2008);
16+
17+
//get an unset variable
18+
$unset_var = 10;
19+
unset ($unset_var);
20+
21+
// define some classes
22+
class classWithToString
23+
{
24+
public function __toString() {
25+
return "Class A object";
26+
}
27+
}
28+
29+
class classWithoutToString
30+
{
31+
}
32+
33+
// heredoc string
34+
$heredoc = <<<EOT
35+
hello world
36+
EOT;
37+
38+
// add arrays
39+
$index_array = array (1, 2, 3);
40+
$assoc_array = array ('one' => 1, 'two' => 2);
41+
42+
//array of values to iterate over
43+
$inputs = array(
44+
45+
// int data
46+
'int 0' => 0,
47+
'int 1' => 1,
48+
'int 12345' => 12345,
49+
'int -12345' => -12345,
50+
51+
// float data
52+
'float 10.5' => 10.5,
53+
'float -10.5' => -10.5,
54+
'float 12.3456789000e10' => 12.3456789000e10,
55+
'float -12.3456789000e10' => -12.3456789000e10,
56+
'float .5' => .5,
57+
58+
// array data
59+
'empty array' => array(),
60+
'int indexed array' => $index_array,
61+
'associative array' => $assoc_array,
62+
'nested arrays' => array('foo', $index_array, $assoc_array),
63+
64+
// null data
65+
'uppercase NULL' => NULL,
66+
'lowercase null' => null,
67+
68+
// boolean data
69+
'lowercase true' => true,
70+
'lowercase false' =>false,
71+
'uppercase TRUE' =>TRUE,
72+
'uppercase FALSE' =>FALSE,
73+
74+
// empty data
75+
'empty string DQ' => "",
76+
'empty string SQ' => '',
77+
78+
// object data
79+
'instance of classWithToString' => new classWithToString(),
80+
'instance of classWithoutToString' => new classWithoutToString(),
81+
82+
// undefined data
83+
'undefined var' => @$undefined_var,
84+
85+
// unset data
86+
'unset var' => @$unset_var,
87+
);
88+
89+
// loop through each element of the array for format
90+
91+
foreach($inputs as $key =>$value) {
92+
echo "\n--$key--\n";
93+
var_dump( gmdate($value, $timestamp) );
94+
var_dump( gmdate($value) );
95+
};
96+
97+
?>
98+
===DONE===
99+
--EXPECTF--
100+
*** Testing gmdate() : usage variation ***
101+
102+
--int 0--
103+
string(1) "0"
104+
string(1) "0"
105+
106+
--int 1--
107+
string(1) "1"
108+
string(1) "1"
109+
110+
--int 12345--
111+
string(5) "12345"
112+
string(5) "12345"
113+
114+
--int -12345--
115+
string(6) "-12345"
116+
string(6) "-12345"
117+
118+
--float 10.5--
119+
string(4) "10.5"
120+
string(4) "10.5"
121+
122+
--float -10.5--
123+
string(5) "-10.5"
124+
string(5) "-10.5"
125+
126+
--float 12.3456789000e10--
127+
string(12) "123456789000"
128+
string(12) "123456789000"
129+
130+
--float -12.3456789000e10--
131+
string(13) "-123456789000"
132+
string(13) "-123456789000"
133+
134+
--float .5--
135+
string(3) "0.5"
136+
string(3) "0.5"
137+
138+
--empty array--
139+
140+
Warning: gmdate() expects parameter 1 to be string, array given in %s on line %d
141+
bool(false)
142+
143+
Warning: gmdate() expects parameter 1 to be string, array given in %s on line %d
144+
bool(false)
145+
146+
--int indexed array--
147+
148+
Warning: gmdate() expects parameter 1 to be string, array given in %s on line %d
149+
bool(false)
150+
151+
Warning: gmdate() expects parameter 1 to be string, array given in %s on line %d
152+
bool(false)
153+
154+
--associative array--
155+
156+
Warning: gmdate() expects parameter 1 to be string, array given in %s on line %d
157+
bool(false)
158+
159+
Warning: gmdate() expects parameter 1 to be string, array given in %s on line %d
160+
bool(false)
161+
162+
--nested arrays--
163+
164+
Warning: gmdate() expects parameter 1 to be string, array given in %s on line %d
165+
bool(false)
166+
167+
Warning: gmdate() expects parameter 1 to be string, array given in %s on line %d
168+
bool(false)
169+
170+
--uppercase NULL--
171+
string(0) ""
172+
string(0) ""
173+
174+
--lowercase null--
175+
string(0) ""
176+
string(0) ""
177+
178+
--lowercase true--
179+
string(1) "1"
180+
string(1) "1"
181+
182+
--lowercase false--
183+
string(0) ""
184+
string(0) ""
185+
186+
--uppercase TRUE--
187+
string(1) "1"
188+
string(1) "1"
189+
190+
--uppercase FALSE--
191+
string(0) ""
192+
string(0) ""
193+
194+
--empty string DQ--
195+
string(0) ""
196+
string(0) ""
197+
198+
--empty string SQ--
199+
string(0) ""
200+
string(0) ""
201+
202+
--instance of classWithToString--
203+
string(53) "CFridayam0808 AM 2008b8UTC2008-08-08T08:08:08+00:0031"
204+
string(%d) "%s"
205+
206+
--instance of classWithoutToString--
207+
208+
Warning: gmdate() expects parameter 1 to be string, object given in %s on line %d
209+
bool(false)
210+
211+
Warning: gmdate() expects parameter 1 to be string, object given in %s on line %d
212+
bool(false)
213+
214+
--undefined var--
215+
string(0) ""
216+
string(0) ""
217+
218+
--unset var--
219+
string(0) ""
220+
string(0) ""
221+
===DONE===
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
--TEST--
2+
Test gmdate() function : usage variation - Passing Timezone format options to format argument.
3+
--FILE--
4+
<?php
5+
/* Prototype : string gmdate(string format [, long timestamp])
6+
* Description: Format a GMT date/time
7+
* Source code: ext/date/php_date.c
8+
* Alias to functions:
9+
*/
10+
11+
echo "*** Testing gmdate() : usage variation ***\n";
12+
13+
// Initialise all required variables
14+
date_default_timezone_set('Asia/Calcutta');
15+
$timestamp = mktime(8, 8, 8, 8, 8, 2008);
16+
17+
echo "\n-- Testing gmdate() function with Timezone identifier format --\n";
18+
var_dump( gmdate('e') );
19+
var_dump( gmdate('e', $timestamp) );
20+
21+
echo "\n-- Testing gmdate() function with checking whether date is in daylight saving time format --\n";
22+
var_dump( gmdate('I') );
23+
var_dump( gmdate('I', $timestamp) );
24+
25+
echo "\n-- Testing gmdate() function with difference to GMT in hours format --\n";
26+
var_dump( gmdate('O') );
27+
var_dump( gmdate('O', $timestamp) );
28+
29+
echo "\n-- Testing gmdate() function with Difference to GMT in hours using colon as separator format --\n";
30+
var_dump( gmdate('P') );
31+
var_dump( gmdate('P', $timestamp) );
32+
33+
echo "\n-- Testing gmdate() function with timezone abbreviation format --\n";
34+
var_dump( gmdate('T') );
35+
var_dump( gmdate('T', $timestamp) );
36+
37+
echo "\n-- Testing gmdate() function with timezone offset format --\n";
38+
var_dump( gmdate('T') );
39+
var_dump( gmdate('T', $timestamp) );
40+
41+
?>
42+
===DONE===
43+
--EXPECTF--
44+
*** Testing gmdate() : usage variation ***
45+
46+
-- Testing gmdate() function with Timezone identifier format --
47+
string(3) "UTC"
48+
string(3) "UTC"
49+
50+
-- Testing gmdate() function with checking whether date is in daylight saving time format --
51+
string(1) "%d"
52+
string(1) "%d"
53+
54+
-- Testing gmdate() function with difference to GMT in hours format --
55+
string(5) "+0000"
56+
string(5) "+0000"
57+
58+
-- Testing gmdate() function with Difference to GMT in hours using colon as separator format --
59+
string(6) "+00:00"
60+
string(6) "+00:00"
61+
62+
-- Testing gmdate() function with timezone abbreviation format --
63+
string(3) "GMT"
64+
string(3) "GMT"
65+
66+
-- Testing gmdate() function with timezone offset format --
67+
string(3) "GMT"
68+
string(3) "GMT"
69+
===DONE===

0 commit comments

Comments
 (0)