]> granicus.if.org Git - php/commitdiff
New testcases for idate function
authorSanjay Mantoor <smantoor@php.net>
Tue, 23 Dec 2008 09:13:28 +0000 (09:13 +0000)
committerSanjay Mantoor <smantoor@php.net>
Tue, 23 Dec 2008 09:13:28 +0000 (09:13 +0000)
ext/date/tests/idate_basic.phpt [new file with mode: 0644]
ext/date/tests/idate_variation1.phpt [new file with mode: 0644]
ext/date/tests/idate_variation2.phpt [new file with mode: 0644]
ext/date/tests/idate_variation3.phpt [new file with mode: 0644]
ext/date/tests/idate_variation4.phpt [new file with mode: 0644]
ext/date/tests/idate_variation5.phpt [new file with mode: 0644]
ext/date/tests/idate_variation6.phpt [new file with mode: 0644]

diff --git a/ext/date/tests/idate_basic.phpt b/ext/date/tests/idate_basic.phpt
new file mode 100644 (file)
index 0000000..944f29f
--- /dev/null
@@ -0,0 +1,24 @@
+--TEST--
+Test idate() function : basic functionality 
+--FILE--
+<?php
+/* Prototype  : int idate(string format [, int timestamp])
+ * Description: Format a local time/date as integer 
+ * Source code: ext/date/php_date.c
+ * Alias to functions: 
+ */
+
+echo "*** Testing idate() : basic functionality ***\n";
+
+// Initialise all required variables
+$format = 'Y';
+
+// Calling idate() with mandatory arguments
+date_default_timezone_set("Asia/Calcutta");
+var_dump( idate($format) );
+?>
+===DONE===
+--EXPECTF--
+*** Testing idate() : basic functionality ***
+int(%d)
+===DONE===
diff --git a/ext/date/tests/idate_variation1.phpt b/ext/date/tests/idate_variation1.phpt
new file mode 100644 (file)
index 0000000..c0231a6
--- /dev/null
@@ -0,0 +1,301 @@
+--TEST--
+Test idate() function : usage variation - Passing unexpected values to first argument 'format'. 
+--FILE--
+<?php
+/* Prototype  : int idate(string format [, int timestamp])
+ * Description: Format a local time/date as integer 
+ * Source code: ext/date/php_date.c
+ * Alias to functions: 
+ */
+
+echo "*** Testing idate() : usage variation ***\n";
+
+// Initialise function arguments not being substituted (if any)
+date_default_timezone_set("Asia/Calcutta");
+$timestamp = mktime(8, 8, 8, 8, 8, 2008);
+
+//get an unset variable
+$unset_var = 10;
+unset ($unset_var);
+
+// define some classes
+class classWithToString
+{
+       public function __toString() {
+               return "Class A object";
+       }
+}
+
+class classWithoutToString
+{
+}
+
+// heredoc string
+$heredoc = <<<EOT
+hello world
+EOT;
+
+// add arrays
+$index_array = array (1, 2, 3);
+$assoc_array = array ('one' => 1, 'two' => 2);
+
+//array of values to iterate over
+$inputs = array(
+
+      // int data
+      'int 0' => 0,
+      'int 1' => 1,
+      'int 12345' => 12345,
+      'int -12345' => -12345,
+
+      // float data
+      'float 10.5' => 10.5,
+      'float -10.5' => -10.5,
+      'float 12.3456789000e10' => 12.3456789000e10,
+      'float -12.3456789000e10' => -12.3456789000e10,
+      'float .5' => .5,
+
+      // array data
+      'empty array' => array(),
+      'int indexed array' => $index_array,
+      'associative array' => $assoc_array,
+      'nested arrays' => array('foo', $index_array, $assoc_array),
+
+      // null data
+      'uppercase NULL' => NULL,
+      'lowercase null' => null,
+
+      // boolean data
+      'lowercase true' => true,
+      'lowercase false' =>false,
+      'uppercase TRUE' =>TRUE,
+      'uppercase FALSE' =>FALSE,
+
+      // empty data
+      'empty string DQ' => "",
+      'empty string SQ' => '',
+
+      // object data
+      'instance of classWithToString' => new classWithToString(),
+      'instance of classWithoutToString' => new classWithoutToString(),
+
+      // undefined data
+      'undefined var' => @$undefined_var,
+
+      // unset data
+      'unset var' => @$unset_var,
+);
+
+// loop through each element of the array for format
+
+foreach($inputs as $key =>$value) {
+      echo "\n--$key--\n";
+      var_dump( idate($value) );
+      var_dump( idate($value, $timestamp) );
+};
+
+?>
+===DONE===
+--EXPECTF--
+*** Testing idate() : usage variation ***
+
+--int 0--
+
+Warning: idate(): Unrecognized date format token. in %s on line %d
+bool(false)
+
+Warning: idate(): Unrecognized date format token. in %s on line %d
+bool(false)
+
+--int 1--
+
+Warning: idate(): Unrecognized date format token. in %s on line %d
+bool(false)
+
+Warning: idate(): Unrecognized date format token. in %s on line %d
+bool(false)
+
+--int 12345--
+
+Warning: idate(): idate format is one char in %s on line %d
+bool(false)
+
+Warning: idate(): idate format is one char in %s on line %d
+bool(false)
+
+--int -12345--
+
+Warning: idate(): idate format is one char in %s on line %d
+bool(false)
+
+Warning: idate(): idate format is one char in %s on line %d
+bool(false)
+
+--float 10.5--
+
+Warning: idate(): idate format is one char in %s on line %d
+bool(false)
+
+Warning: idate(): idate format is one char in %s on line %d
+bool(false)
+
+--float -10.5--
+
+Warning: idate(): idate format is one char in %s on line %d
+bool(false)
+
+Warning: idate(): idate format is one char in %s on line %d
+bool(false)
+
+--float 12.3456789000e10--
+
+Warning: idate(): idate format is one char in %s on line %d
+bool(false)
+
+Warning: idate(): idate format is one char in %s on line %d
+bool(false)
+
+--float -12.3456789000e10--
+
+Warning: idate(): idate format is one char in %s on line %d
+bool(false)
+
+Warning: idate(): idate format is one char in %s on line %d
+bool(false)
+
+--float .5--
+
+Warning: idate(): idate format is one char in %s on line %d
+bool(false)
+
+Warning: idate(): idate format is one char in %s on line %d
+bool(false)
+
+--empty array--
+
+Warning: idate() expects parameter 1 to be string, array given in %s on line %d
+bool(false)
+
+Warning: idate() expects parameter 1 to be string, array given in %s on line %d
+bool(false)
+
+--int indexed array--
+
+Warning: idate() expects parameter 1 to be string, array given in %s on line %d
+bool(false)
+
+Warning: idate() expects parameter 1 to be string, array given in %s on line %d
+bool(false)
+
+--associative array--
+
+Warning: idate() expects parameter 1 to be string, array given in %s on line %d
+bool(false)
+
+Warning: idate() expects parameter 1 to be string, array given in %s on line %d
+bool(false)
+
+--nested arrays--
+
+Warning: idate() expects parameter 1 to be string, array given in %s on line %d
+bool(false)
+
+Warning: idate() expects parameter 1 to be string, array given in %s on line %d
+bool(false)
+
+--uppercase NULL--
+
+Warning: idate(): idate format is one char in %s on line %d
+bool(false)
+
+Warning: idate(): idate format is one char in %s on line %d
+bool(false)
+
+--lowercase null--
+
+Warning: idate(): idate format is one char in %s on line %d
+bool(false)
+
+Warning: idate(): idate format is one char in %s on line %d
+bool(false)
+
+--lowercase true--
+
+Warning: idate(): Unrecognized date format token. in %s on line %d
+bool(false)
+
+Warning: idate(): Unrecognized date format token. in %s on line %d
+bool(false)
+
+--lowercase false--
+
+Warning: idate(): idate format is one char in %s on line %d
+bool(false)
+
+Warning: idate(): idate format is one char in %s on line %d
+bool(false)
+
+--uppercase TRUE--
+
+Warning: idate(): Unrecognized date format token. in %s on line %d
+bool(false)
+
+Warning: idate(): Unrecognized date format token. in %s on line %d
+bool(false)
+
+--uppercase FALSE--
+
+Warning: idate(): idate format is one char in %s on line %d
+bool(false)
+
+Warning: idate(): idate format is one char in %s on line %d
+bool(false)
+
+--empty string DQ--
+
+Warning: idate(): idate format is one char in %s on line %d
+bool(false)
+
+Warning: idate(): idate format is one char in %s on line %d
+bool(false)
+
+--empty string SQ--
+
+Warning: idate(): idate format is one char in %s on line %d
+bool(false)
+
+Warning: idate(): idate format is one char in %s on line %d
+bool(false)
+
+--instance of classWithToString--
+
+Warning: idate(): idate format is one char in %s on line %d
+bool(false)
+
+Warning: idate(): idate format is one char in %s on line %d
+bool(false)
+
+--instance of classWithoutToString--
+
+Warning: idate() expects parameter 1 to be string, object given in %s on line %d
+bool(false)
+
+Warning: idate() expects parameter 1 to be string, object given in %s on line %d
+bool(false)
+
+--undefined var--
+
+Warning: idate(): idate format is one char in %s on line %d
+bool(false)
+
+Warning: idate(): idate format is one char in %s on line %d
+bool(false)
+
+--unset var--
+
+Warning: idate(): idate format is one char in %s on line %d
+bool(false)
+
+Warning: idate(): idate format is one char in %s on line %d
+bool(false)
+===DONE===
diff --git a/ext/date/tests/idate_variation2.phpt b/ext/date/tests/idate_variation2.phpt
new file mode 100644 (file)
index 0000000..7dd761d
--- /dev/null
@@ -0,0 +1,191 @@
+--TEST--
+Test idate() function : usage variation - Passing unexpected values to second optional argument 'timestamp'.
+--FILE--
+<?php
+/* Prototype  : int idate(string format [, int timestamp])
+ * Description: Format a local time/date as integer 
+ * Source code: ext/date/php_date.c
+ * Alias to functions: 
+ */
+
+echo "*** Testing idate() : usage variation ***\n";
+
+// Initialise function arguments not being substituted (if any)
+$format = 'Y';
+date_default_timezone_set("Asia/Calcutta");
+
+//get an unset variable
+$unset_var = 10;
+unset ($unset_var);
+
+// define some classes
+class classWithToString
+{
+       public function __toString() {
+               return "Class A object";
+       }
+}
+
+class classWithoutToString
+{
+}
+
+// heredoc string
+$heredoc = <<<EOT
+hello world
+EOT;
+
+// add arrays
+$index_array = array (1, 2, 3);
+$assoc_array = array ('one' => 1, 'two' => 2);
+
+//array of values to iterate over
+$inputs = array(
+
+      // float data
+      'float 10.5' => 10.5,
+      'float -10.5' => -10.5,
+      'float .5' => .5,
+
+      // array data
+      'empty array' => array(),
+      'int indexed array' => $index_array,
+      'associative array' => $assoc_array,
+      'nested arrays' => array('foo', $index_array, $assoc_array),
+
+      // null data
+      'uppercase NULL' => NULL,
+      'lowercase null' => null,
+
+      // boolean data
+      'lowercase true' => true,
+      'lowercase false' =>false,
+      'uppercase TRUE' =>TRUE,
+      'uppercase FALSE' =>FALSE,
+
+      // empty data
+      'empty string DQ' => "",
+      'empty string SQ' => '',
+
+      // string data
+      'string DQ' => "string",
+      'string SQ' => 'string',
+      'mixed case string' => "sTrInG",
+      'heredoc' => $heredoc,
+
+      // object data
+      'instance of classWithToString' => new classWithToString(),
+      'instance of classWithoutToString' => new classWithoutToString(),
+
+      // undefined data
+      'undefined var' => @$undefined_var,
+
+      // unset data
+      'unset var' => @$unset_var,
+);
+
+// loop through each element of the array for timestamp
+
+foreach($inputs as $key =>$value) {
+      echo "\n--$key--\n";
+      var_dump( idate($format, $value) );
+};
+
+?>
+===DONE===
+--EXPECTF--
+*** Testing idate() : usage variation ***
+
+--float 10.5--
+int(1970)
+
+--float -10.5--
+int(1970)
+
+--float .5--
+int(1970)
+
+--empty array--
+
+Warning: idate() expects parameter 2 to be long, array given in %s on line %d
+bool(false)
+
+--int indexed array--
+
+Warning: idate() expects parameter 2 to be long, array given in %s on line %d
+bool(false)
+
+--associative array--
+
+Warning: idate() expects parameter 2 to be long, array given in %s on line %d
+bool(false)
+
+--nested arrays--
+
+Warning: idate() expects parameter 2 to be long, array given in %s on line %d
+bool(false)
+
+--uppercase NULL--
+int(1970)
+
+--lowercase null--
+int(1970)
+
+--lowercase true--
+int(1970)
+
+--lowercase false--
+int(1970)
+
+--uppercase TRUE--
+int(1970)
+
+--uppercase FALSE--
+int(1970)
+
+--empty string DQ--
+
+Warning: idate() expects parameter 2 to be long, string given in %s on line %d
+bool(false)
+
+--empty string SQ--
+
+Warning: idate() expects parameter 2 to be long, string given in %s on line %d
+bool(false)
+
+--string DQ--
+
+Warning: idate() expects parameter 2 to be long, string given in %s on line %d
+bool(false)
+
+--string SQ--
+
+Warning: idate() expects parameter 2 to be long, string given in %s on line %d
+bool(false)
+
+--mixed case string--
+
+Warning: idate() expects parameter 2 to be long, string given in %s on line %d
+bool(false)
+
+--heredoc--
+
+Warning: idate() expects parameter 2 to be long, string given in %s on line %d
+bool(false)
+
+--instance of classWithToString--
+
+Warning: idate() expects parameter 2 to be long, object given in %s on line %d
+bool(false)
+
+--instance of classWithoutToString--
+
+Warning: idate() expects parameter 2 to be long, object given in %s on line %d
+bool(false)
+
+--undefined var--
+int(1970)
+
+--unset var--
+int(1970)
+===DONE===
diff --git a/ext/date/tests/idate_variation3.phpt b/ext/date/tests/idate_variation3.phpt
new file mode 100644 (file)
index 0000000..1a2ee1f
--- /dev/null
@@ -0,0 +1,35 @@
+--TEST--
+Test idate() function : usage variation - Passing higher positive and negetive float values to timestamp.
+--FILE--
+<?php
+/* Prototype  : int idate(string format [, int timestamp])
+ * Description: Format a local time/date as integer 
+ * Source code: ext/date/php_date.c
+ * Alias to functions: 
+ */
+
+echo "*** Testing idate() : usage variation ***\n";
+
+// Initialise function arguments not being substituted (if any)
+$format = 'Y';
+date_default_timezone_set("Asia/Calcutta");
+
+echo "\n-- Testing idate() function with float 12.3456789000e10 to timestamp --\n";
+$timestamp = 12.3456789000e10;
+var_dump( idate($format, $timestamp) );
+
+echo "\n-- Testing idate() function with float -12.3456789000e10 to timestamp --\n";
+$timestamp = -12.3456789000e10;
+var_dump( idate($format, $timestamp) );
+      
+?>
+===DONE===
+--EXPECTREGEX--
+\*\*\* Testing idate\(\) : usage variation \*\*\*
+
+-- Testing idate\(\) function with float 12.3456789000e10 to timestamp --
+int\((1935|5882)\)
+
+-- Testing idate\(\) function with float -12.3456789000e10 to timestamp --
+int\((2004|1901|-1943)\)
+===DONE===
diff --git a/ext/date/tests/idate_variation4.phpt b/ext/date/tests/idate_variation4.phpt
new file mode 100644 (file)
index 0000000..6aa1735
--- /dev/null
@@ -0,0 +1,66 @@
+--TEST--
+Test idate() function : usage variation - Passing supported Date format characters to format argument.
+--FILE--
+<?php
+/* Prototype  : int idate(string format [, int timestamp])
+ * Description: Format a local time/date as integer 
+ * Source code: ext/date/php_date.c
+ * Alias to functions: 
+ */
+
+echo "*** Testing idate() : usage variation ***\n";
+
+// Initialise function arguments not being substituted (if any)
+date_default_timezone_set("Asia/Calcutta");
+
+//array of values to iterate over
+$inputs = array(
+
+         'Day of the month' => 'd',
+         'Leap Year' =>'L',
+         'Month number' => 'm',
+         'Days in the month' => 't',
+         'Day of the week' => 'w',
+         'ISO-8601 week number' => 'W',
+         'Year (1 or 2 digits)' => 'y',
+         'Year 4 digits' => 'Y',
+         'Day of the year' => 'z',
+);
+
+// loop through each element of the array for timestamp
+foreach($inputs as $key =>$value) {
+      echo "\n--$key--\n";
+      var_dump( idate($value) );
+};
+?>
+===DONE===
+--EXPECTF--
+*** Testing idate() : usage variation ***
+
+--Day of the month--
+int(%d)
+
+--Leap Year--
+int(%d)
+
+--Month number--
+int(%d)
+
+--Days in the month--
+int(%d)
+
+--Day of the week--
+int(%d)
+
+--ISO-8601 week number--
+int(%d)
+
+--Year (1 or 2 digits)--
+int(%d)
+
+--Year 4 digits--
+int(%d)
+
+--Day of the year--
+int(%d)
+===DONE===
diff --git a/ext/date/tests/idate_variation5.phpt b/ext/date/tests/idate_variation5.phpt
new file mode 100644 (file)
index 0000000..e70509c
--- /dev/null
@@ -0,0 +1,62 @@
+--TEST--
+Test idate() function : usage variation - Passing supported Time format characters to format argument.
+--FILE--
+<?php
+/* Prototype  : int idate(string format [, int timestamp])
+ * Description: Format a local time/date as integer 
+ * Source code: ext/date/php_date.c
+ * Alias to functions: 
+ */
+
+echo "*** Testing idate() : usage variation ***\n";
+
+// Initialise function arguments not being substituted (if any)
+date_default_timezone_set("Asia/Calcutta");
+
+//array of values to iterate over
+$inputs = array(
+
+      'Internet Time' => 'B',
+         '12 hour format' => 'h',
+         '24 hour format' => 'H',
+         'Minutes' => 'i',
+         'DST Activated' => 'I',
+         'Seconds' => 's',
+         'Seconds since Unix Epoch' => 'U',
+         'Time zone offset' => 'Z'
+);
+
+// loop through each element of the array for timestamp
+foreach($inputs as $key =>$value) {
+      echo "\n--$key--\n";
+      var_dump( idate($value) );
+};
+?>
+===DONE===
+--EXPECTF--
+*** Testing idate() : usage variation ***
+
+--Internet Time--
+int(%d)
+
+--12 hour format--
+int(%d)
+
+--24 hour format--
+int(%d)
+
+--Minutes--
+int(%d)
+
+--DST Activated--
+int(%d)
+
+--Seconds--
+int(%d)
+
+--Seconds since Unix Epoch--
+int(%d)
+
+--Time zone offset--
+int(%d)
+===DONE===
diff --git a/ext/date/tests/idate_variation6.phpt b/ext/date/tests/idate_variation6.phpt
new file mode 100644 (file)
index 0000000..161a80d
--- /dev/null
@@ -0,0 +1,34 @@
+--TEST--
+Test idate() function : usage variation - Checking return of year(1 or 2 digits) format starting with zero and nonzero.
+--FILE--
+<?php
+/* Prototype  : int idate(string format [, int timestamp])
+ * Description: Format a local time/date as integer 
+ * Source code: ext/date/php_date.c
+ * Alias to functions: 
+ */
+
+echo "*** Testing idate() : usage variation ***\n";
+
+// Initialise function arguments not being substituted (if any)
+date_default_timezone_set("Asia/Calcutta");
+$format = 'y';
+
+echo "\n-- Testing idate() function for 2 digit year having no zero as starting number --\n";
+$timestamp = mktime(8, 8, 8, 8, 8, 1970);
+var_dump( idate($format, $timestamp) );
+
+echo "\n-- Testing idate() function for 2 digit year having zero as starting number --\n";
+$timestamp = mktime(8, 8, 8, 8, 8, 2001);
+var_dump( idate($format, $timestamp) );
+?>
+===DONE===
+--EXPECTF--
+*** Testing idate() : usage variation ***
+
+-- Testing idate() function for 2 digit year having no zero as starting number --
+int(70)
+
+-- Testing idate() function for 2 digit year having zero as starting number --
+int(1)
+===DONE===