From 888bb4e7792db1ede3bc9f8dd75e15d3cf5933e2 Mon Sep 17 00:00:00 2001 From: Zoe Slattery Date: Fri, 23 Jan 2009 15:29:22 +0000 Subject: [PATCH] IMAP fetchheader tests --- ext/imap/tests/imap_fetchheader_basic.phpt | 85 ++++++ ext/imap/tests/imap_fetchheader_error.phpt | 49 ++++ .../tests/imap_fetchheader_variation1.phpt | 245 ++++++++++++++++ .../tests/imap_fetchheader_variation2.phpt | 276 ++++++++++++++++++ .../tests/imap_fetchheader_variation3.phpt | 77 +++++ .../tests/imap_fetchheader_variation4.phpt | 45 +++ .../tests/imap_fetchheader_variation5.phpt | 85 ++++++ 7 files changed, 862 insertions(+) create mode 100644 ext/imap/tests/imap_fetchheader_basic.phpt create mode 100644 ext/imap/tests/imap_fetchheader_error.phpt create mode 100644 ext/imap/tests/imap_fetchheader_variation1.phpt create mode 100644 ext/imap/tests/imap_fetchheader_variation2.phpt create mode 100644 ext/imap/tests/imap_fetchheader_variation3.phpt create mode 100644 ext/imap/tests/imap_fetchheader_variation4.phpt create mode 100644 ext/imap/tests/imap_fetchheader_variation5.phpt diff --git a/ext/imap/tests/imap_fetchheader_basic.phpt b/ext/imap/tests/imap_fetchheader_basic.phpt new file mode 100644 index 0000000000..4a32944af1 --- /dev/null +++ b/ext/imap/tests/imap_fetchheader_basic.phpt @@ -0,0 +1,85 @@ +--TEST-- +Test imap_fetchheader() function : basic functionality +--XFAIL-- +To fix: change zend_hash_find() to zend_ascii_hash_find() in php_imap.c (imap_mail_compose()). +--SKIPIF-- + +--FILE-- + 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-- + +--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 index 0000000000..e2f5b1260b --- /dev/null +++ b/ext/imap/tests/imap_fetchheader_error.phpt @@ -0,0 +1,49 @@ +--TEST-- +Test imap_fetchheader() function : error conditions - incorrect number of args +--SKIPIF-- + +--FILE-- + +===DONE=== +--EXPECTF-- +*** Testing imap_fetchheader() : error conditions *** + +-- Testing imap_fetchheader() function with more than expected no. of arguments -- + +Warning: imap_fetchheader() expects at most 3 parameters, 4 given in %s on line %d +NULL + +-- Testing imap_fetchheader() function with less than expected no. of arguments -- + +Warning: imap_fetchheader() expects at least 2 parameters, 1 given 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 index 0000000000..0c0e9e1f26 --- /dev/null +++ b/ext/imap/tests/imap_fetchheader_variation1.phpt @@ -0,0 +1,245 @@ +--TEST-- +Test imap_fetchheader() function : usage variations - diff data types as $stream_id arg +--SKIPIF-- + +--FILE-- + 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() expects parameter 1 to be resource, integer given in %s on line %d +NULL + +-- Iteration 2 -- + +Warning: imap_fetchheader() expects parameter 1 to be resource, integer given in %s on line %d +NULL + +-- Iteration 3 -- + +Warning: imap_fetchheader() expects parameter 1 to be resource, integer given in %s on line %d +NULL + +-- Iteration 4 -- + +Warning: imap_fetchheader() expects parameter 1 to be resource, integer given in %s on line %d +NULL + +-- Iteration 5 -- + +Warning: imap_fetchheader() expects parameter 1 to be resource, double given in %s on line %d +NULL + +-- Iteration 6 -- + +Warning: imap_fetchheader() expects parameter 1 to be resource, double given in %s on line %d +NULL + +-- Iteration 7 -- + +Warning: imap_fetchheader() expects parameter 1 to be resource, double given in %s on line %d +NULL + +-- Iteration 8 -- + +Warning: imap_fetchheader() expects parameter 1 to be resource, double given in %s on line %d +NULL + +-- Iteration 9 -- + +Warning: imap_fetchheader() expects parameter 1 to be resource, double given in %s on line %d +NULL + +-- Iteration 10 -- + +Warning: imap_fetchheader() expects parameter 1 to be resource, null given in %s on line %d +NULL + +-- Iteration 11 -- + +Warning: imap_fetchheader() expects parameter 1 to be resource, null given in %s on line %d +NULL + +-- Iteration 12 -- + +Warning: imap_fetchheader() expects parameter 1 to be resource, boolean given in %s on line %d +NULL + +-- Iteration 13 -- + +Warning: imap_fetchheader() expects parameter 1 to be resource, boolean given in %s on line %d +NULL + +-- Iteration 14 -- + +Warning: imap_fetchheader() expects parameter 1 to be resource, boolean given in %s on line %d +NULL + +-- Iteration 15 -- + +Warning: imap_fetchheader() expects parameter 1 to be resource, boolean given in %s on line %d +NULL + +-- Iteration 16 -- + +Warning: imap_fetchheader() expects parameter 1 to be resource, %unicode_string_optional% given in %s on line %d +NULL + +-- Iteration 17 -- + +Warning: imap_fetchheader() expects parameter 1 to be resource, %unicode_string_optional% given in %s on line %d +NULL + +-- Iteration 18 -- + +Warning: imap_fetchheader() expects parameter 1 to be resource, %unicode_string_optional% given in %s on line %d +NULL + +-- Iteration 19 -- + +Warning: imap_fetchheader() expects parameter 1 to be resource, %unicode_string_optional% given in %s on line %d +NULL + +-- Iteration 20 -- + +Warning: imap_fetchheader() expects parameter 1 to be resource, %unicode_string_optional% given in %s on line %d +NULL + +-- Iteration 21 -- + +Warning: imap_fetchheader() expects parameter 1 to be resource, array given in %s on line %d +NULL + +-- Iteration 22 -- + +Warning: imap_fetchheader() expects parameter 1 to be resource, array given in %s on line %d +NULL + +-- Iteration 23 -- + +Warning: imap_fetchheader() expects parameter 1 to be resource, array given in %s on line %d +NULL + +-- Iteration 24 -- + +Warning: imap_fetchheader() expects parameter 1 to be resource, array given in %s on line %d +NULL + +-- Iteration 25 -- + +Warning: imap_fetchheader() expects parameter 1 to be resource, object given in %s on line %d +NULL + +-- Iteration 26 -- + +Warning: imap_fetchheader() expects parameter 1 to be resource, null given in %s on line %d +NULL + +-- Iteration 27 -- + +Warning: imap_fetchheader() expects parameter 1 to be resource, null given in %s on line %d +NULL +===DONE=== diff --git a/ext/imap/tests/imap_fetchheader_variation2.phpt b/ext/imap/tests/imap_fetchheader_variation2.phpt new file mode 100644 index 0000000000..af4a37b817 --- /dev/null +++ b/ext/imap/tests/imap_fetchheader_variation2.phpt @@ -0,0 +1,276 @@ +--TEST-- +Test imap_fetchheader() function : usage variations - diff data types for $msg_no arg +--XFAIL-- +Missing unicode implementation in ext/imap +--SKIPIF-- + +--FILE-- + 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-- + +===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 -- +%unicode|string%(%d) "From: foo@anywhere.com +Subject: Test msg 1 +To: webmaster@something.com +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 -- +%unicode|string%(%d) "From: foo@anywhere.com +Subject: Test msg 1 +To: webmaster@something.com +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 -- +%unicode|string%(%d) "From: foo@anywhere.com +Subject: Test msg 1 +To: webmaster@something.com +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() expects parameter 2 to be long, %unicode_string_optional% given in %s on line %d +NULL + +-- Iteration 17 -- + +Warning: imap_fetchheader() expects parameter 2 to be long, %unicode_string_optional% given in %s on line %d +NULL + +-- Iteration 18 -- + +Warning: imap_fetchheader() expects parameter 2 to be long, %unicode_string_optional% given in %s on line %d +NULL + +-- Iteration 19 -- + +Warning: imap_fetchheader() expects parameter 2 to be long, %unicode_string_optional% given in %s on line %d +NULL + +-- Iteration 20 -- + +Warning: imap_fetchheader() expects parameter 2 to be long, %unicode_string_optional% given in %s on line %d +NULL + +-- Iteration 21 -- + +Warning: imap_fetchheader() expects parameter 2 to be long, array given in %s on line %d +NULL + +-- Iteration 22 -- + +Warning: imap_fetchheader() expects parameter 2 to be long, array given in %s on line %d +NULL + +-- Iteration 23 -- + +Warning: imap_fetchheader() expects parameter 2 to be long, array given in %s on line %d +NULL + +-- Iteration 24 -- + +Warning: imap_fetchheader() expects parameter 2 to be long, array given in %s on line %d +NULL + +-- Iteration 25 -- + +Warning: imap_fetchheader() expects parameter 2 to be long, object given in %s on line %d +NULL + +-- 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() expects parameter 2 to be long, resource given in %s on line %d +NULL +===DONE=== diff --git a/ext/imap/tests/imap_fetchheader_variation3.phpt b/ext/imap/tests/imap_fetchheader_variation3.phpt new file mode 100644 index 0000000000..e21c1a966c --- /dev/null +++ b/ext/imap/tests/imap_fetchheader_variation3.phpt @@ -0,0 +1,77 @@ +--TEST-- +Test imap_fetchheader() function : usage variations - FT_UID option +--SKIPIF-- + +--FILE-- + +===DONE=== +--CLEAN-- + +--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 index 0000000000..b4b19e3d37 --- /dev/null +++ b/ext/imap/tests/imap_fetchheader_variation4.phpt @@ -0,0 +1,45 @@ +--TEST-- +Test imap_fetchheader() function : usage variations - diff resource types as $stream_id +--SKIPIF-- + +--FILE-- + +===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 index 0000000000..40b770dd88 --- /dev/null +++ b/ext/imap/tests/imap_fetchheader_variation5.phpt @@ -0,0 +1,85 @@ +--TEST-- +Test imap_fetchheader() function : usage variations - $msg_no argument +--XFAIL-- +Missing unicode implementation in ext/imap +--SKIPIF-- + +--FILE-- + +===DONE=== +--CLEAN-- + +--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 -- + +Notice: A non well formed numeric value encountered in %s on line %d +%unicode|string%(%d) "From: foo@anywhere.com +Subject: Test msg 1 +To: webmaster@something.com +MIME-Version: 1.0 +Content-Type: MULTIPART/mixed; BOUNDARY="%s" + +" + +-- $msg_no is 1:3 -- + +Notice: A non well formed numeric value encountered in %s on line %d +%unicode|string%(%d) "From: foo@anywhere.com +Subject: Test msg 1 +To: webmaster@something.com +MIME-Version: 1.0 +Content-Type: MULTIPART/mixed; BOUNDARY="%s" + +" +===DONE=== -- 2.50.1