]> granicus.if.org Git - php/commitdiff
IMPA fetchheader tests
authorZoe Slattery <zoe@php.net>
Fri, 23 Jan 2009 15:32:48 +0000 (15:32 +0000)
committerZoe Slattery <zoe@php.net>
Fri, 23 Jan 2009 15:32:48 +0000 (15:32 +0000)
ext/imap/tests/imap_fetchheader_basic.phpt [new file with mode: 0644]
ext/imap/tests/imap_fetchheader_error.phpt [new file with mode: 0644]
ext/imap/tests/imap_fetchheader_variation1.phpt [new file with mode: 0644]
ext/imap/tests/imap_fetchheader_variation2.phpt [new file with mode: 0644]
ext/imap/tests/imap_fetchheader_variation3.phpt [new file with mode: 0644]
ext/imap/tests/imap_fetchheader_variation4.phpt [new file with mode: 0644]
ext/imap/tests/imap_fetchheader_variation5.phpt [new file with mode: 0644]

diff --git a/ext/imap/tests/imap_fetchheader_basic.phpt b/ext/imap/tests/imap_fetchheader_basic.phpt
new file mode 100644 (file)
index 0000000..2e47b0c
--- /dev/null
@@ -0,0 +1,83 @@
+--TEST--
+Test imap_fetchheader() function : basic functions 
+--SKIPIF--
+<?php
+require_once(dirname(__FILE__).'/skipif.inc');
+?>
+--FILE--
+<?php
+/* Prototype  : string imap_fetchheader(resource $stream_id, int $msg_no [, int $options])
+ * Description: Get the full unfiltered header for a message 
+ * Source code: ext/imap/php_imap.c
+ */
+
+echo "*** Testing imap_fetchheader() : basic functionality ***\n";
+require_once(dirname(__FILE__).'/imap_include.inc');
+
+// Initialise all required variables
+$stream_id = setup_test_mailbox('', 1, $mailbox, 'multiPart'); // setup temp mailbox with 1 msg
+$msg_no = 1;
+$options = array('FT_UID' => FT_UID, 'FT_INTERNAL' => FT_INTERNAL, 
+                 'FT_PREFETCHTEXT' => FT_PREFETCHTEXT);
+
+// Calling imap_fetchheader() with all possible arguments
+echo "\n-- All possible arguments --\n";
+foreach ($options as $key => $option) {
+       echo "-- Option is $key --\n";
+       if ($key == 'FT_UID') {
+               $msg_uid = imap_uid($stream_id, $msg_no);
+               var_dump(imap_fetchheader($stream_id, $msg_uid, $option));
+       } else {
+               var_dump(imap_fetchheader($stream_id, $msg_no, $option));
+       }
+}
+
+// Calling imap_fetchheader() with mandatory arguments
+echo "\n-- Mandatory arguments --\n";
+var_dump( imap_fetchheader($stream_id, $msg_no) );
+?>
+===DONE===
+--CLEAN--
+<?php
+require_once(dirname(__FILE__).'/clean.inc');
+?>
+--EXPECTF--
+*** Testing imap_fetchheader() : basic functionality ***
+Create a temporary mailbox and add 1 msgs
+.. mailbox '%s.phpttest' created
+
+-- All possible arguments --
+-- Option is FT_UID --
+string(%d) "From: foo@anywhere.com
+Subject: Test msg 1
+To: %s
+MIME-Version: 1.0
+Content-Type: %s; %s
+
+"
+-- Option is FT_INTERNAL --
+string(%d) "From: foo@anywhere.com
+Subject: Test msg 1
+To: %s
+MIME-Version: 1.0
+Content-Type: %s; %s
+
+"
+-- Option is FT_PREFETCHTEXT --
+string(%d) "From: foo@anywhere.com
+Subject: Test msg 1
+To: %s
+MIME-Version: 1.0
+Content-Type: %s; %s
+
+"
+
+-- Mandatory arguments --
+string(%d) "From: foo@anywhere.com
+Subject: Test msg 1
+To: %s
+MIME-Version: 1.0
+Content-Type: %s; %s
+
+"
+===DONE===
diff --git a/ext/imap/tests/imap_fetchheader_error.phpt b/ext/imap/tests/imap_fetchheader_error.phpt
new file mode 100644 (file)
index 0000000..143e45e
--- /dev/null
@@ -0,0 +1,49 @@
+--TEST--
+Test imap_fetchheader() function : error conditions - incorrect number of args
+--SKIPIF--
+<?php
+require_once(dirname(__FILE__).'/skipif.inc');
+?>
+--FILE--
+<?php
+/* Prototype  : string imap_fetchheader(resource $stream_id, int $msg_no [, int $options])
+ * Description: Get the full unfiltered header for a message 
+ * Source code: ext/imap/php_imap.c
+ */
+
+/*
+ * Pass an incorrect number of arguments to imap_fetchheader() to test behaviour
+ */
+
+echo "*** Testing imap_fetchheader() : error conditions ***\n";
+require_once(dirname(__FILE__).'/imap_include.inc');
+
+//Test imap_fetchheader with one more than the expected number of arguments
+echo "\n-- Testing imap_fetchheader() function with more than expected no. of arguments --\n";
+
+$stream_id = imap_open($server, $username, $password);
+$msg_no = 10;
+$options = 10;
+$extra_arg = 10;
+var_dump( imap_fetchheader($stream_id, $msg_no, $options, $extra_arg) );
+
+// Testing imap_fetchheader with one less than the expected number of arguments
+echo "\n-- Testing imap_fetchheader() function with less than expected no. of arguments --\n";
+var_dump( imap_fetchheader($stream_id) );
+
+imap_close($stream_id);
+?>
+===DONE===
+--EXPECTF--
+*** Testing imap_fetchheader() : error conditions ***
+
+-- Testing imap_fetchheader() function with more than expected no. of arguments --
+
+Warning: Wrong parameter count for imap_fetchheader() in %s on line %d
+NULL
+
+-- Testing imap_fetchheader() function with less than expected no. of arguments --
+
+Warning: Wrong parameter count for imap_fetchheader() in %s on line %d
+NULL
+===DONE===
diff --git a/ext/imap/tests/imap_fetchheader_variation1.phpt b/ext/imap/tests/imap_fetchheader_variation1.phpt
new file mode 100644 (file)
index 0000000..b4f6d17
--- /dev/null
@@ -0,0 +1,245 @@
+--TEST--
+Test imap_fetchheader() function : usage variations - diff data types as $stream_id arg
+--SKIPIF--
+<?php
+extension_loaded('imap') or die('skip imap extension not available in this build');
+?>
+--FILE--
+<?php
+/* Prototype  : string imap_fetchheader(resource $stream_id, int $msg_no [, int $options])
+ * Description: Get the full unfiltered header for a message 
+ * Source code: ext/imap/php_imap.c
+ */
+
+/*
+ * Pass different data types as $stream_id argument to test behaviour of imap_fetchheader()
+ */
+
+echo "*** Testing imap_fetchheader() : usage variations ***\n";
+
+// Initialise function arguments not being substituted
+$msg_no = 1;
+
+//get an unset variable
+$unset_var = 10;
+unset ($unset_var);
+
+// get a class
+class classA
+{
+  public function __toString() {
+    return "Class A object";
+  }
+}
+
+// heredoc string
+$heredoc = <<<EOT
+hello world
+EOT;
+
+// get different types of array
+$index_array = array (1, 2, 3);
+$assoc_array = array ('one' => 1, 'two' => 2);
+
+// get a resource variable
+$fp = fopen(__FILE__, "r");
+
+// unexpected values to be passed to $stream_id argument
+$inputs = array(
+
+       // int data
+/*1*/  0,
+       1,
+       12345,
+       -2345,
+
+       // float data
+/*5*/  10.5,
+       -10.5,
+       12.3456789000e10,
+       12.3456789000E-10,
+       .5,
+
+       // null data
+/*10*/ NULL,
+       null,
+
+       // boolean data
+/*12*/ true,
+       false,
+       TRUE,
+       FALSE,
+       
+       // empty data
+/*16*/ "",
+       '',
+
+       // string data
+/*18*/ "string",
+       'string',
+       $heredoc,
+       
+       // array data
+/*21*/ array(),
+       $index_array,
+       $assoc_array,
+       array('foo', $index_array, $assoc_array),
+       
+       
+       // object data
+/*25*/ new classA(),
+
+       // undefined data
+/*26*/ @$undefined_var,
+
+       // unset data
+/*27*/ @$unset_var,
+);
+
+// loop through each element of $inputs to check the behavior of imap_fetchheader()
+$iterator = 1;
+foreach($inputs as $input) {
+  echo "\n-- Iteration $iterator --\n";
+  var_dump( imap_fetchheader($input, $msg_no) );
+  $iterator++;
+};
+?>
+===DONE===
+--EXPECTF--
+*** Testing imap_fetchheader() : usage variations ***
+
+-- Iteration 1 --
+
+Warning: imap_fetchheader(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Iteration 2 --
+
+Warning: imap_fetchheader(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Iteration 3 --
+
+Warning: imap_fetchheader(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Iteration 4 --
+
+Warning: imap_fetchheader(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Iteration 5 --
+
+Warning: imap_fetchheader(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Iteration 6 --
+
+Warning: imap_fetchheader(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Iteration 7 --
+
+Warning: imap_fetchheader(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Iteration 8 --
+
+Warning: imap_fetchheader(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Iteration 9 --
+
+Warning: imap_fetchheader(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Iteration 10 --
+
+Warning: imap_fetchheader(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Iteration 11 --
+
+Warning: imap_fetchheader(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Iteration 12 --
+
+Warning: imap_fetchheader(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Iteration 13 --
+
+Warning: imap_fetchheader(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Iteration 14 --
+
+Warning: imap_fetchheader(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Iteration 15 --
+
+Warning: imap_fetchheader(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Iteration 16 --
+
+Warning: imap_fetchheader(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Iteration 17 --
+
+Warning: imap_fetchheader(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Iteration 18 --
+
+Warning: imap_fetchheader(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Iteration 19 --
+
+Warning: imap_fetchheader(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Iteration 20 --
+
+Warning: imap_fetchheader(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Iteration 21 --
+
+Warning: imap_fetchheader(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Iteration 22 --
+
+Warning: imap_fetchheader(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Iteration 23 --
+
+Warning: imap_fetchheader(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Iteration 24 --
+
+Warning: imap_fetchheader(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Iteration 25 --
+
+Warning: imap_fetchheader(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Iteration 26 --
+
+Warning: imap_fetchheader(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Iteration 27 --
+
+Warning: imap_fetchheader(): supplied argument is not a valid imap resource in %s on line %d
+bool(false)
+===DONE===
diff --git a/ext/imap/tests/imap_fetchheader_variation2.phpt b/ext/imap/tests/imap_fetchheader_variation2.phpt
new file mode 100644 (file)
index 0000000..65d5d85
--- /dev/null
@@ -0,0 +1,292 @@
+--TEST--
+Test imap_fetchheader() function : usage variations - diff data types for $msg_no arg
+--SKIPIF--
+<?php
+require_once(dirname(__FILE__).'/skipif.inc');
+?>
+--FILE--
+<?php
+/* Prototype  : string imap_fetchheader(resource $stream_id, int $msg_no [, int $options])
+ * Description: Get the full unfiltered header for a message 
+ * Source code: ext/imap/php_imap.c
+ */
+
+/*
+ * Pass different data types as $msg_no argument to test behaviour of imap_fetchheader()
+ */
+
+echo "*** Testing imap_fetchheader() : usage variations ***\n";
+require_once(dirname(__FILE__).'/imap_include.inc');
+
+// Initialise function arguments not being substituted
+$stream_id = setup_test_mailbox('', 1, $mailbox, 'notSimple'); // set up temp mailbox with 1 msg
+
+//get an unset variable
+$unset_var = 10;
+unset ($unset_var);
+
+// get a class
+class classA
+{
+  public function __toString() {
+    return "Class A object";
+  }
+}
+
+// heredoc string
+$heredoc = <<<EOT
+hello world
+EOT;
+
+$index_array = array (1, 2, 3);
+$assoc_array = array ('one' => 1, 'two' => 2);
+
+// get a resource variable
+$fp = fopen(__FILE__, "r");
+
+// unexpected values to be passed to $msg_no argument
+$inputs = array(
+
+       // int data
+/*1*/  0,
+       1,
+       12345,
+       -2345,
+
+       // float data
+/*5*/  10.5,
+       -10.5,
+       12.3456789000e10,
+       12.3456789000E-10,
+       .5,
+
+       // null data
+/*10*/ NULL,
+       null,
+
+       // boolean data
+/*12*/ true,
+       false,
+       TRUE,
+       FALSE,
+       
+       // empty data
+/*16*/ "",
+       '',
+
+       // string data
+/*18*/ "string",
+       'string',
+       $heredoc,
+       
+       // array data
+/*21*/ array(),
+       $index_array,
+       $assoc_array,
+       array('foo', $index_array, $assoc_array),
+       
+       
+       // object data
+/*25*/ new classA(),
+
+       // undefined data
+/*26*/ @$undefined_var,
+
+       // unset data
+/*27*/ @$unset_var,
+
+       // resource variable
+/*28*/ $fp
+);
+
+// loop through each element of $inputs to check the behavior of imap_fetchheader()
+$iterator = 1;
+foreach($inputs as $input) {
+  echo "\n-- Iteration $iterator --\n";
+  var_dump( imap_fetchheader($stream_id, $input) );
+  $iterator++;
+};
+
+fclose($fp);
+?>
+===DONE===
+--CLEAN--
+<?php
+require_once(dirname(__FILE__).'/clean.inc');
+?>
+===DONE===
+--EXPECTF--
+*** Testing imap_fetchheader() : usage variations ***
+Create a temporary mailbox and add 1 msgs
+.. mailbox '{localhost/norsh}INBOX.phpttest' created
+
+-- Iteration 1 --
+
+Warning: imap_fetchheader(): Bad message number in %s on line %d
+bool(false)
+
+-- Iteration 2 --
+string(%d) "From: foo@anywhere.com
+Subject: Test msg 1
+To: %s
+MIME-Version: 1.0
+Content-Type: MULTIPART/mixed; BOUNDARY="%s"
+
+"
+
+-- Iteration 3 --
+
+Warning: imap_fetchheader(): Bad message number in %s on line %d
+bool(false)
+
+-- Iteration 4 --
+
+Warning: imap_fetchheader(): Bad message number in %s on line %d
+bool(false)
+
+-- Iteration 5 --
+
+Warning: imap_fetchheader(): Bad message number in %s on line %d
+bool(false)
+
+-- Iteration 6 --
+
+Warning: imap_fetchheader(): Bad message number in %s on line %d
+bool(false)
+
+-- Iteration 7 --
+
+Warning: imap_fetchheader(): Bad message number in %s on line %d
+bool(false)
+
+-- Iteration 8 --
+
+Warning: imap_fetchheader(): Bad message number in %s on line %d
+bool(false)
+
+-- Iteration 9 --
+
+Warning: imap_fetchheader(): Bad message number in %s on line %d
+bool(false)
+
+-- Iteration 10 --
+
+Warning: imap_fetchheader(): Bad message number in %s on line %d
+bool(false)
+
+-- Iteration 11 --
+
+Warning: imap_fetchheader(): Bad message number in %s on line %d
+bool(false)
+
+-- Iteration 12 --
+string(%d) "From: foo@anywhere.com
+Subject: Test msg 1
+To: %s
+MIME-Version: 1.0
+Content-Type: MULTIPART/mixed; BOUNDARY="%s"
+
+"
+
+-- Iteration 13 --
+
+Warning: imap_fetchheader(): Bad message number in %s on line %d
+bool(false)
+
+-- Iteration 14 --
+string(%d) "From: foo@anywhere.com
+Subject: Test msg 1
+To: %s
+MIME-Version: 1.0
+Content-Type: MULTIPART/mixed; BOUNDARY="%s"
+
+"
+
+-- Iteration 15 --
+
+Warning: imap_fetchheader(): Bad message number in %s on line %d
+bool(false)
+
+-- Iteration 16 --
+
+Warning: imap_fetchheader(): Bad message number in %s on line %d
+bool(false)
+
+-- Iteration 17 --
+
+Warning: imap_fetchheader(): Bad message number in %s on line %d
+bool(false)
+
+-- Iteration 18 --
+
+Warning: imap_fetchheader(): Bad message number in %s on line %d
+bool(false)
+
+-- Iteration 19 --
+
+Warning: imap_fetchheader(): Bad message number in %s on line %d
+bool(false)
+
+-- Iteration 20 --
+
+Warning: imap_fetchheader(): Bad message number in %s on line %d
+bool(false)
+
+-- Iteration 21 --
+
+Warning: imap_fetchheader(): Bad message number in %s on line %d
+bool(false)
+
+-- Iteration 22 --
+string(%d) "From: foo@anywhere.com
+Subject: Test msg 1
+To: %s
+MIME-Version: 1.0
+Content-Type: MULTIPART/mixed; BOUNDARY="%s"
+
+"
+
+-- Iteration 23 --
+string(%d) "From: foo@anywhere.com
+Subject: Test msg 1
+To: %s
+MIME-Version: 1.0
+Content-Type: MULTIPART/mixed; BOUNDARY="%s"
+
+"
+
+-- Iteration 24 --
+string(%d) "From: foo@anywhere.com
+Subject: Test msg 1
+To: %s
+MIME-Version: 1.0
+Content-Type: MULTIPART/mixed; BOUNDARY="%s"
+
+"
+
+-- Iteration 25 --
+
+Notice: Object of class classA could not be converted to int in %s on line %d
+string(%d) "From: foo@anywhere.com
+Subject: Test msg 1
+To: %s
+MIME-Version: 1.0
+Content-Type: MULTIPART/mixed; BOUNDARY="%s"
+
+"
+
+-- Iteration 26 --
+
+Warning: imap_fetchheader(): Bad message number in %s on line %d
+bool(false)
+
+-- Iteration 27 --
+
+Warning: imap_fetchheader(): Bad message number in %s on line %d
+bool(false)
+
+-- Iteration 28 --
+
+Warning: imap_fetchheader(): Bad message number in %s on line %d
+bool(false)
+===DONE===
diff --git a/ext/imap/tests/imap_fetchheader_variation3.phpt b/ext/imap/tests/imap_fetchheader_variation3.phpt
new file mode 100644 (file)
index 0000000..e21c1a9
--- /dev/null
@@ -0,0 +1,77 @@
+--TEST--
+Test imap_fetchheader() function : usage variations - FT_UID option
+--SKIPIF--
+<?php
+require_once(dirname(__FILE__).'/skipif.inc');
+?>
+--FILE--
+<?php
+/* Prototype  : string imap_fetchheader(resource $stream_id, int $msg_no [, int $options])
+ * Description: Get the full unfiltered header for a message 
+ * Source code: ext/imap/php_imap.c
+ */
+
+/*
+ * Test if FT_UID is set by passing the following as $options argument to imap_fetchheader():
+ * 1. values that equate to 1
+ * 2. Minimum and maximum PHP values
+ */
+
+echo "*** Testing imap_fetchheader() : usage variations ***\n";
+
+require_once(dirname(__FILE__).'/imap_include.inc');
+
+// Initialise required variables
+$stream_id = setup_test_mailbox('', 1); // set up temporary mailbox with one simple message
+$msg_no = 1;
+$msg_uid = imap_uid($stream_id, $msg_no);
+
+$options = array ('1', true, 
+                  1.000000000000001, 0.00001e5, 
+                  PHP_INT_MAX, -PHP_INT_MAX);
+
+// iterate over each element of $options array to test whether FT_UID is set
+$iterator = 1;
+imap_check($stream_id);
+foreach($options as $option) {
+       echo "\n-- Iteration $iterator --\n";
+       if(is_string(imap_fetchheader($stream_id, $msg_uid, $option))) {
+               echo "FT_UID valid\n";
+       } else {
+                echo "FT_UID not valid\n";
+        }
+       $iterator++;
+}
+?>
+===DONE===
+--CLEAN--
+<?php
+require_once(dirname(__FILE__).'/clean.inc');
+?>
+--EXPECTF--
+*** Testing imap_fetchheader() : usage variations ***
+Create a temporary mailbox and add 1 msgs
+.. mailbox '{localhost/norsh}INBOX.phpttest' created
+
+-- Iteration 1 --
+FT_UID valid
+
+-- Iteration 2 --
+FT_UID valid
+
+-- Iteration 3 --
+FT_UID valid
+
+-- Iteration 4 --
+FT_UID valid
+
+-- Iteration 5 --
+
+Warning: imap_fetchheader(): invalid value for the options parameter in %s on line %d
+FT_UID not valid
+
+-- Iteration 6 --
+
+Warning: imap_fetchheader(): invalid value for the options parameter in %s on line %d
+FT_UID not valid
+===DONE===
diff --git a/ext/imap/tests/imap_fetchheader_variation4.phpt b/ext/imap/tests/imap_fetchheader_variation4.phpt
new file mode 100644 (file)
index 0000000..b4b19e3
--- /dev/null
@@ -0,0 +1,45 @@
+--TEST--
+Test imap_fetchheader() function : usage variations - diff resource types as $stream_id
+--SKIPIF--
+<?php
+extension_loaded('imap') or die('skip imap extension not available in this build');
+?>
+--FILE--
+<?php
+/* Prototype  : string imap_fetchheader(resource $stream_id, int $msg_no [, int $options])
+ * Description: Get the full unfiltered header for a message 
+ * Source code: ext/imap/php_imap.c
+ */
+
+/*
+ * Pass different types of resources to imap_fetchheader() to test behaviour
+ */
+
+echo "*** Testing imap_fetchheader() : usage variations ***\n";
+
+echo "\n-- File Resource opened with fopen() --\n";
+var_dump($file_pointer = fopen(__FILE__, 'r+'));
+var_dump(imap_fetchheader($file_pointer, 1));
+fclose($file_pointer);
+
+echo "\n-- Directory Resource opened with opendir() --\n";
+var_dump($dir_handle = opendir(dirname(__FILE__)));
+var_dump(imap_fetchheader($dir_handle, 1));
+closedir($dir_handle);
+?>
+===DONE===
+--EXPECTF--
+*** Testing imap_fetchheader() : usage variations ***
+
+-- File Resource opened with fopen() --
+resource(%d) of type (stream)
+
+Warning: imap_fetchheader(): supplied resource is not a valid imap resource in %s on line %d
+bool(false)
+
+-- Directory Resource opened with opendir() --
+resource(%d) of type (stream)
+
+Warning: imap_fetchheader(): supplied resource is not a valid imap resource in %s on line %d
+bool(false)
+===DONE===
\ No newline at end of file
diff --git a/ext/imap/tests/imap_fetchheader_variation5.phpt b/ext/imap/tests/imap_fetchheader_variation5.phpt
new file mode 100644 (file)
index 0000000..f0f5fd5
--- /dev/null
@@ -0,0 +1,79 @@
+--TEST--
+Test imap_fetchheader() function : usage variations - $msg_no argument
+--SKIPIF--
+<?php
+require_once(dirname(__FILE__).'/skipif.inc');
+?>
+--FILE--
+<?php
+/* Prototype  : string imap_fetchheader(resource $stream_id, int $msg_no [, int $options])
+ * Description: Get the full unfiltered header for a message 
+ * Source code: ext/imap/php_imap.c
+ */
+
+/*
+ * Pass different integers and strings as $msg_no argument 
+ * to test behaviour of imap_fetchheader()
+ */
+
+echo "*** Testing imap_fetchheader() : usage variations ***\n";
+
+require_once(dirname(__FILE__).'/imap_include.inc');
+
+$stream_id = setup_test_mailbox('', 3, $mailbox, 'notSimple'); // set up temp mailbox with 3 msgs
+
+$sequences = array (0,     4, // out of range
+                    '1,3', '1:3', // message sequences instead of numbers
+                    );
+
+foreach($sequences as $msg_no) {
+       echo "\n-- \$msg_no is $msg_no --\n";
+       var_dump($overview = imap_fetchheader($stream_id, $msg_no));
+       if (!$overview) {
+               echo imap_last_error() . "\n";
+       }
+}
+
+// clear error stack
+imap_errors();
+?>
+===DONE===
+--CLEAN--
+<?php
+require_once(dirname(__FILE__).'/clean.inc');
+?>
+--EXPECTF--
+*** Testing imap_fetchheader() : usage variations ***
+Create a temporary mailbox and add 3 msgs
+.. mailbox '{localhost/norsh}INBOX.phpttest' created
+
+-- $msg_no is 0 --
+
+Warning: imap_fetchheader(): Bad message number in %s on line %d
+bool(false)
+
+
+-- $msg_no is 4 --
+
+Warning: imap_fetchheader(): Bad message number in %s on line %d
+bool(false)
+
+
+-- $msg_no is 1,3 --
+string(%d) "From: foo@anywhere.com
+Subject: Test msg 1
+To: %s
+MIME-Version: 1.0
+Content-Type: MULTIPART/mixed; BOUNDARY="%s"
+
+"
+
+-- $msg_no is 1:3 --
+string(%d) "From: foo@anywhere.com
+Subject: Test msg 1
+To: %s
+MIME-Version: 1.0
+Content-Type: MULTIPART/mixed; BOUNDARY="%s"
+
+"
+===DONE===