diff options
Diffstat (limited to 'ext/imap/tests')
73 files changed, 478 insertions, 1567 deletions
diff --git a/ext/imap/tests/CONFLICTS b/ext/imap/tests/CONFLICTS new file mode 100644 index 0000000000..c301c0ffac --- /dev/null +++ b/ext/imap/tests/CONFLICTS @@ -0,0 +1 @@ +imap diff --git a/ext/imap/tests/README.md b/ext/imap/tests/README.md index 381cdc2e8e..6324ab7f9e 100644 --- a/ext/imap/tests/README.md +++ b/ext/imap/tests/README.md @@ -9,40 +9,16 @@ files will need to be changed to match the local mailserver configuration. The tests have been checked using dovecot (on Linux 32 and 64 bit systems) and hMailServer on Windows. The tests are intended to be mailserver agnostic. -The tests can be run without modification with a fairly minimal dovecot -installation. For information, the dovecot.conf file used in running the tests -is given below. The dovecot password file (dovecotpass) requires a password for -one user, `webmaster@something.com`. It's also necessary to set up one -additional user ID (vmail) to own the mail directory. +## Set-up tests on Ubuntu (checked on Ubuntu 18.04 (Bionic)) +The necessary packages can be installed using the following command; +`apt-get install libc-client-dev libkrb5-dev dovecot-core dovecot-pop3d dovecot-imapd` -```txt -protocols = imap imaps - -listen = * - -ssl_disable = yes - -disable_plaintext_auth=yes - -## Mailbox locations and namespaces - -mail_location = maildir:/home/vmail/mail/%d/%n/Maildir - -auth_verbose = yes - -auth_debug = yes - -auth default { - mechanisms = login - - passdb passwd-file { - args = /etc/dovecot/dovecotpass - } - - userdb static { - args = uid=11459 gid=1002 home=/home/vmail/dovecot/mail/%d/%n - } - - user = root -} +The build of PHP will need to be compiled with the following flags: +``` +--with-imap --with-kerberos --with-imap-ssl ``` + +Then run the set-up script `ext/imap/tests/setup.sh` which will add the `vmail` +group and user which is used by Dovecot for the mailbox. It will also copy the +`ext/imap/tests/dovecot.conf` and `ext/imap/tests/dovecotpass` to the correct +location for Dovecot and restarts it for the new configuration to be enabled. diff --git a/ext/imap/tests/bug35669.phpt b/ext/imap/tests/bug35669.phpt index 1f8ca5d7c3..fc7a135bce 100644 --- a/ext/imap/tests/bug35669.phpt +++ b/ext/imap/tests/bug35669.phpt @@ -8,7 +8,7 @@ Bug #35669 (imap_mail_compose() crashes with multipart-multiboundary-email) ?> --FILE-- <?php - $envelope["from"] = 'Santa <somewhere@northpole.gov>'; + $envelope["from"] = 'Santa <somewhere@northpole.gov>'; $envelope["to"] = 'The bad smurf <bad@smurf.com>'; $envelope['date'] = 'Wed, 04 Jan 2006 19:24:43 -0500'; diff --git a/ext/imap/tests/bug44098.phpt b/ext/imap/tests/bug44098.phpt index c424f05f54..2a0f5cef44 100644 --- a/ext/imap/tests/bug44098.phpt +++ b/ext/imap/tests/bug44098.phpt @@ -11,9 +11,9 @@ Bug #44098 (imap_utf8() returns only capital letters) $exp = 'Luzon®14 dot CoM'; $res = imap_utf8('=?iso-8859-1?b?THV6b26uMTQ=?= dot CoM'); if ($res != $exp) { - echo "failed: got <$res>, expected <exp>\n"; + echo "failed: got <$res>, expected <exp>\n"; } else { - echo "ok"; + echo "ok"; } ?> --EXPECT-- diff --git a/ext/imap/tests/bug45705_1.phpt b/ext/imap/tests/bug45705_1.phpt index f699451407..05d3a0a2f6 100644 --- a/ext/imap/tests/bug45705_1.phpt +++ b/ext/imap/tests/bug45705_1.phpt @@ -2,9 +2,9 @@ Bug #45705 test #1 (imap rfc822_parse_adrlist() modifies passed address parameter) --SKIPIF-- <?php - if (!extension_loaded("imap")) { - die("skip imap extension not available"); - } + if (!extension_loaded("imap")) { + die("skip imap extension not available"); + } ?> --FILE-- <?php diff --git a/ext/imap/tests/bug45705_2.phpt b/ext/imap/tests/bug45705_2.phpt index b8c1c295ae..3de50290f7 100644 --- a/ext/imap/tests/bug45705_2.phpt +++ b/ext/imap/tests/bug45705_2.phpt @@ -2,9 +2,9 @@ Bug #45705 test #2 (imap rfc822_parse_adrlist() modifies passed address parameter) --SKIPIF-- <?php - if (!extension_loaded("imap")) { - die("skip imap extension not available"); - } + if (!extension_loaded("imap")) { + die("skip imap extension not available"); + } ?> --FILE-- <?php diff --git a/ext/imap/tests/bug53377.phpt b/ext/imap/tests/bug53377.phpt index dfe2d032ab..a507369046 100644 --- a/ext/imap/tests/bug53377.phpt +++ b/ext/imap/tests/bug53377.phpt @@ -12,6 +12,7 @@ $s = "=?UTF-8?Q?=E2=82=AC?="; $header = "$s\n $s\n\t$s"; var_dump(imap_mime_header_decode($header)); +?> --EXPECT-- array(3) { [0]=> diff --git a/ext/imap/tests/bug63126.phpt b/ext/imap/tests/bug63126.phpt index 94c618730c..8eea34cf1d 100644 --- a/ext/imap/tests/bug63126.phpt +++ b/ext/imap/tests/bug63126.phpt @@ -6,7 +6,7 @@ extension_loaded('imap') or die('skip imap extension not available in this build require_once(__DIR__.'/imap_include.inc'); -$in = imap_open($default_mailbox, $username, $password, OP_HALFOPEN, 1); +$in = @imap_open($default_mailbox, $username, $password, OP_HALFOPEN, 1); if (!$in) { die("skip could not connect to mailbox $default_mailbox"); } diff --git a/ext/imap/tests/bug75774.phpt b/ext/imap/tests/bug75774.phpt index ba08ab0439..08883ad8f0 100644 --- a/ext/imap/tests/bug75774.phpt +++ b/ext/imap/tests/bug75774.phpt @@ -8,17 +8,18 @@ extension_loaded('imap') or die('skip imap extension not available in this build <?php $fn = __DIR__ . DIRECTORY_SEPARATOR . "foo75774"; -$var1=fopen($fn, "w"); +$var1 = fopen($fn, "w"); -imap_append($var1, "", "", "", ""); +try { + imap_append($var1, "", "", "", ""); +} catch (\TypeError $e) { + echo $e->getMessage() . "\n"; +} fclose($var1); unlink($fn); ?> -==DONE== --EXPECTF-- -Warning: imap_append(): internal date not correctly formatted in %s on line %d - -Warning: imap_append(): supplied resource is not a valid imap resource in %s on line %d -==DONE== +Warning: imap_append(): Internal date not correctly formatted in %s on line %d +imap_append(): supplied resource is not a valid imap resource diff --git a/ext/imap/tests/bug77020.phpt b/ext/imap/tests/bug77020.phpt index 357b75333a..582b132ad8 100644 --- a/ext/imap/tests/bug77020.phpt +++ b/ext/imap/tests/bug77020.phpt @@ -8,8 +8,6 @@ if (!extension_loaded('imap')) die('skip imap extension not available'); <?php imap_mail('1', 1, NULL); ?> -===DONE=== --EXPECTF-- Warning: imap_mail(): No message string in mail command in %s on line %d %A -===DONE=== diff --git a/ext/imap/tests/bug77153.phpt b/ext/imap/tests/bug77153.phpt index 63590aee1d..7b759621fe 100644 --- a/ext/imap/tests/bug77153.phpt +++ b/ext/imap/tests/bug77153.phpt @@ -2,8 +2,8 @@ Bug #77153 (imap_open allows to run arbitrary shell commands via mailbox parameter) --SKIPIF-- <?php - if (!extension_loaded("imap")) { - die("skip imap extension not available"); + if (!extension_loaded("imap")) { + die("skip imap extension not available"); } ?> --FILE-- diff --git a/ext/imap/tests/clean.inc b/ext/imap/tests/clean.inc index 4f381bf893..8bc566ba32 100644 --- a/ext/imap/tests/clean.inc +++ b/ext/imap/tests/clean.inc @@ -6,19 +6,19 @@ $imap_stream = imap_open($default_mailbox, $username, $password); // delete all msgs in default mailbox, i.e INBOX $check = imap_check($imap_stream); for ($i = 1; $i <= $check->Nmsgs; $i++) { - imap_delete($imap_stream, $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); - } - } + // 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); diff --git a/ext/imap/tests/dovecot.conf b/ext/imap/tests/dovecot.conf new file mode 100644 index 0000000000..c465ba3ce9 --- /dev/null +++ b/ext/imap/tests/dovecot.conf @@ -0,0 +1,33 @@ +# 2.2.33.2 (d6601f4ec): /etc/dovecot/dovecot.conf +# Pigeonhole version 0.4.21 (92477967) +listen = *, :: + +# To make authentication work +ssl = no +disable_plaintext_auth = no + +auth_mechanisms = plain cram-md5 +auth_username_format = %u +auth_debug = yes +auth_verbose = yes +#log +log_path = /var/log/dovecot.log +# If not set, use the value from log_path +info_log_path = /var/log/dovecot-info.log +# If not set, use the value from info_log_path +debug_log_path = /var/log/dovecot-debug.log +## Mailbox locations and namespaces +mail_location = maildir:/var/vmail/dovecot/mail/%d/%n/Maildir +passdb { + args = scheme=cram-md5 /etc/dovecot/dovecotpass + driver = passwd-file +} +protocols = imap +service auth { + user = root +} +userdb { + args = /etc/dovecot/dovecotpass + driver = passwd-file + override_fields = home=/var/vmail/dovecot/mail/%d/%n +} diff --git a/ext/imap/tests/dovecotpass b/ext/imap/tests/dovecotpass new file mode 100644 index 0000000000..86a069fc4f --- /dev/null +++ b/ext/imap/tests/dovecotpass @@ -0,0 +1 @@ +webmaster@something.com:{CRAM-MD5}be5f3177e9c7c06403272f25d983ba630df4ef40476b353bb3087a8401713451:vmail:vmail diff --git a/ext/imap/tests/imap_8bit_basic.phpt b/ext/imap/tests/imap_8bit_basic.phpt index 799889bb3d..d874b76733 100644 --- a/ext/imap/tests/imap_8bit_basic.phpt +++ b/ext/imap/tests/imap_8bit_basic.phpt @@ -6,11 +6,6 @@ extension_loaded('imap') or die('skip imap extension not available in this build ?> --FILE-- <?php -/* Prototype : string imap_8bit ( string $string ) - * Description: Convert an 8bit string to a quoted-printable string. - * Source code: ext/imap/php_imap.c - */ - echo "*** Testing imap_8bit() : basic functionality ***\n"; var_dump(imap_8bit("String with CRLF at end \r\n")); @@ -21,7 +16,6 @@ var_dump(imap_8bit("String with tab at end \t")); var_dump(imap_8bit("\x00\x01\x02\x03\x04\xfe\xff\x0a\x0d")); ?> -===Done=== --EXPECT-- *** Testing imap_8bit() : basic functionality *** string(28) "String with CRLF at end=20 @@ -30,4 +24,3 @@ string(25) "String with space at end " string(33) "String with tabs =09=09 in middle" string(26) "String with tab at end =09" string(27) "=00=01=02=03=04=FE=FF=0A=0D" -===Done=== diff --git a/ext/imap/tests/imap_alerts_error.phpt b/ext/imap/tests/imap_alerts_error.phpt deleted file mode 100644 index 546d193c8f..0000000000 --- a/ext/imap/tests/imap_alerts_error.phpt +++ /dev/null @@ -1,31 +0,0 @@ ---TEST-- -Test imap_alerts() function : error conditions ---SKIPIF-- -<?php -require_once(__DIR__.'/skipif.inc'); -?> ---FILE-- -<?php -/* Prototype : array imap_alerts(void) - * Description: Returns an array of all IMAP alerts that have been generated since the last page load or since the last imap_alerts() call, whichever came last. The alert stack is cleared after imap_alerts() is called. - * Source code: ext/imap/php_imap.c - * Alias to functions: - */ - -echo "*** Testing imap_alerts() : error conditions ***\n"; - -// One argument -echo "\n-- Testing imap_alerts() function with one argument --\n"; -$extra_arg = 10; -var_dump( imap_alerts($extra_arg) ); - -?> -===DONE=== ---EXPECTF-- -*** Testing imap_alerts() : error conditions *** - --- Testing imap_alerts() function with one argument -- - -Warning: imap_alerts() expects exactly 0 parameters, 1 given in %s on line %d -NULL -===DONE=== diff --git a/ext/imap/tests/imap_append_basic.phpt b/ext/imap/tests/imap_append_basic.phpt index 500d3afb69..e75b452596 100644 --- a/ext/imap/tests/imap_append_basic.phpt +++ b/ext/imap/tests/imap_append_basic.phpt @@ -6,11 +6,6 @@ require_once(__DIR__.'/skipif.inc'); ?> --FILE-- <?php -/* Prototype : bool imap_append ( resource $imap_stream , string $mailbox , string $message [, string $options ] ) - * Description: Append a string message to a specified mailbox. - * Source code: ext/imap/php_imap.c - */ - echo "*** Testing imap_append() : basic functionality ***\n"; require_once(__DIR__.'/imap_include.inc'); @@ -18,7 +13,7 @@ require_once(__DIR__.'/imap_include.inc'); echo "Create a new mailbox for test\n"; $imap_stream = setup_test_mailbox("", 0); if (!is_resource($imap_stream)) { - exit("TEST FAILED: Unable to create test mailbox\n"); + exit("TEST FAILED: Unable to create test mailbox\n"); } $mb_details = imap_mailboxmsginfo($imap_stream); @@ -47,7 +42,6 @@ var_dump(imap_headers($imap_stream)); imap_close($imap_stream); ?> -===Done=== --CLEAN-- <?php require_once('clean.inc'); @@ -68,4 +62,3 @@ array(2) { [1]=> string(%d) "%w%s 2)%s webmaster@something. Another test (%d chars)" } -===Done=== diff --git a/ext/imap/tests/imap_base64_basic.phpt b/ext/imap/tests/imap_base64_basic.phpt index 3557e9f87e..3345aa35a6 100644 --- a/ext/imap/tests/imap_base64_basic.phpt +++ b/ext/imap/tests/imap_base64_basic.phpt @@ -6,42 +6,35 @@ extension_loaded('imap') or die('skip imap extension not available in this build ?> --FILE-- <?php -/* Prototype : string imap_base64 ( string $text ) - * Description: Decode BASE64 encoded text. - * Source code: ext/imap/php_imap.c - */ - echo "*** Testing imap_base64() : basic functionality ***\n"; $str = 'This is an example string to be base 64 encoded'; $base64 = base64_encode($str); if (imap_base64($base64) == $str) { - echo "TEST PASSED\n"; + echo "TEST PASSED\n"; } else { - echo "TEST FAILED"; + echo "TEST FAILED"; } $str = '!£$%^&*()_+-={][];;@~#?/>.<,'; $base64 = base64_encode($str); if (imap_base64($base64) == $str) { - echo "TEST PASSED\n"; + echo "TEST PASSED\n"; } else { - echo "TEST FAILED"; + echo "TEST FAILED"; } $hex = 'x00\x01\x02\x03\x04\x05\x06\xFA\xFB\xFC\xFD\xFE\xFF'; $base64 = base64_encode($hex); if (imap_base64($base64) == $hex) { - echo "TEST PASSED\n"; + echo "TEST PASSED\n"; } else { - echo "TEST FAILED"; + echo "TEST FAILED"; } ?> -===Done=== --EXPECT-- *** Testing imap_base64() : basic functionality *** TEST PASSED TEST PASSED TEST PASSED -===Done=== diff --git a/ext/imap/tests/imap_binary_basic.phpt b/ext/imap/tests/imap_binary_basic.phpt index 04f85386bc..9df2cdddf6 100644 --- a/ext/imap/tests/imap_binary_basic.phpt +++ b/ext/imap/tests/imap_binary_basic.phpt @@ -6,11 +6,6 @@ extension_loaded('imap') or die('skip imap extension not available in this build ?> --FILE-- <?php -/* Prototype : string imap_binary ( string $string ) - * Description: Convert an 8bit string to a base64 string. - * Source code: ext/imap/php_imap.c - */ - echo "*** Testing imap_binary() : basic functionality ***\n"; echo "Encode as short string\n"; @@ -34,8 +29,7 @@ $base64 = imap_binary($hex); var_dump(bin2hex($base64)); ?> -===Done=== ---EXPECTF-- +--EXPECT-- *** Testing imap_binary() : basic functionality *** Encode as short string string(136) "5647687063794270637942686269426c654746746347786c49484e30636d6c755a794230627942695a53426959584e6c49445930494756755932396b0d0a5a57513d0d0a" @@ -45,4 +39,3 @@ Encode a string with special characters string(60) "5879737450587464573130374f30422b497a3876506934384c413d3d0d0a" Encode some hexadecimal data string(144) "65444177584867774d5678344d444a636544417a584867774e4678344d445663654441325848684751567834526b4a6365455a4458486847524678340d0a526b566365455a470d0a" -===Done=== diff --git a/ext/imap/tests/imap_body.phpt b/ext/imap/tests/imap_body.phpt index a9b3bcd6e5..6c2f629398 100644 --- a/ext/imap/tests/imap_body.phpt +++ b/ext/imap/tests/imap_body.phpt @@ -1,5 +1,5 @@ --TEST-- -imap_body() incorrect parameter count +imap_body() ValueError --CREDITS-- Paul Sohier #phptestfest utrecht @@ -9,40 +9,31 @@ require_once(__DIR__.'/skipif.inc'); ?> --FILE-- <?php -echo "Checking with no parameters\n"; -imap_body(); -echo "Checking with incorrect parameter type\n"; -imap_body(''); -imap_body(false); require_once(__DIR__.'/imap_include.inc'); $stream_id = imap_open($default_mailbox, $username, $password) or - die("Cannot connect to mailbox $default_mailbox: " . imap_last_error()); -imap_body($stream_id); -imap_body($stream_id,-1); -imap_body($stream_id,1,-1); + die("Cannot connect to mailbox $default_mailbox: " . imap_last_error()); + +try { + imap_body($stream_id,-1); +} catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; +} +try { + imap_body($stream_id,1,-1); +} catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; +} //Access not existing -var_dump(imap_body($stream_id, 999, FT_UID)); +var_dump(imap_body($stream_id, 255, FT_UID)); imap_close($stream_id); ?> --EXPECTF-- -Checking with no parameters +imap_body(): Argument #2 ($message_num) must be greater than 0 +imap_body(): Argument #3 ($flags) must be a bitmask of FT_UID, FT_PEEK, and FT_INTERNAL -Warning: imap_body() expects at least 2 parameters, 0 given in %s on line %d -Checking with incorrect parameter type - -Warning: imap_body() expects at least 2 parameters, 1 given in %s on line %d - -Warning: imap_body() expects at least 2 parameters, 1 given in %s on line %d - -Warning: imap_body() expects at least 2 parameters, 1 given in %s on line %d - -Warning: imap_body(): Bad message number in %s on line %d - -Warning: imap_body(): invalid value for the options parameter in %s on line %d - -Warning: imap_body(): Bad message number in %s on line %d +Warning: imap_body(): UID does not exist in %s on line %d bool(false) diff --git a/ext/imap/tests/imap_body_basic.phpt b/ext/imap/tests/imap_body_basic.phpt index bc9f789c6a..af434cffb6 100644 --- a/ext/imap/tests/imap_body_basic.phpt +++ b/ext/imap/tests/imap_body_basic.phpt @@ -6,11 +6,6 @@ require_once(__DIR__.'/skipif.inc'); ?> --FILE-- <?php -/* Prototype : string imap_body ( resource $imap_stream , int $msg_number [, int $options ] ) - * Description: Read the message body. - * Source code: ext/imap/php_imap.c - */ - echo "*** Testing imap_body() : basic functionality ***\n"; require_once(__DIR__.'/imap_include.inc'); @@ -18,7 +13,7 @@ require_once(__DIR__.'/imap_include.inc'); echo "Create a new mailbox for test\n"; $imap_stream = setup_test_mailbox("", 1); if (!is_resource($imap_stream)) { - exit("TEST FAILED: Unable to create test mailbox\n"); + exit("TEST FAILED: Unable to create test mailbox\n"); } $check = imap_check($imap_stream); @@ -32,7 +27,6 @@ var_dump(imap_body($imap_stream, 1, FT_UID)); imap_close($imap_stream); ?> -===Done=== --CLEAN-- <?php require_once('clean.inc'); @@ -45,4 +39,3 @@ Create a temporary mailbox and add 1 msgs Msg Count in new mailbox: 1 string(%d) "1: this is a test message, please ignore%a" string(%d) "1: this is a test message, please ignore%a" -===Done=== diff --git a/ext/imap/tests/imap_bodystruct_basic.phpt b/ext/imap/tests/imap_bodystruct_basic.phpt index 07b552de96..56c88399c3 100644 --- a/ext/imap/tests/imap_bodystruct_basic.phpt +++ b/ext/imap/tests/imap_bodystruct_basic.phpt @@ -6,18 +6,13 @@ require_once(__DIR__.'/skipif.inc'); ?> --FILE-- <?php -/* Prototype : object imap_bodystruct ( resource $imap_stream , int $msg_number , string $section ) - * Description: Read the structure of a specified body section of a specific message. - * Source code: ext/imap/php_imap.c - */ - echo "*** Testing string imap_bodystruct : basic functionality ***\n"; require_once(__DIR__.'/imap_include.inc'); echo "Create a new mailbox for test and add a multipart msgs\n"; $imap_stream = setup_test_mailbox("", 1, $mailbox, "multipart"); if (!is_resource($imap_stream)) { - exit("TEST FAILED: Unable to create test mailbox\n"); + exit("TEST FAILED: Unable to create test mailbox\n"); } echo "\nGet and validate structure of body part 1\n"; @@ -68,7 +63,6 @@ function isValid($param) return $result; } ?> -===Done=== --CLEAN-- <?php require_once('clean.inc'); @@ -90,4 +84,3 @@ parameters is an array Try to get part 4! bool(false) -===Done=== diff --git a/ext/imap/tests/imap_clearflag_full_basic.phpt b/ext/imap/tests/imap_clearflag_full_basic.phpt index 017ca1b71e..cc949385fc 100644 --- a/ext/imap/tests/imap_clearflag_full_basic.phpt +++ b/ext/imap/tests/imap_clearflag_full_basic.phpt @@ -6,11 +6,6 @@ require_once(__DIR__.'/skipif.inc'); ?> --FILE-- <?php -/* Prototype : bool imap_clearflag_full ( resource $imap_stream , string $sequence , string $flag [, string $options ] ) - * Description: Clears flags on messages. - * Source code: ext/imap/php_imap.c - */ - echo "*** Testing imap_clearflag_full() : basic functionality ***\n"; require_once(__DIR__.'/imap_include.inc'); @@ -18,7 +13,7 @@ require_once(__DIR__.'/imap_include.inc'); echo "Create a new mailbox for test\n"; $imap_stream = setup_test_mailbox("", 10); if (!is_resource($imap_stream)) { - exit("TEST FAILED: Unable to create test mailbox\n"); + exit("TEST FAILED: Unable to create test mailbox\n"); } $check = imap_check($imap_stream); @@ -47,7 +42,6 @@ var_dump(imap_search($imap_stream, "DELETED")); imap_close($imap_stream); ?> -===Done=== --CLEAN-- <?php require_once('clean.inc'); @@ -124,4 +118,3 @@ array(3) { int(10) } bool(false) -===Done=== diff --git a/ext/imap/tests/imap_close_basic.phpt b/ext/imap/tests/imap_close_basic.phpt index 4a3f5d683f..57b2e7eab1 100644 --- a/ext/imap/tests/imap_close_basic.phpt +++ b/ext/imap/tests/imap_close_basic.phpt @@ -6,11 +6,6 @@ require_once(__DIR__.'/skipif.inc'); ?> --FILE-- <?php -/* Prototype : bool imap_close(resource $stream_id [, int $options]) - * Description: Close an IMAP stream - * Source code: ext/imap/php_imap.c - */ - echo "*** Testing imap_close() : basic functionality ***\n"; // include file for required variables in imap_open() @@ -22,7 +17,7 @@ $options = CL_EXPUNGE; // mark messages in inbox for deletion for ($i = 1; $i < 4; $i++) { - imap_delete($stream_id, $i); + imap_delete($stream_id, $i); } // Calling imap_close() with all possible arguments @@ -37,7 +32,6 @@ echo "There are now " . imap_num_msg($stream_id) . " msgs in mailbox '$mailbox'\ echo "\n-- Call to imap_close() with mandatory arguments --\n"; var_dump( imap_close($stream_id) ); ?> -===DONE=== --CLEAN-- <?php require_once(__DIR__.'/clean.inc'); @@ -53,4 +47,3 @@ There are now 0 msgs in mailbox '%sINBOX.phpttest' -- Call to imap_close() with mandatory arguments -- bool(true) -===DONE=== diff --git a/ext/imap/tests/imap_close_error.phpt b/ext/imap/tests/imap_close_error.phpt deleted file mode 100644 index 8bb43e6a3b..0000000000 --- a/ext/imap/tests/imap_close_error.phpt +++ /dev/null @@ -1,45 +0,0 @@ ---TEST-- -Test imap_close() function : error conditions - incorrect number of args ---SKIPIF-- -<?php -require_once (__DIR__.'/skipif.inc'); -?> ---FILE-- -<?php -/* Prototype : bool imap_close(resource $stream_id [, int $options]) - * Description: Close an IMAP stream - * Source code: ext/imap/php_imap.c - */ - -/* - * Pass an incorrect number of arguments to imap_close() to test behaviour - */ - -echo "*** Testing imap_close() : error conditions ***\n"; -require_once(__DIR__.'/imap_include.inc'); - -// Zero arguments -echo "\n-- Testing imap_close() function with Zero arguments --\n"; -var_dump( imap_close() ); - -//Test imap_close with one more than the expected number of arguments -echo "\n-- Testing imap_close() function with more than expected no. of arguments --\n"; -$stream_id = imap_open($server, $username, $password); -$options = CL_EXPUNGE; -$extra_arg = 10; -var_dump( imap_close($stream_id, $options, $extra_arg) ); -?> -===DONE=== ---EXPECTF-- -*** Testing imap_close() : error conditions *** - --- Testing imap_close() function with Zero arguments -- - -Warning: imap_close() expects at least 1 parameter, 0 given in %s on line %d -NULL - --- Testing imap_close() function with more than expected no. of arguments -- - -Warning: imap_close() expects at most 2 parameters, 3 given in %s on line %d -NULL -===DONE=== diff --git a/ext/imap/tests/imap_close_variation3.phpt b/ext/imap/tests/imap_close_variation3.phpt deleted file mode 100644 index d282ba1dfd..0000000000 --- a/ext/imap/tests/imap_close_variation3.phpt +++ /dev/null @@ -1,47 +0,0 @@ ---TEST-- -Test imap_close() function : usage variations - different streams ---SKIPIF-- -<?php -extension_loaded('imap') or die('skip imap extension not available in this build'); -?> ---FILE-- -<?php -/* Prototype : bool imap_close(resource $stream_id [, int $options]) - * Description: Close an IMAP stream - * Source code: ext/imap/php_imap.c - */ - -/* - * Pass different stream types to imap_close() to test whether it can close them - */ - -echo "*** Testing imap_close() : usage variations ***\n"; - -echo "\n-- File Resource opened with fopen() --\n"; -var_dump($file_handle = fopen(__FILE__, 'r')); -var_dump(imap_close($file_handle)); -var_dump($file_handle); - -echo "\n-- Directory Resource opened with opendir() --\n"; -var_dump($dir_handle = opendir(__DIR__)); -var_dump(imap_close($dir_handle)); -var_dump($dir_handle); -?> -===DONE=== ---EXPECTF-- -*** Testing imap_close() : usage variations *** - --- File Resource opened with fopen() -- -resource(%d) of type (stream) - -Warning: imap_close(): supplied resource is not a valid imap resource in %s on line %d -bool(false) -resource(%d) of type (stream) - --- Directory Resource opened with opendir() -- -resource(%d) of type (stream) - -Warning: imap_close(): supplied resource is not a valid imap resource in %s on line %d -bool(false) -resource(%d) of type (stream) -===DONE=== diff --git a/ext/imap/tests/imap_close_variation4.phpt b/ext/imap/tests/imap_close_variation4.phpt index d71113ca85..b57f607f88 100644 --- a/ext/imap/tests/imap_close_variation4.phpt +++ b/ext/imap/tests/imap_close_variation4.phpt @@ -1,18 +1,13 @@ --TEST-- -Test imap_close() function : usage variations - different ints as $options arg +Test imap_close() function : usage variations - different ints as $flags arg --SKIPIF-- <?php require_once(__DIR__.'/skipif.inc'); ?> --FILE-- <?php -/* Prototype : bool imap_close(resource $stream_id [, int $options]) - * Description: Close an IMAP stream - * Source code: ext/imap/php_imap.c - */ - /* - * Pass different integers as $options arg to imap_close() to test which are + * Pass different integers as $flags arg to imap_close() to test which are * recognised as CL_EXPUNGE option */ @@ -28,37 +23,41 @@ $stream_id = setup_test_mailbox('', 3, $mailbox); // set up temp mailbox with 3 $iterator = 1; foreach($inputs as $input) { - // mark added messages for deletion - for ($i = 1; $i < 4; $i++) { - imap_delete($stream_id, $i); - } - echo "\n-- Iteration $iterator --\n"; - var_dump( $check = imap_close($stream_id, $input) ); - - // check that imap_close was successful, if not call imap_close and explicitly set CL_EXPUNGE - if(false === $check) { - imap_close($stream_id, CL_EXPUNGE); - } else { - // if imap_close was successful test whether CL_EXPUNGE was set by doing a message count - $imap_stream = imap_open($mailbox, $username, $password); - $num_msg = imap_num_msg($imap_stream); - if ($num_msg != 0) { - echo "CL_EXPUNGE was not set, $num_msg msgs in mailbox\n"; - } else { - echo "CL_EXPUNGE was set\n"; - } - // call imap_close with CL_EXPUNGE explicitly set in case mailbox not empty - imap_close($imap_stream, CL_EXPUNGE); - } - $iterator++; - - // get $stream_id for next iteration - $stream_id = imap_open($mailbox, $username, $password); - populate_mailbox($stream_id, $mailbox, 3); + // mark added messages for deletion + for ($i = 1; $i < 4; $i++) { + imap_delete($stream_id, $i); + } + echo "\n-- Iteration $iterator --\n"; + try { + var_dump( $check = imap_close($stream_id, $input) ); + } catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; + $check = false; + } + + // check that imap_close was successful, if not call imap_close and explicitly set CL_EXPUNGE + if(false === $check) { + imap_close($stream_id, CL_EXPUNGE); + } else { + // if imap_close was successful test whether CL_EXPUNGE was set by doing a message count + $imap_stream = imap_open($mailbox, $username, $password); + $num_msg = imap_num_msg($imap_stream); + if ($num_msg != 0) { + echo "CL_EXPUNGE was not set, $num_msg msgs in mailbox\n"; + } else { + echo "CL_EXPUNGE was set\n"; + } + // call imap_close with CL_EXPUNGE explicitly set in case mailbox not empty + imap_close($imap_stream, CL_EXPUNGE); + } + $iterator++; + + // get $stream_id for next iteration + $stream_id = imap_open($mailbox, $username, $password); + populate_mailbox($stream_id, $mailbox, 3); }; ?> -===DONE=== --CLEAN-- <?php require_once(__DIR__.'/clean.inc'); @@ -77,17 +76,10 @@ bool(true) CL_EXPUNGE was set -- Iteration 3 -- - -Warning: imap_close(): invalid value for the flags parameter in %s on line %d -bool(false) +imap_close(): Argument #2 ($flags) must be CL_EXPUNGE or 0 -- Iteration 4 -- - -Warning: imap_close(): invalid value for the flags parameter in %s on line %d -bool(false) +imap_close(): Argument #2 ($flags) must be CL_EXPUNGE or 0 -- Iteration 5 -- - -Warning: imap_close(): invalid value for the flags parameter in %s on line %d -bool(false) -===DONE=== +imap_close(): Argument #2 ($flags) must be CL_EXPUNGE or 0 diff --git a/ext/imap/tests/imap_createmailbox_basic.phpt b/ext/imap/tests/imap_createmailbox_basic.phpt index 9d3cb83058..84db5cbd31 100644 --- a/ext/imap/tests/imap_createmailbox_basic.phpt +++ b/ext/imap/tests/imap_createmailbox_basic.phpt @@ -6,17 +6,12 @@ require_once(__DIR__.'/skipif.inc'); ?> --FILE-- <?php -/* Prototype : bool imap_createmailbox ( resource $imap_stream , string $mailbox ) - * Description: Creates a new mailbox specified by mailbox . - * Source code: ext/imap/php_imap.c - */ - echo "*** Testing imap_createmailbox() : basic functionality ***\n"; require_once(__DIR__.'/imap_include.inc'); $imap_stream = imap_open($default_mailbox, $username, $password) or - die("Cannot connect to mailbox $default_mailbox: " . imap_last_error()); + die("Cannot connect to mailbox $default_mailbox: " . imap_last_error()); $newname = "phpnewbox"; @@ -25,8 +20,8 @@ echo "Newname will be '$newname'\n"; $newbox = imap_utf7_encode($server.$newname); if (imap_createmailbox($imap_stream, $newbox)) { - echo "Add a couple of msgs to '$newname' mailbox\n"; - populate_mailbox($imap_stream, $newbox, 2); + echo "Add a couple of msgs to '$newname' mailbox\n"; + populate_mailbox($imap_stream, $newbox, 2); $status = imap_status($imap_stream, $newbox, SA_ALL); if ($status) { @@ -54,7 +49,6 @@ if (imap_createmailbox($imap_stream, $newbox)) { imap_close($imap_stream); ?> -===Done=== --EXPECTF-- *** Testing imap_createmailbox() : basic functionality *** Newname will be 'phpnewbox' @@ -66,4 +60,3 @@ Unseen: 2 UIDnext: %d UIDvalidity: %d Mailbox 'phpnewbox' removed to restore initial state -===Done=== diff --git a/ext/imap/tests/imap_errors_basic.phpt b/ext/imap/tests/imap_errors_basic.phpt index 0a42e95e1f..c897193766 100644 --- a/ext/imap/tests/imap_errors_basic.phpt +++ b/ext/imap/tests/imap_errors_basic.phpt @@ -1,36 +1,25 @@ --TEST-- -Test imap_errors() function : basic functionality +Test imap_errors() function : invalid password --SKIPIF-- <?php require_once(__DIR__.'/skipif.inc'); ?> --FILE-- <?php -/* Prototype : array imap_errors ( void ) - * Description: Returns all of the IMAP errors that have occurred. - * Source code: ext/imap/php_imap.c - */ - -echo "*** Testing imap_errors() : basic functionality ***\n"; +echo "*** Testing imap_errors() : invalid password ***\n"; require_once(__DIR__.'/imap_include.inc'); $password = "bogus"; // invalid password to use in this test -echo "Issue open with invalid password with normal default number of retries, i.e 3\n"; -$mbox = imap_open($default_mailbox, $username, $password, OP_READONLY, 3); - -echo "List any errors\n"; -var_dump(imap_errors()); - -echo "\n\nIssue open with invalid password with retries == 1\n"; +echo "Issue opening with invalid password, 1 retry\n"; $mbox = imap_open($default_mailbox, $username, $password, OP_READONLY, 1); echo "List any errors\n"; var_dump(imap_errors()); + ?> -===Done=== --EXPECTF-- -*** Testing imap_errors() : basic functionality *** -Issue open with invalid password with normal default number of retries, i.e 3 +*** Testing imap_errors() : invalid password *** +Issue opening with invalid password, 1 retry Warning: imap_open(): Couldn't open stream %s in %s on line %d List any errors @@ -39,17 +28,4 @@ array(%d) { string(%d) "%s" [1]=> string(%d) "%s" - [2]=> - string(%d) "%a -} - - -Issue open with invalid password with retries == 1 - -Warning: imap_open(): Couldn't open stream %s in %s on line %d -List any errors -array(%d) { - [0]=> - string(%d) "%a } -===Done=== diff --git a/ext/imap/tests/imap_expunge_error.phpt b/ext/imap/tests/imap_expunge_error.phpt deleted file mode 100644 index f1298843bb..0000000000 --- a/ext/imap/tests/imap_expunge_error.phpt +++ /dev/null @@ -1,27 +0,0 @@ ---TEST-- -imap_num_recent() incorrect parameter count ---CREDITS-- -Paul Sohier -#phptestfest utrecht ---SKIPIF-- -<?php -require_once(__DIR__.'/skipif.inc'); -?> ---FILE-- -<?php -echo "Checking with no parameters\n"; -imap_num_recent(); - -echo "Checking with incorrect parameter type\n"; -imap_num_recent(''); -imap_num_recent(false); -?> ---EXPECTF-- -Checking with no parameters - -Warning: imap_num_recent() expects exactly 1 parameter, 0 given in %s on line %d -Checking with incorrect parameter type - -Warning: imap_num_recent() expects parameter 1 to be resource, string given in %s on line %d - -Warning: imap_num_recent() expects parameter 1 to be resource, bool given in %s on line %d diff --git a/ext/imap/tests/imap_fetch_overview_basic.phpt b/ext/imap/tests/imap_fetch_overview_basic.phpt index 03aa9ae0a5..a9fe85c45e 100644 --- a/ext/imap/tests/imap_fetch_overview_basic.phpt +++ b/ext/imap/tests/imap_fetch_overview_basic.phpt @@ -6,12 +6,6 @@ require_once(__DIR__.'/skipif.inc'); ?> --FILE-- <?php -/* Prototype : array imap_fetch_overview(resource $stream_id, int $msg_no [, int $options]) - * Description: Read an overview of the information in the headers - * of the given message sequence - * Source code: ext/imap/php_imap.c - */ - echo "*** Testing imap_fetch_overview() : basic functionality ***\n"; require_once(__DIR__.'/imap_include.inc'); @@ -44,7 +38,6 @@ displayOverviewFields($a[1]); imap_close($stream_id); ?> -===DONE=== --CLEAN-- <?php require_once(__DIR__.'/clean.inc'); @@ -93,4 +86,3 @@ deleted is 0 seen is 0 draft is 0 udate is OK -===DONE=== diff --git a/ext/imap/tests/imap_fetch_overview_error.phpt b/ext/imap/tests/imap_fetch_overview_error.phpt deleted file mode 100644 index 629535b0bf..0000000000 --- a/ext/imap/tests/imap_fetch_overview_error.phpt +++ /dev/null @@ -1,54 +0,0 @@ ---TEST-- -Test imap_fetch_overview() function : error conditions - incorrect number of args ---SKIPIF-- -<?php -require_once(__DIR__.'/skipif.inc'); -?> ---FILE-- -<?php -/* Prototype : array imap_fetch_overview(resource $stream_id, int $msg_no [, int $options]) - * Description: Read an overview of the information in the headers - * of the given message sequence - * Source code: ext/imap/php_imap.c - */ - -/* - * Pass an incorrect number of arguments to imap_fetch_overview() to test behaviour - */ - -echo "*** Testing imap_fetch_overview() : error conditions ***\n"; - -require_once(__DIR__.'/imap_include.inc'); - -//Test imap_fetch_overview with one more than the expected number of arguments -echo "\n-- Testing imap_fetch_overview() function with more than expected no. of arguments --\n"; -$stream_id = setup_test_mailbox('', 2, $mailbox, 'notSimple'); // set up temp mailbox with 2 msgs -$msg_no = 1; -$options = FT_UID; -$extra_arg = 10; -var_dump( imap_fetch_overview($stream_id, $msg_no, $options, $extra_arg) ); - -// Testing imap_fetch_overview with one less than the expected number of arguments -echo "\n-- Testing imap_fetch_overview() function with less than expected no. of arguments --\n"; -var_dump( imap_fetch_overview($stream_id) ); -?> -===DONE=== ---CLEAN-- -<?php -require_once(__DIR__.'/clean.inc'); -?> ---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 '{%s}%s' 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_variation3.phpt b/ext/imap/tests/imap_fetch_overview_variation3.phpt index 3c52c73d90..f416887388 100644 --- a/ext/imap/tests/imap_fetch_overview_variation3.phpt +++ b/ext/imap/tests/imap_fetch_overview_variation3.phpt @@ -6,13 +6,8 @@ require_once(__DIR__.'/skipif.inc'); ?> --FILE-- <?php -/* Prototype : array imap_fetch_overview(resource $stream_id, int $msg_no [, int $options]) - * Description: Read an overview of the information in the headers of the given message sequence - * Source code: ext/imap/php_imap.c - */ - /* - * Test passing a range of values into the $options argument to imap_fetch_overview(): + * Test passing a range of values into the $flags argument to imap_fetch_overview(): * 1. values that equate to 1 * 2. Minimum and maximum PHP values */ @@ -26,29 +21,28 @@ $stream_id = setup_test_mailbox('', 1); // set up temporary mailbox with one sim $msg_no = 1; $msg_uid = imap_uid($stream_id, $msg_no); -$options = array ('1', +$flags = array ('1', true, 1.000000000000001, 0.00001e5, - PHP_INT_MAX, - -PHP_INT_MAX + 245 ); -// iterate over each element of $options array -$iterator = 1; imap_check($stream_id); -foreach($options as $option) { - echo "\nTesting with option value:"; - var_dump($option); - $overview = imap_fetch_overview($stream_id, $msg_uid, $option); - if ($overview) { - echo "imap_fetch_overview() returns an object\n"; +foreach($flags as $option) { + echo "\nTesting with option value:"; + var_dump($option); + try { + $overview = imap_fetch_overview($stream_id, $msg_uid, $option); + if ($overview) { + echo "imap_fetch_overview() returns an object\n"; } - $iterator++; + } catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; + } } ?> -===DONE=== --CLEAN-- <?php require_once(__DIR__.'/clean.inc'); @@ -64,17 +58,11 @@ imap_fetch_overview() returns an object Testing with option value:bool(true) imap_fetch_overview() returns an object -Testing with option value:float(1) +Testing with option value:float(1.000000000000001) 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=== +Testing with option value:int(245) +imap_fetch_overview(): Argument #3 ($flags) must be FT_UID or 0 diff --git a/ext/imap/tests/imap_fetch_overview_variation4.phpt b/ext/imap/tests/imap_fetch_overview_variation4.phpt deleted file mode 100644 index 2aa89b75b6..0000000000 --- a/ext/imap/tests/imap_fetch_overview_variation4.phpt +++ /dev/null @@ -1,46 +0,0 @@ ---TEST-- -Test imap_fetch_overview() function : usage variations - different resources as $stream_id ---SKIPIF-- -<?php -extension_loaded('imap') or die('skip imap extension not available in this build'); -?> ---FILE-- -<?php -/* Prototype : array imap_fetch_overview(resource $stream_id, int $msg_no [, int $options]) - * Description: Read an overview of the information in the headers - * of the given message sequence - * Source code: ext/imap/php_imap.c - */ - -/* - * Pass different resource types to imap_fetch_overview() to test behaviour - */ - -echo "*** Testing imap_fetch_overview() : usage variations ***\n"; - -echo "\n-- File Resource opened with fopen() --\n"; -var_dump($file_pointer = fopen(__FILE__, 'r+')); -var_dump(imap_fetch_overview($file_pointer, 1)); -fclose($file_pointer); - -echo "\n-- Directory Resource opened with opendir() --\n"; -var_dump($dir_handle = opendir(__DIR__)); -var_dump(imap_fetch_overview($dir_handle, 1)); -closedir($dir_handle); -?> -===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 index c052b39384..9774e682c1 100644 --- a/ext/imap/tests/imap_fetch_overview_variation5.phpt +++ b/ext/imap/tests/imap_fetch_overview_variation5.phpt @@ -6,12 +6,6 @@ require_once(__DIR__.'/skipif.inc'); ?> --FILE-- <?php -/* Prototype : array imap_fetch_overview(resource $stream_id, int $msg_no [, int $options]) - * Description: Read an overview of the information in the headers - * of the given message sequence - * Source code: ext/imap/php_imap.c - */ - /* * Pass different sequences/msg numbers as $msg_no argument to test behaviour * of imap_fetch_overview() @@ -27,22 +21,21 @@ $sequences = array (0, 4, '4', // out of range '1:3'); // pass uid without setting FT_UID option foreach($sequences as $msg_no) { - echo "\n-- \$msg_no is $msg_no --\n"; + echo "\n-- \$msg_no is $msg_no --\n"; $overview = imap_fetch_overview($stream_id, $msg_no); - if (!$overview) { - echo imap_last_error() . "\n"; + if (!$overview) { + echo imap_last_error() . "\n"; } else { - foreach($overview as $ov) { - echo "\n"; - displayOverviewFields($ov); - } + foreach($overview as $ov) { + echo "\n"; + displayOverviewFields($ov); + } } } // clear error stack imap_errors(); ?> -===DONE=== --CLEAN-- <?php require_once(__DIR__.'/clean.inc'); @@ -135,4 +128,3 @@ deleted is 0 seen is 0 draft is 0 udate is OK -===DONE=== diff --git a/ext/imap/tests/imap_fetch_overview_variation6.phpt b/ext/imap/tests/imap_fetch_overview_variation6.phpt index d284f9bf94..256f631082 100644 --- a/ext/imap/tests/imap_fetch_overview_variation6.phpt +++ b/ext/imap/tests/imap_fetch_overview_variation6.phpt @@ -6,11 +6,6 @@ require_once(__DIR__.'/skipif.inc'); ?> --FILE-- <?php -/* Prototype : array imap_fetch_overview(resource $stream_id, int $msg_no [, int $options]) - * Description: Read an overview of the information in the headers of the given message sequence - * Source code: ext/imap/php_imap.c - */ - /* * Pass a multipart message to imap_fetch_overview() to test the contents of returned array */ @@ -40,52 +35,51 @@ displayOverviewFields($a[0]); * @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; - } + 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-- <?php require_once(__DIR__.'/clean.inc'); @@ -106,4 +100,3 @@ deleted is 0 seen is 0 draft is 0 udate is OK -===DONE=== diff --git a/ext/imap/tests/imap_fetchbody_basic.phpt b/ext/imap/tests/imap_fetchbody_basic.phpt index 66fa345535..3c16f939c8 100644 --- a/ext/imap/tests/imap_fetchbody_basic.phpt +++ b/ext/imap/tests/imap_fetchbody_basic.phpt @@ -6,8 +6,7 @@ require_once(__DIR__.'/skipif.inc'); ?> --FILE-- <?php -/* Prototype : string imap_fetchbody(resource $stream_id, int $msg_no, string $section - * [, int $options]) +/* [, int $options]) * Description: Get a specific body section * Source code: ext/imap/php_imap.c */ @@ -27,26 +26,26 @@ $options = array ('FT_UID' => FT_UID, 'FT_PEEK' => FT_PEEK, 'FT_INTERNAL' => FT_ // Calling imap_fetchbody() with all possible arguments echo "\n-- All possible arguments --\n"; foreach ($options as $key => $option) { - echo "-- Option is $key --\n"; - switch ($key) { + echo "-- Option is $key --\n"; + switch ($key) { - case 'FT_UID'; - $msg_uid = imap_uid($stream_id, $msg_no); - var_dump( imap_fetchbody($stream_id, $msg_uid, $section, $option) ); - break; + case 'FT_UID'; + $msg_uid = imap_uid($stream_id, $msg_no); + var_dump( imap_fetchbody($stream_id, $msg_uid, $section, $option) ); + break; - case 'FT_PEEK'; - var_dump( imap_fetchbody($stream_id, $msg_no, $section, $option) ); - $overview = imap_fetch_overview($stream_id, 1); - echo "Seen Flag: "; - var_dump( $overview[0]->seen ); - break; + case 'FT_PEEK'; + var_dump( imap_fetchbody($stream_id, $msg_no, $section, $option) ); + $overview = imap_fetch_overview($stream_id, 1); + echo "Seen Flag: "; + var_dump( $overview[0]->seen ); + break; - case 'FT_INTERNAL'; - var_dump( imap_fetchbody($stream_id, $msg_no, $section, $option) ); - break; + case 'FT_INTERNAL'; + var_dump( imap_fetchbody($stream_id, $msg_no, $section, $option) ); + break; - } + } } // Calling imap_fetchbody() with mandatory arguments @@ -56,7 +55,6 @@ $overview = imap_fetch_overview($stream_id, 1); echo "Seen Flag: "; var_dump( $overview[0]->seen ); ?> -===DONE=== --CLEAN-- <?php require_once(__DIR__.'/clean.inc'); @@ -78,4 +76,3 @@ string(36) "message 2:yyyyyyyyyyyyyyyyyyyyyyyyyy" -- Mandatory arguments -- string(36) "message 2:yyyyyyyyyyyyyyyyyyyyyyyyyy" Seen Flag: int(%d) -===DONE=== diff --git a/ext/imap/tests/imap_fetchbody_error.phpt b/ext/imap/tests/imap_fetchbody_error.phpt deleted file mode 100644 index c45371a813..0000000000 --- a/ext/imap/tests/imap_fetchbody_error.phpt +++ /dev/null @@ -1,57 +0,0 @@ ---TEST-- -Test imap_fetchbody() function : error conditions - incorrect number of args ---SKIPIF-- -<?php -require_once(__DIR__.'/skipif.inc'); -?> ---FILE-- -<?php -/* Prototype :string imap_fetchbody(resource $stream_id, int $msg_no, string $section - * [, int $options]) - * Description: Get a specific body section - * Source code: ext/imap/php_imap.c - */ - -/* - * Pass an incorrect number of arguments to imap_fetchbody() to test behaviour - */ - -echo "*** Testing imap_fetchbody() : error conditions ***\n"; -require_once(__DIR__.'/imap_include.inc'); - -//Test imap_fetchbody with one more than the expected number of arguments -echo "\n-- Testing imap_fetchbody() function with more than expected no. of arguments --\n"; - -$stream_id = setup_test_mailbox('', 1); // set up temp mailbox with 1 simple msg -$msg_no = 1; -$section = '1'; -$options = FT_PEEK; -$extra_arg = 10; - -var_dump( imap_fetchbody($stream_id, $msg_no, $section, $options, $extra_arg) ); - -// Testing imap_fetchbody with one less than the expected number of arguments -echo "\n-- Testing imap_fetchbody() function with less than expected no. of arguments --\n"; - -var_dump( imap_fetchbody($stream_id, $msg_no) ); -?> -===DONE=== ---CLEAN-- -<?php -require_once(__DIR__.'/clean.inc'); -?> ---EXPECTF-- -*** Testing imap_fetchbody() : error conditions *** - --- Testing imap_fetchbody() function with more than expected no. of arguments -- -Create a temporary mailbox and add 1 msgs -.. mailbox '{%s}%s' created - -Warning: imap_fetchbody() expects at most 4 parameters, 5 given in %s on line %d -NULL - --- Testing imap_fetchbody() function with less than expected no. of arguments -- - -Warning: imap_fetchbody() expects at least 3 parameters, 2 given in %s on line %d -NULL -===DONE=== diff --git a/ext/imap/tests/imap_fetchbody_variation4.phpt b/ext/imap/tests/imap_fetchbody_variation4.phpt index 3259ed9321..df5d895670 100644 --- a/ext/imap/tests/imap_fetchbody_variation4.phpt +++ b/ext/imap/tests/imap_fetchbody_variation4.phpt @@ -6,13 +6,8 @@ require_once(__DIR__.'/skipif.inc'); ?> --FILE-- <?php -/* Prototype : string imap_fetchbody(resource $stream_id, int $msg_no, string $section [, int $options]) - * Description: Get a specific body section - * Source code: ext/imap/php_imap.c - */ - /* - * Test if FT_UID is set by passing the following as $options argument to imap_fetchbody(): + * Test if FT_UID is set by passing the following as $flags argument to imap_fetchbody(): * 1. values that equate to 1 * 2. Minimum and maximum PHP values */ @@ -27,25 +22,29 @@ $msg_uid = imap_uid($stream_id, $msg_no); $section = 1; //Note: the first four values are valid as they will all be cast to 1L. -$options = array ('1', true, +$flags = 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 +// iterate over each element of $flags 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_fetchbody($stream_id, $msg_uid, $section, $option))) { - echo "FT_UID valid\n"; - } else { - echo "FT_UID not valid\n"; +foreach($flags as $option) { + echo "\n-- Iteration $iterator --\n"; + + try { + if(is_string(imap_fetchbody($stream_id, $msg_uid, $section, $option))) { + echo "FT_UID valid\n"; + } else { + echo "FT_UID not valid\n"; } - $iterator++; + } catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; + } + $iterator++; } ?> -===DONE=== --CLEAN-- <?php require_once(__DIR__.'/clean.inc'); @@ -68,12 +67,7 @@ FT_UID valid FT_UID valid -- Iteration 5 -- - -Warning: imap_fetchbody(): invalid value for the options parameter in %s on line %d -FT_UID not valid +imap_fetchbody(): Argument #4 ($flags) must be a bitmask of FT_UID, FT_PEEK, and FT_INTERNAL -- Iteration 6 -- - -Warning: imap_fetchbody(): invalid value for the options parameter in %s on line %d -FT_UID not valid -===DONE=== +imap_fetchbody(): Argument #4 ($flags) must be a bitmask of FT_UID, FT_PEEK, and FT_INTERNAL diff --git a/ext/imap/tests/imap_fetchbody_variation5.phpt b/ext/imap/tests/imap_fetchbody_variation5.phpt deleted file mode 100644 index fa32d0e995..0000000000 --- a/ext/imap/tests/imap_fetchbody_variation5.phpt +++ /dev/null @@ -1,46 +0,0 @@ ---TEST-- -Test imap_fetchbody() function : usage variation - different resources as $stream_id arg ---SKIPIF-- -<?php -extension_loaded('imap') or die('skip imap extension not available in this build'); -?> ---FILE-- -<?php -/* Prototype : string imap_fetchbody(resource $stream_id, int $msg_no, string $section - * [, int options]) - * Description: Get a specific body section - * Source code: ext/imap/php_imap.c - */ - -/* - * Pass different resource types to imap_fetchbody() to test behaviour - */ - -echo "*** Testing imap_fetchbody() : usage variations ***\n"; - -echo "\n-- File Resource opened with fopen() --\n"; -var_dump($file_pointer = fopen(__FILE__, 'r+')); -var_dump(imap_fetchbody($file_pointer, 1)); -fclose($file_pointer); - -echo "\n-- Directory Resource opened with opendir() --\n"; -var_dump($dir_handle = opendir(__DIR__)); -var_dump(imap_fetchbody($dir_handle, 1)); -closedir($dir_handle); -?> -===DONE=== ---EXPECTF-- -*** Testing imap_fetchbody() : usage variations *** - --- File Resource opened with fopen() -- -resource(5) of type (stream) - -Warning: imap_fetchbody() expects at least 3 parameters, 2 given in %s on line %d -NULL - --- Directory Resource opened with opendir() -- -resource(6) of type (stream) - -Warning: imap_fetchbody() expects at least 3 parameters, 2 given in %s on line %d -NULL -===DONE=== diff --git a/ext/imap/tests/imap_fetchbody_variation6.phpt b/ext/imap/tests/imap_fetchbody_variation6.phpt index 18f7d3a40d..8b3d73540a 100644 --- a/ext/imap/tests/imap_fetchbody_variation6.phpt +++ b/ext/imap/tests/imap_fetchbody_variation6.phpt @@ -1,18 +1,13 @@ --TEST-- -Test imap_fetchbody() function : usage variations - $msg_no arg +Test imap_fetchbody() function : usage variations - $message_num arg --SKIPIF-- <?php require_once(__DIR__.'/skipif.inc'); ?> --FILE-- <?php -/* Prototype : string imap_fetchbody(resource $stream_id, int $msg_no, string $section [, int $options]) - * Description: Get a specific body section - * Source code: ext/imap/php_imap.c - */ - /* - * Pass different integers, strings, msg sequences and msg UIDs as $msg_no argument + * Pass different integers, strings, msg sequences and msg UIDs as $message_num argument * to test behaviour of imap_fetchbody() */ @@ -24,19 +19,17 @@ require_once(__DIR__.'/imap_include.inc'); $stream_id = setup_test_mailbox('', 3); // set up temp mailbox with simple msgs $section = 1; -$sequences = array (0, 4, // out of range - '1,3', '1:3', // message sequences instead of numbers - ); +$sequences = [0, /* out of range */ 4, 1]; -foreach($sequences as $msg_no) { - echo "\n-- \$msg_no is $msg_no --\n"; - var_dump($overview = imap_fetchbody($stream_id, $msg_no, $section)); - if (!$overview) { - echo imap_last_error() . "\n"; - } +foreach($sequences as $message_num) { + echo "\n-- \$message_num is $message_num --\n"; + try { + var_dump(imap_fetchbody($stream_id, $message_num, $section)); + } catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; + } } ?> -===DONE=== --CLEAN-- <?php require_once(__DIR__.'/clean.inc'); @@ -46,25 +39,14 @@ require_once(__DIR__.'/clean.inc'); Create a temporary mailbox and add 3 msgs .. mailbox '{%s}%s' created --- $msg_no is 0 -- - -Warning: imap_fetchbody(): Bad message number in %s on line %d -bool(false) - +-- $message_num is 0 -- +imap_fetchbody(): Argument #2 ($message_num) must be greater than 0 --- $msg_no is 4 -- +-- $message_num is 4 -- Warning: imap_fetchbody(): 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 -string(%d) "1: this is a test message, please ignore%a" - --- $msg_no is 1:3 -- - -Notice: A non well formed numeric value encountered in %s on line %d -string(%d) "1: this is a test message, please ignore%a" -===DONE=== +-- $message_num is 1 -- +string(%s) "1: this is a test message, please ignore +%A" diff --git a/ext/imap/tests/imap_fetchheader_basic.phpt b/ext/imap/tests/imap_fetchheader_basic.phpt index 4ffa34c09e..44f7de5a39 100644 --- a/ext/imap/tests/imap_fetchheader_basic.phpt +++ b/ext/imap/tests/imap_fetchheader_basic.phpt @@ -6,11 +6,6 @@ require_once(__DIR__.'/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(__DIR__.'/imap_include.inc'); @@ -23,20 +18,19 @@ $options = array('FT_UID' => FT_UID, 'FT_INTERNAL' => FT_INTERNAL, // 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)); - } + 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(__DIR__.'/clean.inc'); @@ -80,4 +74,3 @@ 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 deleted file mode 100644 index 82a47b64f1..0000000000 --- a/ext/imap/tests/imap_fetchheader_error.phpt +++ /dev/null @@ -1,49 +0,0 @@ ---TEST-- -Test imap_fetchheader() function : error conditions - incorrect number of args ---SKIPIF-- -<?php -require_once(__DIR__.'/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(__DIR__.'/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: 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_variation3.phpt b/ext/imap/tests/imap_fetchheader_variation3.phpt index 8230fdcf3e..a457db0491 100644 --- a/ext/imap/tests/imap_fetchheader_variation3.phpt +++ b/ext/imap/tests/imap_fetchheader_variation3.phpt @@ -6,13 +6,8 @@ require_once(__DIR__.'/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(): + * Test if FT_UID is set by passing the following as $flags argument to imap_fetchheader(): * 1. values that equate to 1 * 2. Minimum and maximum PHP values */ @@ -26,24 +21,27 @@ $stream_id = setup_test_mailbox('', 1); // set up temporary mailbox with one sim $msg_no = 1; $msg_uid = imap_uid($stream_id, $msg_no); -$options = array ('1', true, +$flags = 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 +// iterate over each element of $flags 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"; +foreach($flags as $option) { + echo "\n-- Iteration $iterator --\n"; + try { + if (is_string(imap_fetchheader($stream_id, $msg_uid, $option))) { + echo "FT_UID valid\n"; + } else { + echo "FT_UID not valid\n"; } - $iterator++; + } catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; + } + $iterator++; } ?> -===DONE=== --CLEAN-- <?php require_once(__DIR__.'/clean.inc'); @@ -66,12 +64,7 @@ FT_UID valid FT_UID valid -- Iteration 5 -- - -Warning: imap_fetchheader(): invalid value for the options parameter in %s on line %d -FT_UID not valid +imap_fetchheader(): Argument #3 ($flags) must be a bitmask of FT_UID, FT_PREFETCHTEXT, and FT_INTERNAL -- Iteration 6 -- - -Warning: imap_fetchheader(): invalid value for the options parameter in %s on line %d -FT_UID not valid -===DONE=== +imap_fetchheader(): Argument #3 ($flags) must be a bitmask of FT_UID, FT_PREFETCHTEXT, and FT_INTERNAL diff --git a/ext/imap/tests/imap_fetchheader_variation4.phpt b/ext/imap/tests/imap_fetchheader_variation4.phpt deleted file mode 100644 index 05322f1527..0000000000 --- a/ext/imap/tests/imap_fetchheader_variation4.phpt +++ /dev/null @@ -1,45 +0,0 @@ ---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(__DIR__)); -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=== diff --git a/ext/imap/tests/imap_fetchheader_variation5.phpt b/ext/imap/tests/imap_fetchheader_variation5.phpt index 8773621b09..cb00986a06 100644 --- a/ext/imap/tests/imap_fetchheader_variation5.phpt +++ b/ext/imap/tests/imap_fetchheader_variation5.phpt @@ -1,18 +1,13 @@ --TEST-- -Test imap_fetchheader() function : usage variations - $msg_no argument +Test imap_fetchheader() function : usage variations - $message_num argument --SKIPIF-- <?php require_once(__DIR__.'/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 + * Pass different integers and strings as $message_num argument * to test behaviour of imap_fetchheader() */ @@ -22,22 +17,20 @@ require_once(__DIR__.'/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 - ); +$sequences = [0, /* out of range */ 4, 1]; -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"; - } +foreach($sequences as $message_num) { + echo "\n-- \$message_num is $message_num --\n"; + try { + var_dump(imap_fetchheader($stream_id, $message_num)); + } catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; + } } // clear error stack imap_errors(); ?> -===DONE=== --CLEAN-- <?php require_once(__DIR__.'/clean.inc'); @@ -47,37 +40,19 @@ require_once(__DIR__.'/clean.inc'); Create a temporary mailbox and add 3 msgs .. mailbox '{%s}%s' created --- $msg_no is 0 -- - -Warning: imap_fetchheader(): Bad message number in %s on line %d -bool(false) - +-- $message_num is 0 -- +imap_fetchheader(): Argument #2 ($message_num) must be greater than 0 --- $msg_no is 4 -- +-- $message_num 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 -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 -- - -Notice: A non well formed numeric value encountered in %s on line %d +-- $message_num is 1 -- string(%d) "From: foo@anywhere.com Subject: Test msg 1 To: %s MIME-Version: 1.0 -Content-Type: MULTIPART/mixed; BOUNDARY="%s" +Content-Type: MULTIPART/mixed; BOUNDARY="%s=:%d" " -===DONE=== diff --git a/ext/imap/tests/imap_fetchstructure_basic.phpt b/ext/imap/tests/imap_fetchstructure_basic.phpt index 5d83a27427..24cd2307dd 100644 --- a/ext/imap/tests/imap_fetchstructure_basic.phpt +++ b/ext/imap/tests/imap_fetchstructure_basic.phpt @@ -8,18 +8,15 @@ require_once(__DIR__.'/skipif.inc'); ?> --FILE-- <?php -echo "Checking with no parameters\n"; -imap_fetchstructure(); - -echo "Checking with incorrect parameter type\n"; -imap_fetchstructure(''); -imap_fetchstructure(false); require_once(__DIR__.'/imap_include.inc'); $stream_id = setup_test_mailbox('', 1); -imap_fetchstructure($stream_id); -imap_fetchstructure($stream_id,0); +try { + imap_fetchstructure($stream_id,0); +} catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; +} $z = imap_fetchstructure($stream_id,1); @@ -28,7 +25,7 @@ $fields = array('type','encoding','ifsubtype','subtype', 'ifdescription','lines','bytes','parameters'); foreach ($fields as $key) { - var_dump(isset($z->$key)); + var_dump(isset($z->$key)); } var_dump($z->type); var_dump($z->encoding); @@ -44,18 +41,9 @@ imap_close($stream_id); require_once('clean.inc'); ?> --EXPECTF-- -Checking with no parameters - -Warning: imap_fetchstructure() expects at least 2 parameters, 0 given in %s on line %d -Checking with incorrect parameter type - -Warning: imap_fetchstructure() expects at least 2 parameters, 1 given in %s on line %d - -Warning: imap_fetchstructure() expects at least 2 parameters, 1 given in %s on line %d Create a temporary mailbox and add 1 msgs -.. mailbox '{%s}%s' created - -Warning: imap_fetchstructure() expects at least 2 parameters, 1 given in %s on line %d +.. mailbox '{127.0.0.1:143/norsh}INBOX.phpttest' created +imap_fetchstructure(): Argument #2 ($message_num) must be greater than 0 bool(true) bool(true) bool(true) diff --git a/ext/imap/tests/imap_gc_error.phpt b/ext/imap/tests/imap_gc_error.phpt index e9b2222778..5b5b65d271 100644 --- a/ext/imap/tests/imap_gc_error.phpt +++ b/ext/imap/tests/imap_gc_error.phpt @@ -9,27 +9,17 @@ require_once(__DIR__.'/skipif.inc'); ?> --FILE-- <?php -echo "Checking with no parameters\n"; -imap_gc(); - -echo "Checking with incorrect parameter type\n"; -imap_gc('', false); -imap_gc(false, false); require_once(__DIR__.'/imap_include.inc'); $stream_id = imap_open($default_mailbox, $username, $password) or - die("Cannot connect to mailbox $default_mailbox: " . imap_last_error()); -imap_gc($stream_id, -1); - -?> ---EXPECTF-- -Checking with no parameters + die("Cannot connect to mailbox $default_mailbox: " . imap_last_error()); -Warning: imap_gc() expects exactly 2 parameters, 0 given in %s on line %d -Checking with incorrect parameter type +try { + imap_gc($stream_id, -1); +} catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; +} -Warning: imap_gc() expects parameter 1 to be resource, string given in %s on line %d - -Warning: imap_gc() expects parameter 1 to be resource, bool given in %s on line %d - -Warning: imap_gc(): invalid value for the flags parameter in %s on line %d +?> +--EXPECT-- +imap_gc(): Argument #2 ($flags) must be a bitmask of IMAP_GC_TEXTS, IMAP_GC_ELT, and IMAP_GC_ENV diff --git a/ext/imap/tests/imap_getsubscribed_basic.phpt b/ext/imap/tests/imap_getsubscribed_basic.phpt index 666203a8c2..8e5d85383d 100644 --- a/ext/imap/tests/imap_getsubscribed_basic.phpt +++ b/ext/imap/tests/imap_getsubscribed_basic.phpt @@ -5,22 +5,15 @@ Olivier Doucet --SKIPIF-- <?php require_once(__DIR__.'/skipif.inc'); +if (getenv("SKIP_ASAN")) die("skip asan chokes on this: 'LeakSanitizer does not work under ptrace (strace, gdb, etc)'"); ?> --FILE-- <?php -echo "Checking with no parameters\n"; -imap_getsubscribed(); - -echo "Checking with incorrect parameter type\n"; -imap_getsubscribed(''); -imap_getsubscribed(false); require_once(__DIR__.'/imap_include.inc'); $stream_id = imap_open($default_mailbox, $username, $password) or - die("Cannot connect to mailbox $default_mailbox: " . imap_last_error()); + die("Cannot connect to mailbox $default_mailbox: " . imap_last_error()); -imap_getsubscribed($stream_id); -imap_getsubscribed($stream_id,$default_mailbox); var_dump(imap_getsubscribed($stream_id,$default_mailbox,'ezDvfXvbvcxSerz')); @@ -43,18 +36,6 @@ imap_close($stream_id); require_once('clean.inc'); ?> --EXPECTF-- -Checking with no parameters - -Warning: imap_getsubscribed() expects exactly 3 parameters, 0 given in %s on line %d -Checking with incorrect parameter type - -Warning: imap_getsubscribed() expects exactly 3 parameters, 1 given in %s on line %d - -Warning: imap_getsubscribed() expects exactly 3 parameters, 1 given in %s on line %d - -Warning: imap_getsubscribed() expects exactly 3 parameters, 1 given in %s on line %d - -Warning: imap_getsubscribed() expects exactly 3 parameters, 2 given in %s on line %d bool(false) Checking OK bool(true) diff --git a/ext/imap/tests/imap_headerinfo_basic.phpt b/ext/imap/tests/imap_headerinfo_basic.phpt index c13e62f8bf..056a46523c 100644 --- a/ext/imap/tests/imap_headerinfo_basic.phpt +++ b/ext/imap/tests/imap_headerinfo_basic.phpt @@ -16,14 +16,14 @@ $z = imap_headerinfo($stream_id, 1); $fields = array ('toaddress','to','fromaddress','from', 'reply_toaddress','reply_to', - 'senderaddress', 'sender', + 'senderaddress', 'sender', 'subject','Subject', - 'Recent','Unseen','Flagged','Answered','Deleted','Draft', - 'Msgno','MailDate','Size','udate'); + 'Recent','Unseen','Flagged','Answered','Deleted','Draft', + 'Msgno','MailDate','Size','udate'); echo "Check general fields\n"; foreach ($fields as $key) { - var_dump(isset($z->$key)); + var_dump(isset($z->$key)); } echo "Check type\n"; @@ -35,44 +35,44 @@ var_dump($z->subject); var_dump($z->Subject); if ($z->Recent == 'R' || $z->Recent == 'N' || $z->Recent == ' ') { - echo "Recent: OK"; + echo "Recent: OK"; } else { - echo "Recent: error: ".$z->Recent; + echo "Recent: error: ".$z->Recent; } echo "\n"; if ($z->Unseen == 'U' || $z->Unseen == ' ') { - echo "Unseen: OK"; + echo "Unseen: OK"; } else { - echo "Unseen: error: ".$z->Unseen; + echo "Unseen: error: ".$z->Unseen; } echo "\n"; if ($z->Flagged == 'F' || $z->Flagged == ' ') { - echo "Flagged: OK"; + echo "Flagged: OK"; } else { - echo "Flagged: error: ".$z->Flagged; + echo "Flagged: error: ".$z->Flagged; } echo "\n"; if ($z->Answered == 'A' || $z->Answered == ' ') { - echo "Answered: OK"; + echo "Answered: OK"; } else { - echo "Answered: error"; + echo "Answered: error"; } echo "\n"; if ($z->Deleted == 'D' || $z->Deleted == ' ') { - echo "Deleted: OK"; + echo "Deleted: OK"; } else { - echo "Deleted: error"; + echo "Deleted: error"; } echo "\n"; if ($z->Draft == 'X' || $z->Draft == ' ') { - echo "Draft: OK"; + echo "Draft: OK"; } else { - echo "Draft: error"; + echo "Draft: error"; } echo "\n"; diff --git a/ext/imap/tests/imap_headerinfo_error.phpt b/ext/imap/tests/imap_headerinfo_error.phpt deleted file mode 100644 index 8d67b70130..0000000000 --- a/ext/imap/tests/imap_headerinfo_error.phpt +++ /dev/null @@ -1,36 +0,0 @@ ---TEST-- -imap_headerinfo() incorrect parameter count ---CREDITS-- -Olivier Doucet ---SKIPIF-- -<?php -require_once(__DIR__.'/skipif.inc'); -?> ---FILE-- -<?php -echo "Checking with no parameters\n"; -imap_headerinfo(); - -echo "Checking with incorrect parameter type\n"; -imap_headerinfo(''); -imap_headerinfo(false); - -require_once(__DIR__.'/imap_include.inc'); -$stream_id = imap_open($default_mailbox, $username, $password) or - die("Cannot connect to mailbox $default_mailbox: " . imap_last_error()); - -imap_headerinfo($stream_id); - -imap_close($stream_id); -?> ---EXPECTF-- -Checking with no parameters - -Warning: imap_headerinfo() expects at least 2 parameters, 0 given in %s on line %d -Checking with incorrect parameter type - -Warning: imap_headerinfo() expects at least 2 parameters, 1 given in %s on line %d - -Warning: imap_headerinfo() expects at least 2 parameters, 1 given in %s on line %d - -Warning: imap_headerinfo() expects at least 2 parameters, 1 given in %s on line %d diff --git a/ext/imap/tests/imap_headers.phpt b/ext/imap/tests/imap_headers.phpt deleted file mode 100644 index cd9d6d387f..0000000000 --- a/ext/imap/tests/imap_headers.phpt +++ /dev/null @@ -1,27 +0,0 @@ ---TEST-- -imap_headers() incorrect parameter count ---CREDITS-- -Paul Sohier -#phptestfest utrecht ---SKIPIF-- -<?php -require_once(__DIR__.'/skipif.inc'); -?> ---FILE-- -<?php -echo "Checking with no parameters\n"; -imap_headers(); - -echo "Checking with incorrect parameter type\n"; -imap_headers(''); -imap_headers(false); -?> ---EXPECTF-- -Checking with no parameters - -Warning: imap_headers() expects exactly 1 parameter, 0 given in %s on line %d -Checking with incorrect parameter type - -Warning: imap_headers() expects parameter 1 to be resource, string given in %s on line %d - -Warning: imap_headers() expects parameter 1 to be resource, bool given in %s on line %d diff --git a/ext/imap/tests/imap_include.inc b/ext/imap/tests/imap_include.inc index 369a560a5f..e57d651697 100644 --- a/ext/imap/tests/imap_include.inc +++ b/ext/imap/tests/imap_include.inc @@ -1,6 +1,6 @@ <?php // Change these to make tests run successfully -$server = '{127.0.0.1/norsh}'; +$server = '{127.0.0.1:143/norsh}'; $default_mailbox = $server . "INBOX"; $domain = "something.com"; $admin_user = "webmaster"; // a user with admin access @@ -64,32 +64,32 @@ function displayOverviewFields($resp, $fields=null) { * @return IMAP stream to new mailbox on success; FALSE on failure */ function setup_test_mailbox($mailbox_suffix, $message_count, &$new_mailbox = null, $msg_type = "simple"){ - global $server, $default_mailbox, $username, $password; + global $server, $default_mailbox, $username, $password; - // open a stream to default mailbox - $imap_stream = imap_open($default_mailbox, $username, $password); + // open a stream to default mailbox + $imap_stream = imap_open($default_mailbox, $username, $password); - if ($imap_stream === false) { - echo "Cannot connect to IMAP server $server: " . imap_last_error() . "\n"; - return false; - } + if ($imap_stream === false) { + echo "Cannot connect to IMAP server $server: " . imap_last_error() . "\n"; + return false; + } - echo "Create a temporary mailbox and add " . $message_count . " msgs\n"; - $new_mailbox = create_mailbox($imap_stream, $mailbox_suffix, $message_count, $msg_type); - if ($new_mailbox === false) { - echo "Cant create a temporary mailbox: " . imap_last_error(). "\n"; - return false; - } + echo "Create a temporary mailbox and add " . $message_count . " msgs\n"; + $new_mailbox = create_mailbox($imap_stream, $mailbox_suffix, $message_count, $msg_type); + if ($new_mailbox === false) { + echo "Can't create a temporary mailbox: " . imap_last_error(). "\n"; + return false; + } - echo ".. mailbox '$new_mailbox' created\n"; + echo ".. mailbox '$new_mailbox' created\n"; - // reopen stream to new mailbox - if (imap_reopen($imap_stream, $new_mailbox) === false) { - echo "cant re-open '$new_mailbox' mailbox: " . imap_last_error() . "\n"; - return false; - } + // reopen stream to new mailbox + if (imap_reopen($imap_stream, $new_mailbox) === false) { + echo "can't re-open '$new_mailbox' mailbox: " . imap_last_error() . "\n"; + return false; + } - return $imap_stream; + return $imap_stream; } /** @@ -99,30 +99,30 @@ function setup_test_mailbox($mailbox_suffix, $message_count, &$new_mailbox = nul * @param string $mailbox */ function create_mailbox($imap_stream, $mailbox_suffix, $message_count, $msg_type= "simple"){ - global $default_mailbox, $mailbox_prefix; - $mailbox = $default_mailbox . "." . $mailbox_prefix . $mailbox_suffix; - - $mailboxes = imap_getmailboxes($imap_stream, $mailbox, '*'); - - // check mailbox does not already exist - if ($mailboxes) { - foreach($mailboxes as $value) { - if ($value->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; + global $default_mailbox, $mailbox_prefix; + $mailbox = $default_mailbox . "." . $mailbox_prefix . $mailbox_suffix; + + $mailboxes = imap_getmailboxes($imap_stream, $mailbox, '*'); + + // check mailbox does not already exist + if ($mailboxes) { + foreach($mailboxes as $value) { + if ($value->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; } /** @@ -133,48 +133,48 @@ function create_mailbox($imap_stream, $mailbox_suffix, $message_count, $msg_type */ 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); - } + 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); + } } /** @@ -185,12 +185,12 @@ function populate_mailbox($imap_stream, $mailbox, $message_count, $msg_type = "s */ function get_mailbox_name($mailbox){ - if (preg_match('/\{.*?\}(.*)/', $mailbox, $match) != 1) { - echo "Unrecpognized mailbox name\n"; - return false; - } + if (preg_match('/\{.*?\}(.*)/', $mailbox, $match) != 1) { + echo "Unrecpognized mailbox name\n"; + return false; + } - return $match[1]; + return $match[1]; } ?> diff --git a/ext/imap/tests/imap_list_basic.phpt b/ext/imap/tests/imap_list_basic.phpt index 21f8a63894..addcf70e77 100644 --- a/ext/imap/tests/imap_list_basic.phpt +++ b/ext/imap/tests/imap_list_basic.phpt @@ -8,19 +8,11 @@ require_once(__DIR__.'/skipif.inc'); ?> --FILE-- <?php -echo "Checking with no parameters\n"; -imap_list(); - -echo "Checking with incorrect parameter type\n"; -imap_list(''); -imap_list(false); require_once(__DIR__.'/imap_include.inc'); $stream_id = imap_open($default_mailbox, $username, $password) or - die("Cannot connect to mailbox $default_mailbox: " . imap_last_error()); + die("Cannot connect to mailbox $default_mailbox: " . imap_last_error()); -imap_list($stream_id); -imap_list($stream_id,$default_mailbox); imap_list($stream_id,$default_mailbox,'ezerz'); @@ -31,17 +23,5 @@ var_dump($z[0]); imap_close($stream_id); ?> --EXPECTF-- -Checking with no parameters - -Warning: imap_list() expects exactly 3 parameters, 0 given in %s on line %d -Checking with incorrect parameter type - -Warning: imap_list() expects exactly 3 parameters, 1 given in %s on line %d - -Warning: imap_list() expects exactly 3 parameters, 1 given in %s on line %d - -Warning: imap_list() expects exactly 3 parameters, 1 given in %s on line %d - -Warning: imap_list() expects exactly 3 parameters, 2 given in %s on line %d bool(true) string(%s) "{%s}%s" diff --git a/ext/imap/tests/imap_lsub_basic.phpt b/ext/imap/tests/imap_lsub_basic.phpt index 638479ca80..3cd4722e1f 100644 --- a/ext/imap/tests/imap_lsub_basic.phpt +++ b/ext/imap/tests/imap_lsub_basic.phpt @@ -5,22 +5,15 @@ Olivier Doucet --SKIPIF-- <?php require_once(__DIR__.'/skipif.inc'); +if (getenv("SKIP_ASAN")) die("skip leak sanitizer crashes"); ?> --FILE-- <?php -echo "Checking with no parameters\n"; -imap_lsub(); - -echo "Checking with incorrect parameter type\n"; -imap_lsub(''); -imap_lsub(false); require_once(__DIR__.'/imap_include.inc'); $stream_id = imap_open($default_mailbox, $username, $password) or - die("Cannot connect to mailbox $default_mailbox: " . imap_last_error()); + die("Cannot connect to mailbox $default_mailbox: " . imap_last_error()); -imap_lsub($stream_id); -imap_lsub($stream_id,$default_mailbox); var_dump(imap_lsub($stream_id,$default_mailbox,'ezDvfXvbvcxSerz')); @@ -43,18 +36,6 @@ imap_close($stream_id); require_once('clean.inc'); ?> --EXPECTF-- -Checking with no parameters - -Warning: imap_lsub() expects exactly 3 parameters, 0 given in %s on line %d -Checking with incorrect parameter type - -Warning: imap_lsub() expects exactly 3 parameters, 1 given in %s on line %d - -Warning: imap_lsub() expects exactly 3 parameters, 1 given in %s on line %d - -Warning: imap_lsub() expects exactly 3 parameters, 1 given in %s on line %d - -Warning: imap_lsub() expects exactly 3 parameters, 2 given in %s on line %d bool(false) Checking OK bool(true) diff --git a/ext/imap/tests/imap_mail_copy.phpt b/ext/imap/tests/imap_mail_copy.phpt deleted file mode 100644 index 12a85a1804..0000000000 --- a/ext/imap/tests/imap_mail_copy.phpt +++ /dev/null @@ -1,54 +0,0 @@ ---TEST-- -Test imap_mail_copy() incorrect parameters ---CREDITS-- -Olivier Doucet ---SKIPIF-- -<?php -require_once(__DIR__.'/skipif.inc'); -?> ---FILE-- -<?php -echo "Checking with no parameters\n"; -imap_mail_copy(); - - -echo "Checking with incorrect parameter type\n"; -imap_mail_copy(''); -imap_mail_copy(false); - - -// more tests -require_once(__DIR__.'/imap_include.inc'); - - -echo "Test with IMAP server\n"; -$stream_id = imap_open($default_mailbox, $username, $password) or - die("Cannot connect to mailbox $default_mailbox: " . imap_last_error()); - -var_dump(imap_mail_copy($stream_id)); -var_dump(imap_mail_copy($stream_id,-1)); -var_dump(imap_mail_copy($stream_id, '')); - -imap_close($stream_id); -?> -===Done=== ---EXPECTF-- -Checking with no parameters - -Warning: imap_mail_copy() expects at least 3 parameters, 0 given in %s on line %d -Checking with incorrect parameter type - -Warning: imap_mail_copy() expects at least 3 parameters, 1 given in %s on line %d - -Warning: imap_mail_copy() expects at least 3 parameters, 1 given in %s on line %d -Test with IMAP server - -Warning: imap_mail_copy() expects at least 3 parameters, 1 given in %s on line %d -NULL - -Warning: imap_mail_copy() expects at least 3 parameters, 2 given in %s on line %d -NULL - -Warning: imap_mail_copy() expects at least 3 parameters, 2 given in %s on line %d -NULL -===Done=== diff --git a/ext/imap/tests/imap_mail_copy_basic.phpt b/ext/imap/tests/imap_mail_copy_basic.phpt index a05951e8f6..25725478a6 100644 --- a/ext/imap/tests/imap_mail_copy_basic.phpt +++ b/ext/imap/tests/imap_mail_copy_basic.phpt @@ -8,11 +8,6 @@ require_once(__DIR__.'/skipif.inc'); ?> --FILE-- <?php -/* Prototype : bool imap_mail_copy ( resource $imap_stream , string $msglist , string $mailbox [, int $options = 0 ] ) - * Description: Copies mail messages specified by msglist to specified mailbox. - * Source code: ext/imap/php_imap.c - */ - echo "*** Testing imap_mail_copy() : basic functionality ***\n"; require_once(__DIR__.'/imap_include.inc'); @@ -21,7 +16,7 @@ require_once(__DIR__.'/imap_include.inc'); echo "Create a new mailbox for test\n"; $imap_stream = setup_test_mailbox("", 1); if (!is_resource($imap_stream)) { - exit("TEST FAILED: Unable to create test mailbox\n"); + exit("TEST FAILED: Unable to create test mailbox\n"); } $check = imap_check($imap_stream); @@ -31,7 +26,6 @@ var_dump(imap_mail_copy($imap_stream, '1', 'INBOX.'.$mailbox_prefix)); imap_close($imap_stream); ?> -===Done=== --CLEAN-- <?php require_once('clean.inc'); @@ -43,4 +37,3 @@ Create a temporary mailbox and add 1 msgs .. mailbox '%s' created Msg Count in new mailbox: 1 bool(true) -===Done=== diff --git a/ext/imap/tests/imap_mail_move.phpt b/ext/imap/tests/imap_mail_move.phpt deleted file mode 100644 index 122960b78c..0000000000 --- a/ext/imap/tests/imap_mail_move.phpt +++ /dev/null @@ -1,54 +0,0 @@ ---TEST-- -Test imap_mail_move() incorrect parameters ---CREDITS-- -Olivier Doucet ---SKIPIF-- -<?php -require_once(__DIR__.'/skipif.inc'); -?> ---FILE-- -<?php -echo "Checking with no parameters\n"; -imap_mail_move(); - - -echo "Checking with incorrect parameter type\n"; -imap_mail_move(''); -imap_mail_move(false); - - -// more tests -require_once(__DIR__.'/imap_include.inc'); - - -echo "Test with IMAP server\n"; -$stream_id = imap_open($default_mailbox, $username, $password) or - die("Cannot connect to mailbox $default_mailbox: " . imap_last_error()); - -var_dump(imap_mail_move($stream_id)); -var_dump(imap_mail_move($stream_id,-1)); -var_dump(imap_mail_move($stream_id, '')); - -imap_close($stream_id); -?> -===Done=== ---EXPECTF-- -Checking with no parameters - -Warning: imap_mail_move() expects at least 3 parameters, 0 given in %s on line %d -Checking with incorrect parameter type - -Warning: imap_mail_move() expects at least 3 parameters, 1 given in %s on line %d - -Warning: imap_mail_move() expects at least 3 parameters, 1 given in %s on line %d -Test with IMAP server - -Warning: imap_mail_move() expects at least 3 parameters, 1 given in %s on line %d -NULL - -Warning: imap_mail_move() expects at least 3 parameters, 2 given in %s on line %d -NULL - -Warning: imap_mail_move() expects at least 3 parameters, 2 given in %s on line %d -NULL -===Done=== diff --git a/ext/imap/tests/imap_mail_move_basic.phpt b/ext/imap/tests/imap_mail_move_basic.phpt index 380d288d9b..3988951f12 100644 --- a/ext/imap/tests/imap_mail_move_basic.phpt +++ b/ext/imap/tests/imap_mail_move_basic.phpt @@ -8,11 +8,6 @@ require_once(__DIR__.'/skipif.inc'); ?> --FILE-- <?php -/* Prototype : bool imap_mail_move ( resource $imap_stream , string $msglist , string $mailbox [, int $options = 0 ] ) - * Description: Copies mail messages specified by msglist to specified mailbox. - * Source code: ext/imap/php_imap.c - */ - echo "*** Testing imap_mail_move() : basic functionality ***\n"; require_once(__DIR__.'/imap_include.inc'); @@ -21,7 +16,7 @@ require_once(__DIR__.'/imap_include.inc'); echo "Create a new mailbox for test\n"; $imap_stream = setup_test_mailbox("", 1); if (!is_resource($imap_stream)) { - exit("TEST FAILED: Unable to create test mailbox\n"); + exit("TEST FAILED: Unable to create test mailbox\n"); } $check = imap_check($imap_stream); @@ -31,7 +26,6 @@ var_dump(imap_mail_move($imap_stream, '1', 'INBOX.'.$mailbox_prefix)); imap_close($imap_stream); ?> -===Done=== --CLEAN-- <?php require_once('clean.inc'); @@ -43,4 +37,3 @@ Create a temporary mailbox and add 1 msgs .. mailbox '%s' created Msg Count in new mailbox: 1 bool(true) -===Done=== diff --git a/ext/imap/tests/imap_mutf7_to_utf8.phpt b/ext/imap/tests/imap_mutf7_to_utf8.phpt index e2c745ecd0..f45361f4a9 100644 --- a/ext/imap/tests/imap_mutf7_to_utf8.phpt +++ b/ext/imap/tests/imap_mutf7_to_utf8.phpt @@ -8,16 +8,12 @@ imap_mutf7_to_utf8 var_dump(imap_mutf7_to_utf8("")); var_dump(imap_mutf7_to_utf8(1)); -var_dump(imap_mutf7_to_utf8(array(1,2))); var_dump(imap_mutf7_to_utf8("t&AOQ-st")); echo "Done\n"; ?> ---EXPECTF-- +--EXPECT-- string(0) "" string(1) "1" - -Warning: imap_mutf7_to_utf8() expects parameter 1 to be string, array given in %s on line %d -NULL string(5) "täst" Done diff --git a/ext/imap/tests/imap_num_msg_error.phpt b/ext/imap/tests/imap_num_msg_error.phpt deleted file mode 100644 index fffa3ae951..0000000000 --- a/ext/imap/tests/imap_num_msg_error.phpt +++ /dev/null @@ -1,27 +0,0 @@ ---TEST-- -imap_num_msg() incorrect parameter count ---CREDITS-- -Paul Sohier -#phptestfest utrecht ---SKIPIF-- -<?php -require_once(__DIR__.'/skipif.inc'); -?> ---FILE-- -<?php -echo "Checking with no parameters\n"; -imap_num_msg(); - -echo "Checking with incorrect parameter type\n"; -imap_num_msg(''); -imap_num_msg(false); -?> ---EXPECTF-- -Checking with no parameters - -Warning: imap_num_msg() expects exactly 1 parameter, 0 given in %s on line %d -Checking with incorrect parameter type - -Warning: imap_num_msg() expects parameter 1 to be resource, string given in %s on line %d - -Warning: imap_num_msg() expects parameter 1 to be resource, bool given in %s on line %d diff --git a/ext/imap/tests/imap_num_recent_error.phpt b/ext/imap/tests/imap_num_recent_error.phpt deleted file mode 100644 index b0ad5cefa0..0000000000 --- a/ext/imap/tests/imap_num_recent_error.phpt +++ /dev/null @@ -1,27 +0,0 @@ ---TEST-- -imap_expunge() incorrect parameter count ---CREDITS-- -Paul Sohier -#phptestfest utrecht ---SKIPIF-- -<?php -require_once(__DIR__.'/skipif.inc'); -?> ---FILE-- -<?php -echo "Checking with no parameters\n"; -imap_expunge(); - -echo "Checking with incorrect parameter type\n"; -imap_expunge(''); -imap_expunge(false); -?> ---EXPECTF-- -Checking with no parameters - -Warning: imap_expunge() expects exactly 1 parameter, 0 given in %s on line %d -Checking with incorrect parameter type - -Warning: imap_expunge() expects parameter 1 to be resource, string given in %s on line %d - -Warning: imap_expunge() expects parameter 1 to be resource, bool given in %s on line %d diff --git a/ext/imap/tests/imap_open_error.phpt b/ext/imap/tests/imap_open_error.phpt index b94c11d797..be1063fadc 100644 --- a/ext/imap/tests/imap_open_error.phpt +++ b/ext/imap/tests/imap_open_error.phpt @@ -1,47 +1,39 @@ --TEST-- -imap_open() incorrect parameter count +imap_open() ValueErrors --CREDITS-- Paul Sohier #phptestfest utrecht --SKIPIF-- <?php require_once(__DIR__.'/skipif.inc'); +if (getenv("SKIP_ASAN")) die("skip leak sanitizer crashes"); ?> --FILE-- <?php -echo "Checking with no parameters\n"; -imap_open(); -imap_open(false); -imap_open(false, false); -imap_open(''); -imap_open('', ''); echo "Checking with incorrect parameters\n" ; imap_open('', '', ''); -imap_open('', '', '', -1); + +try { + imap_open('', '', '', -1); +} catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; +} require_once(__DIR__.'/imap_include.inc'); -imap_open($default_mailbox, $username, $password, NIL, -1); + +try { + imap_open($default_mailbox, $username, $password, NIL, -1); +} catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; +} ?> --EXPECTF-- -Checking with no parameters - -Warning: imap_open() expects at least 3 parameters, 0 given in %s on line %d - -Warning: imap_open() expects at least 3 parameters, 1 given in %s on line %d - -Warning: imap_open() expects at least 3 parameters, 2 given in %s on line %d - -Warning: imap_open() expects at least 3 parameters, 1 given in %s on line %d - -Warning: imap_open() expects at least 3 parameters, 2 given in %s on line %d Checking with incorrect parameters Warning: imap_open(): Couldn't open stream in %s on line %d - -Warning: imap_open(): Couldn't open stream in %s on line %d - -Warning: imap_open(): Retries must be greater or equal to 0 in %s on line %d +imap_open(): Argument #4 ($flags) must be a bitmask of the OP_* constants, and CL_EXPUNGE +imap_open(): Argument #5 ($retries) must be greater than or equal to 0 Notice: Unknown: Can't open mailbox : no such mailbox (errflg=2) in Unknown on line 0 diff --git a/ext/imap/tests/imap_ping_error.phpt b/ext/imap/tests/imap_ping_error.phpt deleted file mode 100644 index 5c2498c302..0000000000 --- a/ext/imap/tests/imap_ping_error.phpt +++ /dev/null @@ -1,27 +0,0 @@ ---TEST-- -imap_ping() incorrect parameter count ---CREDITS-- -Paul Sohier -#phptestfest utrecht ---SKIPIF-- -<?php -require_once(__DIR__.'/skipif.inc'); -?> ---FILE-- -<?php -echo "Checking with no parameters\n"; -imap_ping(); - -echo "Checking with incorrect parameter type\n"; -imap_ping(''); -imap_ping(false); -?> ---EXPECTF-- -Checking with no parameters - -Warning: imap_ping() expects exactly 1 parameter, 0 given in %s on line %d -Checking with incorrect parameter type - -Warning: imap_ping() expects parameter 1 to be resource, string given in %s on line %d - -Warning: imap_ping() expects parameter 1 to be resource, bool given in %s on line %d diff --git a/ext/imap/tests/imap_renamemailbox_basic.phpt b/ext/imap/tests/imap_renamemailbox_basic.phpt index 91f99d13e3..c6b1812d16 100644 --- a/ext/imap/tests/imap_renamemailbox_basic.phpt +++ b/ext/imap/tests/imap_renamemailbox_basic.phpt @@ -8,27 +8,17 @@ require_once(__DIR__.'/skipif.inc'); ?> --FILE-- <?php -echo "Checking with no parameters\n"; -imap_renamemailbox(); - -echo "Checking with incorrect parameter type\n"; -imap_renamemailbox(''); -imap_renamemailbox(false); - require_once(__DIR__.'/imap_include.inc'); $stream_id = setup_test_mailbox('', 1); if (!is_resource($stream_id)) { - exit("TEST FAILED: Unable to create test mailbox\n"); + exit("TEST FAILED: Unable to create test mailbox\n"); } $newbox = $default_mailbox . "." . $mailbox_prefix; -imap_renamemailbox($stream_id, $newbox.'not'); -imap_renamemailbox($stream_id, $newbox); - //commented because of bug #49901 //$ancError = error_reporting(0); //$z = imap_renamemailbox($stream_id, $newbox.'not2', $newbox.'2'); @@ -47,20 +37,8 @@ imap_close($stream_id); require_once('clean.inc'); ?> --EXPECTF-- -Checking with no parameters - -Warning: imap_renamemailbox() expects exactly 3 parameters, 0 given in %s on line %d -Checking with incorrect parameter type - -Warning: imap_renamemailbox() expects exactly 3 parameters, 1 given in %s on line %d - -Warning: imap_renamemailbox() expects exactly 3 parameters, 1 given in %s on line %d Create a temporary mailbox and add 1 msgs .. mailbox '{%s}%s' created - -Warning: imap_renamemailbox() expects exactly 3 parameters, 2 given in %s on line %d - -Warning: imap_renamemailbox() expects exactly 3 parameters, 2 given in %s on line %d Checking OK bool(true) bool(true) diff --git a/ext/imap/tests/imap_rfc822_parse_headers_basic.phpt b/ext/imap/tests/imap_rfc822_parse_headers_basic.phpt index 36fcc7f077..87dc4aaf05 100644 --- a/ext/imap/tests/imap_rfc822_parse_headers_basic.phpt +++ b/ext/imap/tests/imap_rfc822_parse_headers_basic.phpt @@ -16,14 +16,14 @@ $z = imap_headerinfo($stream_id, 1); $fields = array ('toaddress','to','fromaddress','from', 'reply_toaddress','reply_to', - 'senderaddress', 'sender', + 'senderaddress', 'sender', 'subject','Subject', - 'MailDate','Size','udate'); + 'MailDate','Size','udate'); echo "Check general fields\n"; foreach ($fields as $key) { - var_dump(isset($z->$key)); + var_dump(isset($z->$key)); } echo "Check type\n"; @@ -35,44 +35,44 @@ var_dump($z->subject); var_dump($z->Subject); if ($z->Recent == 'R' || $z->Recent == 'N' || $z->Recent == ' ') { - echo "Recent: OK"; + echo "Recent: OK"; } else { - echo "Recent: error"; + echo "Recent: error"; } echo "\n"; if ($z->Unseen == 'U' || $z->Unseen == ' ') { - echo "Unseen: OK"; + echo "Unseen: OK"; } else { - echo "Unseen: error"; + echo "Unseen: error"; } echo "\n"; if ($z->Flagged == 'F' || $z->Flagged == ' ') { - echo "Flagged: OK"; + echo "Flagged: OK"; } else { - echo "Flagged: error"; + echo "Flagged: error"; } echo "\n"; if ($z->Answered == 'A' || $z->Answered == ' ') { - echo "Answered: OK"; + echo "Answered: OK"; } else { - echo "Answered: error"; + echo "Answered: error"; } echo "\n"; if ($z->Deleted == 'D' || $z->Deleted == ' ') { - echo "Deleted: OK"; + echo "Deleted: OK"; } else { - echo "Deleted: error"; + echo "Deleted: error"; } echo "\n"; if ($z->Draft == 'X' || $z->Draft == ' ') { - echo "Draft: OK"; + echo "Draft: OK"; } else { - echo "Draft: error"; + echo "Draft: error"; } echo "\n"; diff --git a/ext/imap/tests/imap_savebody_basic.phpt b/ext/imap/tests/imap_savebody_basic.phpt index 2be987a361..ccbaa1ba66 100644 --- a/ext/imap/tests/imap_savebody_basic.phpt +++ b/ext/imap/tests/imap_savebody_basic.phpt @@ -8,18 +8,10 @@ require_once(__DIR__.'/skipif.inc'); ?> --FILE-- <?php -echo "Checking with no parameters\n"; -imap_savebody(); - -echo "Checking with incorrect parameter type\n"; -imap_savebody(''); -imap_savebody(false); require_once(__DIR__.'/imap_include.inc'); $stream_id = setup_test_mailbox('', 1); -imap_savebody($stream_id); - $file = __DIR__.'/tmpsavebody.txt'; //with URL @@ -42,18 +34,8 @@ imap_close($stream_id); require_once('clean.inc'); ?> --EXPECTF-- -Checking with no parameters - -Warning: imap_savebody() expects at least 3 parameters, 0 given in %s on line %d -Checking with incorrect parameter type - -Warning: imap_savebody() expects at least 3 parameters, 1 given in %s on line %d - -Warning: imap_savebody() expects at least 3 parameters, 1 given in %s on line %d Create a temporary mailbox and add 1 msgs -.. mailbox '{%s}%s' created - -Warning: imap_savebody() expects at least 3 parameters, 1 given in %s on line %d +.. mailbox '{127.0.0.1:143/norsh}INBOX.phpttest' created bool(true) Size: %d bool(true) diff --git a/ext/imap/tests/imap_timeout_basic.phpt b/ext/imap/tests/imap_timeout_basic.phpt index a69b86b595..f9618c3e3a 100644 --- a/ext/imap/tests/imap_timeout_basic.phpt +++ b/ext/imap/tests/imap_timeout_basic.phpt @@ -8,12 +8,6 @@ require_once(__DIR__.'/skipif.inc'); ?> --FILE-- <?php -echo "Checking with no parameters\n"; -imap_timeout(); - -echo "Checking with incorrect parameter type\n"; -imap_timeout(''); -imap_timeout(false); echo "GET values:\n"; var_dump(imap_timeout(IMAP_OPENTIMEOUT)); @@ -39,12 +33,6 @@ var_dump(imap_timeout(IMAP_WRITETIMEOUT)); ?> --EXPECTF-- -Checking with no parameters - -Warning: imap_timeout() expects at least 1 parameter, 0 given in %s on line %d -Checking with incorrect parameter type - -Warning: imap_timeout() expects parameter 1 to be int, %s given in %s on line %d GET values: int(%d) int(%d) diff --git a/ext/imap/tests/imap_undelete_error.phpt b/ext/imap/tests/imap_undelete_error.phpt deleted file mode 100644 index 0eae8033eb..0000000000 --- a/ext/imap/tests/imap_undelete_error.phpt +++ /dev/null @@ -1,36 +0,0 @@ ---TEST-- -imap_undelete() incorrect parameter count ---CREDITS-- -Olivier Doucet ---SKIPIF-- -<?php -require_once(__DIR__.'/skipif.inc'); -?> ---FILE-- -<?php -echo "Checking with no parameters\n"; -imap_undelete(); - -echo "Checking with incorrect parameter type\n"; -imap_undelete(''); -imap_undelete(false); - -require_once(__DIR__.'/imap_include.inc'); -$stream_id = imap_open($default_mailbox, $username, $password) or - die("Cannot connect to mailbox $default_mailbox: " . imap_last_error()); - -imap_undelete($stream_id); - -imap_close($stream_id); -?> ---EXPECTF-- -Checking with no parameters - -Warning: imap_undelete() expects at least 2 parameters, 0 given in %s on line %d -Checking with incorrect parameter type - -Warning: imap_undelete() expects at least 2 parameters, 1 given in %s on line %d - -Warning: imap_undelete() expects at least 2 parameters, 1 given in %s on line %d - -Warning: imap_undelete() expects at least 2 parameters, 1 given in %s on line %d diff --git a/ext/imap/tests/imap_utf8.phpt b/ext/imap/tests/imap_utf8.phpt index a8901555d5..a82c3721c3 100644 --- a/ext/imap/tests/imap_utf8.phpt +++ b/ext/imap/tests/imap_utf8.phpt @@ -7,7 +7,6 @@ imap_utf8() tests var_dump(imap_utf8("")); var_dump(imap_utf8(1)); -var_dump(imap_utf8(array(1,2))); var_dump(imap_utf8("test")); echo "Done\n"; @@ -15,8 +14,5 @@ echo "Done\n"; --EXPECTF-- string(0) "" string(1) "1" - -Warning: imap_utf8() expects parameter 1 to be string, array given in %s on line %d -NULL string(4) "%s" Done diff --git a/ext/imap/tests/imap_utf8_to_mutf7_basic.phpt b/ext/imap/tests/imap_utf8_to_mutf7_basic.phpt index bea268a457..8037ae9491 100644 --- a/ext/imap/tests/imap_utf8_to_mutf7_basic.phpt +++ b/ext/imap/tests/imap_utf8_to_mutf7_basic.phpt @@ -8,16 +8,12 @@ imap_utf8_to_mutf7 var_dump(imap_utf8_to_mutf7("")); var_dump(imap_utf8_to_mutf7(1)); -var_dump(imap_utf8_to_mutf7(array(1,2))); var_dump(imap_utf8_to_mutf7("täst")); echo "Done\n"; ?> ---EXPECTF-- +--EXPECT-- string(0) "" string(1) "1" - -Warning: imap_utf8_to_mutf7() expects parameter 1 to be string, array given in %s on line %d -NULL string(8) "t&AOQ-st" Done diff --git a/ext/imap/tests/setup.sh b/ext/imap/tests/setup.sh new file mode 100644 index 0000000000..5cb18334a3 --- /dev/null +++ b/ext/imap/tests/setup.sh @@ -0,0 +1,6 @@ +sudo service dovecot stop +sudo groupadd -g 5000 vmail +sudo useradd -m -d /var/vmail -s /bin/false -u 5000 -g vmail vmail +sudo cp ext/imap/tests/dovecot.conf /etc/dovecot/dovecot.conf +sudo cp ext/imap/tests/dovecotpass /etc/dovecot/dovecotpass +sudo service dovecot start diff --git a/ext/imap/tests/skipif.inc b/ext/imap/tests/skipif.inc index 12b1408634..2167ad1d0c 100644 --- a/ext/imap/tests/skipif.inc +++ b/ext/imap/tests/skipif.inc @@ -2,7 +2,7 @@ extension_loaded('imap') or die('skip imap extension not available in this build'); // Change these to make tests run successfully -$mailbox = '{localhost/norsh}'; +$mailbox = '{127.0.0.1:143/debug/norsh}'; $username = 'webmaster@something.com'; $password = 'p4ssw0rd'; $options = OP_HALFOPEN; // this should be enough to verify server present @@ -10,7 +10,7 @@ $retries = 0; // don't retry connect on failure $mbox = @imap_open($mailbox, $username, $password, $options, $retries); if (!$mbox) { - die("skip could not connect to mailbox $mailbox"); + die("skip could not connect to mailbox $mailbox"); } imap_close($mbox); ?> |
