From: Zoe Slattery Date: Fri, 28 Nov 2008 17:41:03 +0000 (+0000) Subject: Committing include files required for tests. Tests and bug reports to follow. X-Git-Tag: php-5.2.8~31 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b51bb4132faf9a0f2e1d32fc72edd19227aedae2;p=php Committing include files required for tests. Tests and bug reports to follow. --- diff --git a/ext/imap/tests/clean.inc b/ext/imap/tests/clean.inc new file mode 100644 index 0000000000..f5e869ff07 --- /dev/null +++ b/ext/imap/tests/clean.inc @@ -0,0 +1,25 @@ +Nmsgs; $i++) { + imap_delete($imap_stream, $i); +} + +$mailboxes = imap_getmailboxes($imap_stream, $server, '*'); + +foreach($mailboxes as $value) { + // Only delete mailboxes with our prefix + if (preg_match('/\{.*?\}INBOX\.(.+)/', $value->name, $match) == 1) { + if (strlen($match[1]) >= strlen($mailbox_prefix) + && substr_compare($match[1], $mailbox_prefix, 0, strlen($mailbox_prefix)) == 0) { + imap_deletemailbox($imap_stream, $value->name); + } + } +} + +imap_close($imap_stream, CL_EXPUNGE); +?> \ No newline at end of file diff --git a/ext/imap/tests/imap_include.inc b/ext/imap/tests/imap_include.inc new file mode 100644 index 0000000000..a93187871d --- /dev/null +++ b/ext/imap/tests/imap_include.inc @@ -0,0 +1,150 @@ +name == $mailbox) { + exit ("TEST FAILED : Mailbox '$mailbox' already exists\n"); + } + } + } + + if (imap_createmailbox($imap_stream, $mailbox) === false) { + return false; + } + + // Add number of test msgs requested + if ($message_count > 0) { + populate_mailbox($imap_stream, $mailbox, $message_count, $msg_type); + } + + return $mailbox; +} + +/** + * Populate a mailbox with generic emails + * + * @param resource $imap_stream + * @param string $mailbox + */ +function populate_mailbox($imap_stream, $mailbox, $message_count, $msg_type = "simple"){ + + global $users, $domain; + + for($i = 1; $i <= $message_count; $i++) { + if ($msg_type == "simple") { + $msg = "From: foo@anywhere.com\r\n" + . "To: $users[0]@$domain\r\n" + . "Subject: test$i\r\n" + . "\r\n" + . "$i: this is a test message, please ignore\r\n"; + } else { + $envelope["from"]= "foo@anywhere.com"; + $envelope["to"] = "$users[0]@$domain"; + $envelope["subject"] = "Test msg $i"; + + $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"; + + $part4["type"] = TYPETEXT; + $part4["subtype"] = "plain"; + $part4["description"] = "Return Values"; + $part4["contents.data"] = "message 3:zzzzzzzzzzzzzzzzzzzzzzzzzz"; + + $body[1] = $part1; + $body[2] = $part2; + $body[3] = $part3; + $body[4] = $part4; + + $msg = imap_mail_compose($envelope, $body); + } + + imap_append($imap_stream, $mailbox, $msg); + } +} + +/** + * Get the mailbox name from a mailbox decription, i.e strip off server details. + * + * @param string mailbox complete mailbox name + * @return mailbox name + */ +function get_mailbox_name($mailbox){ + + if (preg_match('/\{.*?\}(.*)/', $mailbox, $match) != 1) { + echo "Unrecpognized mailbox name\n"; + return false; + } + + return $match[1]; +} + +?> \ No newline at end of file diff --git a/ext/imap/tests/skipif.inc b/ext/imap/tests/skipif.inc new file mode 100644 index 0000000000..d01fcd986f --- /dev/null +++ b/ext/imap/tests/skipif.inc @@ -0,0 +1,16 @@ + \ No newline at end of file