From: Zoe Slattery Date: Mon, 8 Dec 2008 19:12:39 +0000 (+0000) Subject: tests for imap_fetch_overview X-Git-Tag: php-5.3.0beta1~492 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6cf2385268be45a43fda16cc03bc41b3b652606f;p=php tests for imap_fetch_overview --- diff --git a/ext/imap/tests/imap_fetch_overview_basic.phpt b/ext/imap/tests/imap_fetch_overview_basic.phpt new file mode 100644 index 0000000000..80d5c69f1d --- /dev/null +++ b/ext/imap/tests/imap_fetch_overview_basic.phpt @@ -0,0 +1,118 @@ +--TEST-- +Test imap_fetch_overview() function : basic functionality +--SKIPIF-- + +--FILE-- + Object #1\n"; +foreach ($mandatoryFields as $mf) +{ + $z = $a[0]->$mf; + echo "$mf is $z\n"; +} + +// Calling imap_fetch_overview() with mandatory arguments +echo "\n-- Mandatory arguments --\n"; +$a = imap_fetch_overview($stream_id, '1:2') ; + +//first object in array +echo "\n--> Object #1\n"; +foreach ($mandatoryFields as $mf) +{ + $z = $a[0]->$mf; + echo "$mf is $z\n"; +} + +//Second object in array +echo "\n--> Object #2\n"; +foreach ($mandatoryFields as $mf) +{ + $z = $a[1]->$mf; + echo "$mf is $z\n"; +} + +imap_close($stream_id); + +?> +===DONE=== +--CLEAN-- + +--EXPECTF-- +*** Testing imap_fetch_overview() : basic functionality *** +Create a temporary mailbox and add 2 msgs +.. mailbox '{localhost/norsh}INBOX.phpttest' created + +-- All possible arguments -- + +--> Object #1 +size is %d +uid is %d +msgno is 1 +recent is %d +flagged is 0 +answered is 0 +deleted is 0 +seen is 0 +draft is 0 + +-- Mandatory arguments -- + +--> Object #1 +size is %d +uid is %d +msgno is 1 +recent is %d +flagged is 0 +answered is 0 +deleted is 0 +seen is 0 +draft is 0 + +--> Object #2 +size is %d +uid is %d +msgno is 2 +recent is %d +flagged is 0 +answered is 0 +deleted is 0 +seen is 0 +draft is 0 +===DONE=== diff --git a/ext/imap/tests/imap_fetch_overview_error.phpt b/ext/imap/tests/imap_fetch_overview_error.phpt new file mode 100644 index 0000000000..2fc0f343c3 --- /dev/null +++ b/ext/imap/tests/imap_fetch_overview_error.phpt @@ -0,0 +1,54 @@ +--TEST-- +Test imap_fetch_overview() function : error conditions - incorrect number of args +--SKIPIF-- + +--FILE-- + +===DONE=== +--CLEAN-- + +--EXPECTF-- +*** Testing imap_fetch_overview() : error conditions *** + +-- Testing imap_fetch_overview() function with more than expected no. of arguments -- +Create a temporary mailbox and add 2 msgs +.. mailbox '{localhost/norsh}INBOX.phpttest' created + +Warning: imap_fetch_overview() expects at most 3 parameters, 4 given in %s on line %d +NULL + +-- Testing imap_fetch_overview() function with less than expected no. of arguments -- + +Warning: imap_fetch_overview() expects at least 2 parameters, 1 given in %s on line %d +NULL +===DONE=== diff --git a/ext/imap/tests/imap_fetch_overview_variation1.phpt b/ext/imap/tests/imap_fetch_overview_variation1.phpt new file mode 100644 index 0000000000..150c555617 --- /dev/null +++ b/ext/imap/tests/imap_fetch_overview_variation1.phpt @@ -0,0 +1,221 @@ +--TEST-- +Test imap_fetch_overview() function : usage variations - diff data types as $stream_id arg +--SKIPIF-- + +--FILE-- + +===DONE=== +--EXPECTF-- +*** Testing imap_fetch_overview() : usage variations *** + +-- Testing with first argument value: int(0) + +Warning: imap_fetch_overview() expects parameter 1 to be resource, integer given in %s on line %d +NULL + +-- Testing with first argument value: int(1) + +Warning: imap_fetch_overview() expects parameter 1 to be resource, integer given in %s on line %d +NULL + +-- Testing with first argument value: int(12345) + +Warning: imap_fetch_overview() expects parameter 1 to be resource, integer given in %s on line %d +NULL + +-- Testing with first argument value: int(-2345) + +Warning: imap_fetch_overview() expects parameter 1 to be resource, integer given in %s on line %d +NULL + +-- Testing with first argument value: float(10.5) + +Warning: imap_fetch_overview() expects parameter 1 to be resource, double given in %s on line %d +NULL + +-- Testing with first argument value: float(-10.5) + +Warning: imap_fetch_overview() expects parameter 1 to be resource, double given in %s on line %d +NULL + +-- Testing with first argument value: float(123456789000) + +Warning: imap_fetch_overview() expects parameter 1 to be resource, double given in %s on line %d +NULL + +-- Testing with first argument value: float(1.23456789E-9) + +Warning: imap_fetch_overview() expects parameter 1 to be resource, double given in %s on line %d +NULL + +-- Testing with first argument value: float(0.5) + +Warning: imap_fetch_overview() expects parameter 1 to be resource, double given in %s on line %d +NULL + +-- Testing with first argument value: NULL + +Warning: imap_fetch_overview() expects parameter 1 to be resource, null given in %s on line %d +NULL + +-- Testing with first argument value: NULL + +Warning: imap_fetch_overview() expects parameter 1 to be resource, null given in %s on line %d +NULL + +-- Testing with first argument value: bool(true) + +Warning: imap_fetch_overview() expects parameter 1 to be resource, boolean given in %s on line %d +NULL + +-- Testing with first argument value: bool(false) + +Warning: imap_fetch_overview() expects parameter 1 to be resource, boolean given in %s on line %d +NULL + +-- Testing with first argument value: bool(true) + +Warning: imap_fetch_overview() expects parameter 1 to be resource, boolean given in %s on line %d +NULL + +-- Testing with first argument value: bool(false) + +Warning: imap_fetch_overview() expects parameter 1 to be resource, boolean given in %s on line %d +NULL + +-- Testing with first argument value: %string|unicode%(0) "" + +Warning: imap_fetch_overview() expects parameter 1 to be resource, %unicode_string_optional% given in %s on line %d +NULL + +-- Testing with first argument value: %string|unicode%(0) "" + +Warning: imap_fetch_overview() expects parameter 1 to be resource, %unicode_string_optional% given in %s on line %d +NULL + +-- Testing with first argument value: array(0) { +} + +Warning: imap_fetch_overview() expects parameter 1 to be resource, array given in %s on line %d +NULL + +-- Testing with first argument value: %string|unicode%(6) "string" + +Warning: imap_fetch_overview() expects parameter 1 to be resource, %unicode_string_optional% given in %s on line %d +NULL + +-- Testing with first argument value: %string|unicode%(6) "string" + +Warning: imap_fetch_overview() expects parameter 1 to be resource, %unicode_string_optional% given in %s on line %d +NULL + +-- Testing with first argument value: %string|unicode%(11) "hello world" + +Warning: imap_fetch_overview() expects parameter 1 to be resource, %unicode_string_optional% given in %s on line %d +NULL + +-- Testing with first argument value: object(classA)#1 (0) { +} + +Warning: imap_fetch_overview() expects parameter 1 to be resource, object given in %s on line %d +NULL + +-- Testing with first argument value: NULL + +Warning: imap_fetch_overview() expects parameter 1 to be resource, null given in %s on line %d +NULL + +-- Testing with first argument value: NULL + +Warning: imap_fetch_overview() expects parameter 1 to be resource, null given in %s on line %d +NULL +===DONE=== diff --git a/ext/imap/tests/imap_fetch_overview_variation2.phpt b/ext/imap/tests/imap_fetch_overview_variation2.phpt new file mode 100644 index 0000000000..0b341587cc --- /dev/null +++ b/ext/imap/tests/imap_fetch_overview_variation2.phpt @@ -0,0 +1,245 @@ +--TEST-- +Test imap_fetch_overview() function : usage variations - diff data types as $msg_no arg +--SKIPIF-- + +--FILE-- +>> 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*/ "", + '', + array(), + + // string data +/*19*/ "string", + 'string', + $heredoc, + + // object data +/*22*/ new classA(), + + // undefined data +/*23*/ @$undefined_var, + + // unset data +/*24*/ @$unset_var, + + // resource variable +/*25*/ $fp +); + +// loop through each element of $inputs to check the behavior of imap_fetch_overview() +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Testing with second argument value: "; + var_dump($input); + $overview = imap_fetch_overview($stream_id, $input); + if (!$overview) { + echo imap_last_error() . "\n"; + } else { + foreach ($mandatoryFields as $mf) + { + $z = $overview[0]->$mf; + echo "$mf is $z\n"; + } + } + $iterator++; +}; + +fclose($fp); + +// clear the error stack +imap_errors(); +?> +===DONE=== +--CLEAN-- + +--EXPECTF-- +*** Testing imap_fetch_overview() : usage variations *** +Create a temporary mailbox and add 1 msgs +.. mailbox '{localhost/norsh}INBOX.phpttest' created + +-- Testing with second argument value: int(0) +Sequence out of range + +-- Testing with second argument value: int(1) +size is %d +uid is %d +msgno is 1 +recent is %d +flagged is 0 +answered is 0 +deleted is 0 +seen is 0 +draft is 0 + +-- Testing with second argument value: int(12345) +Sequence out of range + +-- Testing with second argument value: int(-2345) +Syntax error in sequence + +-- Testing with second argument value: float(10.5) +Sequence out of range + +-- Testing with second argument value: float(-10.5) +Syntax error in sequence + +-- Testing with second argument value: float(123456789000) +Sequence out of range + +-- Testing with second argument value: float(1.23456789E-9) +Sequence syntax error + +-- Testing with second argument value: float(0.5) +Sequence out of range + +-- Testing with second argument value: NULL +Sequence out of range + +-- Testing with second argument value: NULL +Sequence out of range + +-- Testing with second argument value: bool(true) +size is %d +uid is %d +msgno is 1 +recent is %d +flagged is 0 +answered is 0 +deleted is 0 +seen is 0 +draft is 0 + +-- Testing with second argument value: bool(false) +Sequence out of range + +-- Testing with second argument value: bool(true) +size is %d +uid is %d +msgno is 1 +recent is %d +flagged is 0 +answered is 0 +deleted is 0 +seen is 0 +draft is 0 + +-- Testing with second argument value: bool(false) +Sequence out of range + +-- Testing with second argument value: %string|unicode%(0) "" +Sequence out of range + +-- Testing with second argument value: %string|unicode%(0) "" +Sequence out of range + +-- Testing with second argument value: array(0) { +} + +Warning: imap_fetch_overview() expects parameter 2 to be %binary_string_optional%, array given in %s on line %d +Sequence out of range + +-- Testing with second argument value: %string|unicode%(6) "string" +Syntax error in sequence + +-- Testing with second argument value: %string|unicode%(6) "string" +Syntax error in sequence + +-- Testing with second argument value: %string|unicode%(11) "hello world" +Syntax error in sequence + +-- Testing with second argument value: object(classA)#1 (0) { +} +Syntax error in sequence + +-- Testing with second argument value: NULL +Syntax error in sequence + +-- Testing with second argument value: NULL +Syntax error in sequence + +-- Testing with second argument value: resource(7) of type (stream) + +Warning: imap_fetch_overview() expects parameter 2 to be %binary_string_optional%, resource given in %s on line %d +Syntax error in sequence +===DONE=== diff --git a/ext/imap/tests/imap_fetch_overview_variation3.phpt b/ext/imap/tests/imap_fetch_overview_variation3.phpt new file mode 100644 index 0000000000..5fa56b5f76 --- /dev/null +++ b/ext/imap/tests/imap_fetch_overview_variation3.phpt @@ -0,0 +1,80 @@ +--TEST-- +Test imap_fetch_overview() function : usage variations - FT_UID option +--SKIPIF-- + +--FILE-- + +===DONE=== +--CLEAN-- + +--EXPECTF-- +*** Testing imap_fetch_overview() : usage variations *** +Create a temporary mailbox and add 1 msgs +.. mailbox '{localhost/norsh}INBOX.phpttest' created + +Testing with option value:%string|unicode%(1) "1" +imap_fetch_overview() returns an object + +Testing with option value:bool(true) +imap_fetch_overview() returns an object + +Testing with option value:float(1) +imap_fetch_overview() returns an object + +Testing with option value:float(1) +imap_fetch_overview() returns an object + +Testing with option value:int(%d) + +Warning: imap_fetch_overview(): invalid value for the options parameter in %s on line %d + +Testing with option value:int(-%d) + +Warning: imap_fetch_overview(): invalid value for the options parameter in %s on line %d +===DONE=== diff --git a/ext/imap/tests/imap_fetch_overview_variation4.phpt b/ext/imap/tests/imap_fetch_overview_variation4.phpt new file mode 100644 index 0000000000..a5c2666310 --- /dev/null +++ b/ext/imap/tests/imap_fetch_overview_variation4.phpt @@ -0,0 +1,46 @@ +--TEST-- +Test imap_fetch_overview() function : usage variations - different resources as $stream_id +--SKIPIF-- + +--FILE-- + +===DONE=== +--EXPECTF-- +*** Testing imap_fetch_overview() : usage variations *** + +-- File Resource opened with fopen() -- +resource(%d) of type (stream) + +Warning: imap_fetch_overview(): 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_fetch_overview(): supplied resource is not a valid imap resource in %s on line %d +bool(false) +===DONE=== diff --git a/ext/imap/tests/imap_fetch_overview_variation5.phpt b/ext/imap/tests/imap_fetch_overview_variation5.phpt new file mode 100644 index 0000000000..79861be7a2 --- /dev/null +++ b/ext/imap/tests/imap_fetch_overview_variation5.phpt @@ -0,0 +1,149 @@ +--TEST-- +Test imap_fetch_overview() function : usage variations - $msg_no argument +--SKIPIF-- + +--FILE-- +$mf; + echo "$mf is $z\n"; + } + } + } +} + +// clear error stack +imap_errors(); +?> +===DONE=== +--CLEAN-- + +--EXPECTF-- +*** Testing imap_fetch_overview() : usage variations *** +Create a temporary mailbox and add 3 msgs +.. mailbox '{localhost/norsh}INBOX.phpttest' created + +-- $msg_no is 0 -- +Sequence out of range + +-- $msg_no is 4 -- +Sequence out of range + +-- $msg_no is 4 -- +Sequence out of range + +-- $msg_no is 2 -- + +size is %d +uid is %d +msgno is 2 +recent is %d +flagged is 0 +answered is 0 +deleted is 0 +seen is 0 +draft is 0 + +-- $msg_no is 1,3 -- + +size is %d +uid is %d +msgno is 1 +recent is %d +flagged is 0 +answered is 0 +deleted is 0 +seen is 0 +draft is 0 + +size is %d +uid is %d +msgno is 3 +recent is %d +flagged is 0 +answered is 0 +deleted is 0 +seen is 0 +draft is 0 + +-- $msg_no is 1, 2 -- +Syntax error in sequence + +-- $msg_no is 1:3 -- + +size is %d +uid is %d +msgno is 1 +recent is %d +flagged is 0 +answered is 0 +deleted is 0 +seen is 0 +draft is 0 + +size is %d +uid is %d +msgno is 2 +recent is %d +flagged is 0 +answered is 0 +deleted is 0 +seen is 0 +draft is 0 + +size is %d +uid is %d +msgno is 3 +recent is %d +flagged is 0 +answered is 0 +deleted is 0 +seen is 0 +draft is 0 +===DONE=== diff --git a/ext/imap/tests/imap_fetch_overview_variation6.phpt b/ext/imap/tests/imap_fetch_overview_variation6.phpt new file mode 100644 index 0000000000..fda937e243 --- /dev/null +++ b/ext/imap/tests/imap_fetch_overview_variation6.phpt @@ -0,0 +1,125 @@ +--TEST-- +Test imap_fetch_overview() function : usage variations - multipart message +--SKIPIF-- + +--FILE-- + Object #1\n"; +foreach ($mandatoryFields as $mf) +{ + $z = $a[0]->$mf; + echo "$mf is $z\n"; +} + + + + +/** + * Create a multipart message with subparts + * + * @param resource $imap_stream + * @param string $mailbox + */ +function create_multipart_message($imap_stream, $mailbox) { + global $users, $domain; + $envelope["from"]= "foo@anywhere.com"; + $envelope["to"] = "$users[0]@$domain"; + $envelope["subject"] = "Test msg 1"; + + $part1["type"] = TYPEMULTIPART; + $part1["subtype"] = "mixed"; + + $part2["type"] = TYPETEXT; + $part2["subtype"] = "plain"; + $part2["description"] = "imap_mail_compose() function"; + $part2["contents.data"] = "message 1:xxxxxxxxxxxxxxxxxxxxxxxxxx"; + + $part3["type"] = TYPETEXT; + $part3["subtype"] = "plain"; + $part3["description"] = "Example"; + $part3["contents.data"] = "message 2:yyyyyyyyyyyyyyyyyyyyyyyyyy"; + + $file_handle = fopen(__FILE__, 'r+'); + $file_size = 1; + + $part4["type"] = TYPEAPPLICATION; + $part4["encoding"] = ENCBASE64; + $part4["subtype"] = "octet-stream"; + $part4["description"] = 'Test'; + $part4['disposition.type'] = 'attachment'; + $part4['disposition'] = array ('filename' => 'Test'); + $part4['type.parameters'] = array('name' => 'Test'); + $part4["contents.data"] = base64_encode(fread($file_handle, 1)); + + $body[1] = $part1; + $body[2] = $part2; + $body[3] = $part3; + $body[4] = $part4; + + $msg = imap_mail_compose($envelope, $body); + + if (imap_append($imap_stream, $mailbox, $msg) === false) { + echo imap_last_error() . "\n"; + echo "TEST FAILED : could not append new message to mailbox '$mailbox'\n"; + exit; + } +} + +?> +===DONE=== +--CLEAN-- + +--EXPECTF-- +*** Testing imap_fetch_overview() : usage variations *** +Create a temporary mailbox and add 0 msgs +.. mailbox '{localhost/norsh}INBOX.phpttest' created + +--> Object #1 +size is %d +uid is %d +msgno is 1 +recent is %d +flagged is 0 +answered is 0 +deleted is 0 +seen is 0 +draft is 0 +===DONE===