From: George Peter Banyard Date: Tue, 3 Nov 2020 09:49:18 +0000 (+0000) Subject: Modernize IMAP tests X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=06ddda22fe4e8fd987ad7c1b520469d7a2680e0f;p=php Modernize IMAP tests Use constants when appropriate, drop some ouputs which depends on env vars Enable parallel testing. Closes GH-6380 --- diff --git a/azure/apt.yml b/azure/apt.yml index 71f58ce8da..aa27d4a551 100644 --- a/azure/apt.yml +++ b/azure/apt.yml @@ -42,6 +42,11 @@ steps: snmp-mibs-downloader \ unixodbc-dev \ llvm \ - libc-client-dev libkrb5-dev dovecot-core dovecot-pop3d dovecot-imapd \ + libc-client-dev \ + libkrb5-dev \ + dovecot-core \ + dovecot-pop3d \ + dovecot-imapd \ + sendmail \ ${{ parameters.packages }} displayName: 'APT' diff --git a/azure/setup.yml b/azure/setup.yml index e0b4dc79da..489df88159 100644 --- a/azure/setup.yml +++ b/azure/setup.yml @@ -20,8 +20,8 @@ steps: set -e 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 cp ext/imap/tests/setup/dovecot.conf /etc/dovecot/dovecot.conf + sudo cp ext/imap/tests/setup/dovecotpass /etc/dovecot/dovecotpass sudo service dovecot restart displayName: 'Configure IMAP' diff --git a/ext/imap/tests/CONFLICTS b/ext/imap/tests/CONFLICTS deleted file mode 100644 index c301c0ffac..0000000000 --- a/ext/imap/tests/CONFLICTS +++ /dev/null @@ -1 +0,0 @@ -imap diff --git a/ext/imap/tests/README.md b/ext/imap/tests/README.md index 6324ab7f9e..1dee1d2663 100644 --- a/ext/imap/tests/README.md +++ b/ext/imap/tests/README.md @@ -11,14 +11,14 @@ hMailServer on Windows. The tests are intended to be mailserver agnostic. ## 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` +`apt-get install libc-client-dev libkrb5-dev dovecot-core dovecot-pop3d dovecot-imapd sendmail` 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` +Then run the set-up script `ext/imap/tests/setup/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 +`ext/imap/tests/setup/dovecot.conf` and `ext/imap/tests/setup/dovecotpass` to the correct location for Dovecot and restarts it for the new configuration to be enabled. diff --git a/ext/imap/tests/bug31142_2.phpt b/ext/imap/tests/bug31142_2.phpt index 004c054963..dbb4c9a6ad 100644 --- a/ext/imap/tests/bug31142_2.phpt +++ b/ext/imap/tests/bug31142_2.phpt @@ -2,9 +2,7 @@ Bug #31142 test #2 (imap_mail_compose() generates incorrect output) --SKIPIF-- --FILE-- --FILE-- --FILE-- --FILE-- , expected \n"; -} else { - echo "ok"; -} +var_dump($res); + ?> --EXPECT-- -ok +string(17) "Luzon®14 dot CoM" diff --git a/ext/imap/tests/bug45705_1.phpt b/ext/imap/tests/bug45705_1.phpt index 05d3a0a2f6..b8d33e6758 100644 --- a/ext/imap/tests/bug45705_1.phpt +++ b/ext/imap/tests/bug45705_1.phpt @@ -2,9 +2,7 @@ Bug #45705 test #1 (imap rfc822_parse_adrlist() modifies passed address parameter) --SKIPIF-- --FILE-- --FILE-- --FILE-- +--CONFLICTS-- +defaultmailbox --FILE-- array('DISABLE_AUTHENTICATOR' => array('GSSAPI','NTLM')), 'String' => array('DISABLE_AUTHENTICATOR' => 'GSSAPI'), ); -require_once(__DIR__.'/imap_include.inc'); +require_once(__DIR__. '/setup/imap_include.inc'); foreach ($tests as $name => $testparams) { echo "Test for $name\n"; - $in = imap_open($default_mailbox, $username, $password, OP_HALFOPEN, 1, $testparams); + $in = imap_open(IMAP_SERVER_DEBUG, IMAP_MAILBOX_USERNAME, IMAP_MAILBOX_PASSWORD, OP_HALFOPEN, 1, $testparams); if ($in) { if (is_array($errors = imap_errors())) { foreach ($errors as $err) { diff --git a/ext/imap/tests/bug64076.phpt b/ext/imap/tests/bug64076.phpt index ccafcfe251..7e9ee6fd04 100644 --- a/ext/imap/tests/bug64076.phpt +++ b/ext/imap/tests/bug64076.phpt @@ -2,22 +2,23 @@ Bug #64076 (imap_sort() does not return FALSE on failure) --SKIPIF-- --FILE-- --CLEAN-- --EXPECT-- Create a temporary mailbox and add 2 msgs -.. mailbox '{127.0.0.1:143/norsh}INBOX.phpttest' created +New mailbox created bool(false) bool(true) diff --git a/ext/imap/tests/bug77020.phpt b/ext/imap/tests/bug77020.phpt index 43c8133700..d828654983 100644 --- a/ext/imap/tests/bug77020.phpt +++ b/ext/imap/tests/bug77020.phpt @@ -6,8 +6,8 @@ if (!extension_loaded('imap')) die('skip imap extension not available'); ?> --FILE-- --EXPECTF-- -Warning: imap_mail(): No message string in mail command in %s on line %d -%S +%Adone diff --git a/ext/imap/tests/bug77153.phpt b/ext/imap/tests/bug77153.phpt index 7b759621fe..359923ca83 100644 --- a/ext/imap/tests/bug77153.phpt +++ b/ext/imap/tests/bug77153.phpt @@ -1,10 +1,8 @@ ---TEST-- +--TEST-- Bug #77153 (imap_open allows to run arbitrary shell commands via mailbox parameter) --SKIPIF-- --FILE-- \ No newline at end of file +?> diff --git a/ext/imap/tests/bug80213.phpt b/ext/imap/tests/bug80213.phpt index 9a7961df77..5bad48f306 100644 --- a/ext/imap/tests/bug80213.phpt +++ b/ext/imap/tests/bug80213.phpt @@ -14,8 +14,13 @@ $body = [[ 'type.parameters' => ['param'], 'disposition' => ['disp'], ]]; -imap_mail_compose($envelope, $body); +var_dump(imap_mail_compose($envelope, $body)); echo "done\n"; ?> --EXPECT-- +string(67) "MIME-Version: 1.0 +Content-Type: TEXT/PLAIN; CHARSET=US-ASCII + + +" done diff --git a/ext/imap/tests/bug80226.phpt b/ext/imap/tests/bug80226.phpt index 95ec235178..36dd97cf6a 100644 --- a/ext/imap/tests/bug80226.phpt +++ b/ext/imap/tests/bug80226.phpt @@ -2,12 +2,16 @@ Bug #80226 (imap_sort() leaks sortpgm memory) --SKIPIF-- +--CONFLICTS-- +defaultmailbox --FILE-- --EXPECT-- +array(0) { +} diff --git a/ext/imap/tests/clean.inc b/ext/imap/tests/clean.inc deleted file mode 100644 index 8bc566ba32..0000000000 --- a/ext/imap/tests/clean.inc +++ /dev/null @@ -1,25 +0,0 @@ -Nmsgs; $i++) { - imap_delete($imap_stream, $i); -} - -$mailboxes = imap_getmailboxes($imap_stream, $server, '*'); - -foreach($mailboxes as $value) { - // Only delete mailboxes with our prefix - if (preg_match('/\{.*?\}INBOX\.(.+)/', $value->name, $match) == 1) { - if (strlen($match[1]) >= strlen($mailbox_prefix) - && substr_compare($match[1], $mailbox_prefix, 0, strlen($mailbox_prefix)) == 0) { - imap_deletemailbox($imap_stream, $value->name); - } - } -} - -imap_close($imap_stream, CL_EXPUNGE); -?> diff --git a/ext/imap/tests/imap_append_basic.phpt b/ext/imap/tests/imap_append_basic.phpt index e75b452596..ab2e46886e 100644 --- a/ext/imap/tests/imap_append_basic.phpt +++ b/ext/imap/tests/imap_append_basic.phpt @@ -2,22 +2,19 @@ Test imap_append() function : basic functionality --SKIPIF-- --FILE-- Mailbox . "\n"; +echo "Add a couple of msgs to the new mailbox\n"; var_dump(imap_append($imap_stream, $mb_details->Mailbox , "From: webmaster@something.com\r\n" . "To: info@something.com\r\n" @@ -44,14 +41,15 @@ imap_close($imap_stream); ?> --CLEAN-- --EXPECTF-- *** Testing imap_append() : basic functionality *** Create a new mailbox for test Create a temporary mailbox and add 0 msgs -.. mailbox '%s' created -Add a couple of msgs to new mailbox {%s}INBOX.%s +New mailbox created +Add a couple of msgs to the new mailbox bool(true) bool(true) Msg Count after append : 2 diff --git a/ext/imap/tests/imap_body.phpt b/ext/imap/tests/imap_body.phpt index 6c2f629398..de07a5c579 100644 --- a/ext/imap/tests/imap_body.phpt +++ b/ext/imap/tests/imap_body.phpt @@ -5,14 +5,17 @@ Paul Sohier #phptestfest utrecht --SKIPIF-- +--CONFLICTS-- +# Might not be needed +defaultmailbox --FILE-- --FILE-- --CLEAN-- --EXPECTF-- *** Testing imap_body() : basic functionality *** Create a new mailbox for test Create a temporary mailbox and add 1 msgs -.. mailbox '%s' created +New mailbox created Msg Count in new mailbox: 1 string(%d) "1: this is a test message, please ignore -" +newline%r\R?%r" string(%d) "1: this is a test message, please ignore -" +newline%r\R?%r" diff --git a/ext/imap/tests/imap_bodystruct_basic.phpt b/ext/imap/tests/imap_bodystruct_basic.phpt index 56c88399c3..5670fc4ad1 100644 --- a/ext/imap/tests/imap_bodystruct_basic.phpt +++ b/ext/imap/tests/imap_bodystruct_basic.phpt @@ -2,15 +2,15 @@ Test imap_bodystruct() function : basic functionality --SKIPIF-- --FILE-- --CLEAN-- ---EXPECTF-- +--EXPECT-- *** Testing string imap_bodystruct : basic functionality *** Create a new mailbox for test and add a multipart msgs Create a temporary mailbox and add 1 msgs -.. mailbox '{%s}%s' created +New mailbox created Get and validate structure of body part 1 ifsubtype is 0 or 1 diff --git a/ext/imap/tests/imap_clearflag_full_basic.phpt b/ext/imap/tests/imap_clearflag_full_basic.phpt index cc949385fc..bcf168b18b 100644 --- a/ext/imap/tests/imap_clearflag_full_basic.phpt +++ b/ext/imap/tests/imap_clearflag_full_basic.phpt @@ -2,16 +2,16 @@ Test imap_clearflag_full() function : basic functionality --SKIPIF-- --FILE-- --CLEAN-- ---EXPECTF-- +--EXPECT-- *** Testing imap_clearflag_full() : basic functionality *** Create a new mailbox for test Create a temporary mailbox and add 10 msgs -.. mailbox '{%s}%s' created +New mailbox created Initial msg count in new_mailbox : 10 Set some flags bool(true) diff --git a/ext/imap/tests/imap_close_basic.phpt b/ext/imap/tests/imap_close_basic.phpt index 57b2e7eab1..c962b62f7f 100644 --- a/ext/imap/tests/imap_close_basic.phpt +++ b/ext/imap/tests/imap_close_basic.phpt @@ -2,17 +2,17 @@ Test imap_close() function : basic functionality --SKIPIF-- --FILE-- --CLEAN-- --EXPECTF-- *** Testing imap_close() : basic functionality *** Create a temporary mailbox and add 3 msgs -.. mailbox '%sINBOX.phpttest' created +New mailbox created -- Call to imap_close() with all possible arguments -- bool(true) -There are now 0 msgs in mailbox '%sINBOX.phpttest' +There are now 0 msgs in mailbox '%sINBOX.phpttestimapclosebasic' -- Call to imap_close() with mandatory arguments -- bool(true) diff --git a/ext/imap/tests/imap_close_variation4.phpt b/ext/imap/tests/imap_close_variation4.phpt index b57f607f88..cf6f72873a 100644 --- a/ext/imap/tests/imap_close_variation4.phpt +++ b/ext/imap/tests/imap_close_variation4.phpt @@ -2,8 +2,11 @@ Test imap_close() function : usage variations - different ints as $flags arg --SKIPIF-- +--CONFLICTS-- +# It should be possible to use a custom mailbox instead of conflicting with the default one +defaultmailbox --FILE-- --CLEAN-- ---EXPECTF-- +--EXPECT-- *** Testing imap_close() : usage variations *** Create a temporary mailbox and add 3 msgs -.. mailbox '{%s}%s' created +New mailbox created -- Iteration 1 -- bool(true) diff --git a/ext/imap/tests/imap_createmailbox_basic.phpt b/ext/imap/tests/imap_createmailbox_basic.phpt index 84db5cbd31..691b535630 100644 --- a/ext/imap/tests/imap_createmailbox_basic.phpt +++ b/ext/imap/tests/imap_createmailbox_basic.phpt @@ -2,22 +2,24 @@ Test imap_createmailbox() function : basic functionality --SKIPIF-- +--CONFLICTS-- +defaultmailbox --FILE-- +--CLEAN-- + --EXPECTF-- *** Testing imap_createmailbox() : basic functionality *** diff --git a/ext/imap/tests/imap_errors_basic.phpt b/ext/imap/tests/imap_errors_basic.phpt index c897193766..f691a5c705 100644 --- a/ext/imap/tests/imap_errors_basic.phpt +++ b/ext/imap/tests/imap_errors_basic.phpt @@ -2,16 +2,16 @@ Test imap_errors() function : invalid password --SKIPIF-- --FILE-- +--CONFLICTS-- +defaultmailbox --FILE-- --CLEAN-- --EXPECTF-- *** Testing imap_fetch_overview() : basic functionality *** Create a temporary mailbox and add 2 msgs -.. mailbox '{%s}%s' created +New mailbox created -- All possible arguments -- diff --git a/ext/imap/tests/imap_fetch_overview_variation3.phpt b/ext/imap/tests/imap_fetch_overview_variation3.phpt index f416887388..ada23d4f2a 100644 --- a/ext/imap/tests/imap_fetch_overview_variation3.phpt +++ b/ext/imap/tests/imap_fetch_overview_variation3.phpt @@ -2,8 +2,10 @@ Test imap_fetch_overview() function : usage variations - FT_UID option --SKIPIF-- +--CONFLICTS-- +defaultmailbox --FILE-- --CLEAN-- ---EXPECTF-- +--EXPECT-- *** Testing imap_fetch_overview() : usage variations *** Create a temporary mailbox and add 1 msgs -.. mailbox '{%s}%s' created +New mailbox created Testing with option value:string(1) "1" imap_fetch_overview() returns an object diff --git a/ext/imap/tests/imap_fetch_overview_variation5.phpt b/ext/imap/tests/imap_fetch_overview_variation5.phpt index 9774e682c1..00c7602a23 100644 --- a/ext/imap/tests/imap_fetch_overview_variation5.phpt +++ b/ext/imap/tests/imap_fetch_overview_variation5.phpt @@ -2,8 +2,10 @@ Test imap_fetch_overview() function : usage variations - $msg_no argument --SKIPIF-- +--CONFLICTS-- +defaultmailbox --FILE-- --CLEAN-- --EXPECTF-- *** Testing imap_fetch_overview() : usage variations *** Create a temporary mailbox and add 3 msgs -.. mailbox '{%s}%s' created +New mailbox created -- $msg_no is 0 -- Sequence out of range diff --git a/ext/imap/tests/imap_fetch_overview_variation6.phpt b/ext/imap/tests/imap_fetch_overview_variation6.phpt index 256f631082..a779c25460 100644 --- a/ext/imap/tests/imap_fetch_overview_variation6.phpt +++ b/ext/imap/tests/imap_fetch_overview_variation6.phpt @@ -2,8 +2,10 @@ Test imap_fetch_overview() function : usage variations - multipart message --SKIPIF-- +--CONFLICTS-- +defaultmailbox --FILE-- --CLEAN-- --EXPECTF-- *** Testing imap_fetch_overview() : usage variations *** Create a temporary mailbox and add 0 msgs -.. mailbox '{%s}%s' created +New mailbox created --> Object #1 size is %d diff --git a/ext/imap/tests/imap_fetchbody_basic.phpt b/ext/imap/tests/imap_fetchbody_basic.phpt index 3c16f939c8..c07813ef7b 100644 --- a/ext/imap/tests/imap_fetchbody_basic.phpt +++ b/ext/imap/tests/imap_fetchbody_basic.phpt @@ -2,8 +2,10 @@ Test imap_fetchbody() function : basic functionality --SKIPIF-- +--CONFLICTS-- +defaultmailbox --FILE-- seen ); ?> --CLEAN-- --EXPECTF-- *** Testing imap_fetchbody() : basic functionality *** Create a temporary mailbox and add 1 msgs -.. mailbox '{%s}%s' created +New mailbox created -- All possible arguments -- -- Option is FT_UID -- diff --git a/ext/imap/tests/imap_fetchbody_variation4.phpt b/ext/imap/tests/imap_fetchbody_variation4.phpt index df5d895670..5e25dd1126 100644 --- a/ext/imap/tests/imap_fetchbody_variation4.phpt +++ b/ext/imap/tests/imap_fetchbody_variation4.phpt @@ -2,7 +2,7 @@ Test imap_fetchbody() function : usage variations - FT_UID option --SKIPIF-- --FILE-- --CLEAN-- ---EXPECTF-- +--EXPECT-- *** Testing imap_fetchbody() : usage variations *** Create a temporary mailbox and add 1 msgs -.. mailbox '{%s}%s' created +New mailbox created -- Iteration 1 -- FT_UID valid diff --git a/ext/imap/tests/imap_fetchbody_variation6.phpt b/ext/imap/tests/imap_fetchbody_variation6.phpt index 8b3d73540a..7889c40193 100644 --- a/ext/imap/tests/imap_fetchbody_variation6.phpt +++ b/ext/imap/tests/imap_fetchbody_variation6.phpt @@ -2,7 +2,7 @@ Test imap_fetchbody() function : usage variations - $message_num arg --SKIPIF-- --FILE-- --CLEAN-- --EXPECTF-- *** Testing imap_fetchbody() : usage variations *** Create a temporary mailbox and add 3 msgs -.. mailbox '{%s}%s' created +New mailbox created -- $message_num is 0 -- imap_fetchbody(): Argument #2 ($message_num) must be greater than 0 @@ -48,5 +49,5 @@ Warning: imap_fetchbody(): Bad message number in %s on line %d bool(false) -- $message_num is 1 -- -string(%s) "1: this is a test message, please ignore -%A" +string(%d) "1: this is a test message, please ignore +newline%r\R?%r" diff --git a/ext/imap/tests/imap_fetchheader_basic.phpt b/ext/imap/tests/imap_fetchheader_basic.phpt index 44f7de5a39..dc934e00cf 100644 --- a/ext/imap/tests/imap_fetchheader_basic.phpt +++ b/ext/imap/tests/imap_fetchheader_basic.phpt @@ -2,15 +2,15 @@ Test imap_fetchheader() function : basic function --SKIPIF-- --FILE-- FT_UID, 'FT_INTERNAL' => FT_INTERNAL, 'FT_PREFETCHTEXT' => FT_PREFETCHTEXT); @@ -33,12 +33,13 @@ var_dump( imap_fetchheader($stream_id, $msg_no) ); ?> --CLEAN-- --EXPECTF-- *** Testing imap_fetchheader() : basic functionality *** Create a temporary mailbox and add 1 msgs -.. mailbox '%s.phpttest' created +New mailbox created -- All possible arguments -- -- Option is FT_UID -- diff --git a/ext/imap/tests/imap_fetchheader_variation3.phpt b/ext/imap/tests/imap_fetchheader_variation3.phpt index a457db0491..1289087b7d 100644 --- a/ext/imap/tests/imap_fetchheader_variation3.phpt +++ b/ext/imap/tests/imap_fetchheader_variation3.phpt @@ -2,7 +2,7 @@ Test imap_fetchheader() function : usage variations - FT_UID option --SKIPIF-- --FILE-- --CLEAN-- ---EXPECTF-- +--EXPECT-- *** Testing imap_fetchheader() : usage variations *** Create a temporary mailbox and add 1 msgs -.. mailbox '{%s}%s' created +New mailbox created -- Iteration 1 -- FT_UID valid diff --git a/ext/imap/tests/imap_fetchheader_variation5.phpt b/ext/imap/tests/imap_fetchheader_variation5.phpt index cb00986a06..eb6493017b 100644 --- a/ext/imap/tests/imap_fetchheader_variation5.phpt +++ b/ext/imap/tests/imap_fetchheader_variation5.phpt @@ -2,7 +2,7 @@ Test imap_fetchheader() function : usage variations - $message_num argument --SKIPIF-- --FILE-- --CLEAN-- --EXPECTF-- *** Testing imap_fetchheader() : usage variations *** Create a temporary mailbox and add 3 msgs -.. mailbox '{%s}%s' created +New mailbox created -- $message_num is 0 -- imap_fetchheader(): Argument #2 ($message_num) must be greater than 0 diff --git a/ext/imap/tests/imap_fetchstructure_basic.phpt b/ext/imap/tests/imap_fetchstructure_basic.phpt index 24cd2307dd..2eb730c890 100644 --- a/ext/imap/tests/imap_fetchstructure_basic.phpt +++ b/ext/imap/tests/imap_fetchstructure_basic.phpt @@ -4,13 +4,13 @@ imap_fetchstructure() function : basic functionality Olivier Doucet --SKIPIF-- --FILE-- --CLEAN-- --EXPECTF-- Create a temporary mailbox and add 1 msgs -.. mailbox '{127.0.0.1:143/norsh}INBOX.phpttest' created +New mailbox created imap_fetchstructure(): Argument #2 ($message_num) must be greater than 0 bool(true) bool(true) diff --git a/ext/imap/tests/imap_gc_error.phpt b/ext/imap/tests/imap_gc_error.phpt index 5b5b65d271..81b4a4bab6 100644 --- a/ext/imap/tests/imap_gc_error.phpt +++ b/ext/imap/tests/imap_gc_error.phpt @@ -1,18 +1,18 @@ --TEST-- -imap_gc() incorrect parameter count +imap_gc() ValueError --CREDITS-- Paul Sohier #phptestfest utrecht --SKIPIF-- --FILE-- +--CONFLICTS-- +defaultmailbox --FILE-- --CLEAN-- --EXPECTF-- bool(false) diff --git a/ext/imap/tests/imap_headerinfo_basic.phpt b/ext/imap/tests/imap_headerinfo_basic.phpt index 056a46523c..0d84aee44b 100644 --- a/ext/imap/tests/imap_headerinfo_basic.phpt +++ b/ext/imap/tests/imap_headerinfo_basic.phpt @@ -4,13 +4,13 @@ imap_headerinfo() function : basic functionality Olivier Doucet --SKIPIF-- --FILE-- --CLEAN-- --EXPECTF-- Create a temporary mailbox and add 1 msgs -.. mailbox '{%s}%s' created +New mailbox created Check general fields bool(true) bool(true) diff --git a/ext/imap/tests/imap_list_basic.phpt b/ext/imap/tests/imap_list_basic.phpt index addcf70e77..e11c6c1bd0 100644 --- a/ext/imap/tests/imap_list_basic.phpt +++ b/ext/imap/tests/imap_list_basic.phpt @@ -4,20 +4,22 @@ imap_list() function : basic functionality Olivier Doucet --SKIPIF-- --FILE-- +--CONFLICTS-- +defaultmailbox --FILE-- --CLEAN-- --EXPECTF-- bool(false) diff --git a/ext/imap/tests/imap_mail_copy_basic.phpt b/ext/imap/tests/imap_mail_copy_basic.phpt index 25725478a6..689f75667e 100644 --- a/ext/imap/tests/imap_mail_copy_basic.phpt +++ b/ext/imap/tests/imap_mail_copy_basic.phpt @@ -4,13 +4,15 @@ Test imap_mail_copy() function : basic functionality Olivier Doucet --SKIPIF-- +--CONFLICTS-- +defaultmailbox --FILE-- Nmsgs . "\n"; -var_dump(imap_mail_copy($imap_stream, '1', 'INBOX.'.$mailbox_prefix)); +var_dump(imap_mail_copy($imap_stream, '1', 'INBOX.'.IMAP_MAILBOX_PHPT_PREFIX)); imap_close($imap_stream); ?> --CLEAN-- ---EXPECTF-- +--EXPECT-- *** Testing imap_mail_copy() : basic functionality *** Create a new mailbox for test Create a temporary mailbox and add 1 msgs -.. mailbox '%s' created +New mailbox created Msg Count in new mailbox: 1 bool(true) diff --git a/ext/imap/tests/imap_mail_move_basic.phpt b/ext/imap/tests/imap_mail_move_basic.phpt index 3988951f12..4c07c85a78 100644 --- a/ext/imap/tests/imap_mail_move_basic.phpt +++ b/ext/imap/tests/imap_mail_move_basic.phpt @@ -4,13 +4,15 @@ Test imap_mail_move() function : basic functionality Olivier Doucet --SKIPIF-- +--CONFLICTS-- +defaultmailbox --FILE-- Nmsgs . "\n"; -var_dump(imap_mail_move($imap_stream, '1', 'INBOX.'.$mailbox_prefix)); +var_dump(imap_mail_move($imap_stream, '1', 'INBOX.'. IMAP_MAILBOX_PHPT_PREFIX)); imap_close($imap_stream); ?> --CLEAN-- ---EXPECTF-- +--EXPECT-- *** Testing imap_mail_move() : basic functionality *** Create a new mailbox for test Create a temporary mailbox and add 1 msgs -.. mailbox '%s' created +New mailbox created Msg Count in new mailbox: 1 bool(true) diff --git a/ext/imap/tests/imap_mutf7_to_utf8.phpt b/ext/imap/tests/imap_mutf7_to_utf8.phpt index f45361f4a9..835a25428f 100644 --- a/ext/imap/tests/imap_mutf7_to_utf8.phpt +++ b/ext/imap/tests/imap_mutf7_to_utf8.phpt @@ -2,7 +2,6 @@ imap_mutf7_to_utf8 --SKIPIF-- - --FILE-- --FILE-- @@ -20,10 +20,8 @@ try { echo $e->getMessage() . \PHP_EOL; } -require_once(__DIR__.'/imap_include.inc'); - try { - imap_open($default_mailbox, $username, $password, NIL, -1); + imap_open('', '', '', NIL, -1); } catch (\ValueError $e) { echo $e->getMessage() . \PHP_EOL; } diff --git a/ext/imap/tests/imap_renamemailbox_basic.phpt b/ext/imap/tests/imap_renamemailbox_basic.phpt index c6b1812d16..f727f21729 100644 --- a/ext/imap/tests/imap_renamemailbox_basic.phpt +++ b/ext/imap/tests/imap_renamemailbox_basic.phpt @@ -4,20 +4,20 @@ imap_renamemailbox() function : basic functionality Olivier Doucet --SKIPIF-- --FILE-- --CLEAN-- ---EXPECTF-- +--EXPECT-- Create a temporary mailbox and add 1 msgs -.. mailbox '{%s}%s' created +New mailbox created 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 87dc4aaf05..fd2dfb939d 100644 --- a/ext/imap/tests/imap_rfc822_parse_headers_basic.phpt +++ b/ext/imap/tests/imap_rfc822_parse_headers_basic.phpt @@ -4,13 +4,13 @@ imap_rfc822_parse_headers() function : basic functionality Olivier Doucet --SKIPIF-- --FILE-- --CLEAN-- --EXPECTF-- Create a temporary mailbox and add 1 msgs -.. mailbox '{%s}%s' created +New mailbox created Check general fields bool(true) bool(true) diff --git a/ext/imap/tests/imap_savebody_basic.phpt b/ext/imap/tests/imap_savebody_basic.phpt index ccbaa1ba66..38be6ab4a0 100644 --- a/ext/imap/tests/imap_savebody_basic.phpt +++ b/ext/imap/tests/imap_savebody_basic.phpt @@ -4,13 +4,13 @@ imap_savebody() function : basic functionality Olivier Doucet --SKIPIF-- --FILE-- --EXPECTF-- Create a temporary mailbox and add 1 msgs -.. mailbox '{127.0.0.1:143/norsh}INBOX.phpttest' created +New mailbox 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 f9618c3e3a..e449c3fdec 100644 --- a/ext/imap/tests/imap_timeout_basic.phpt +++ b/ext/imap/tests/imap_timeout_basic.phpt @@ -4,7 +4,7 @@ imap_timeout() function : basic functionality Olivier Doucet --SKIPIF-- --FILE-- --FILE-- --CLEAN-- ---EXPECTF-- +--EXPECT-- Create a temporary mailbox and add 1 msgs -.. mailbox '{%s}%s' created +New mailbox created bool(true) diff --git a/ext/imap/tests/imap_utf8.phpt b/ext/imap/tests/imap_utf8.phpt index a82c3721c3..522d4d6f56 100644 --- a/ext/imap/tests/imap_utf8.phpt +++ b/ext/imap/tests/imap_utf8.phpt @@ -11,8 +11,8 @@ var_dump(imap_utf8("test")); echo "Done\n"; ?> ---EXPECTF-- +--EXPECT-- string(0) "" string(1) "1" -string(4) "%s" +string(4) "test" Done diff --git a/ext/imap/tests/imap_utf8_to_mutf7_basic.phpt b/ext/imap/tests/imap_utf8_to_mutf7_basic.phpt index 8037ae9491..c0f3b06dc9 100644 --- a/ext/imap/tests/imap_utf8_to_mutf7_basic.phpt +++ b/ext/imap/tests/imap_utf8_to_mutf7_basic.phpt @@ -2,7 +2,6 @@ imap_utf8_to_mutf7 --SKIPIF-- - --FILE-- Nmsgs; $i++) { + imap_delete($imap_stream, $i); +} + +if (!isset($mailbox_suffix)) { throw new Exception("No suffix provided"); } + +$mailboxes = imap_getmailboxes($imap_stream, IMAP_SERVER, '*'); + +foreach($mailboxes as $value) { + // Only delete mailbox with our prefix (+ optional test suffix) + if (preg_match('/\{.*?\}INBOX\.' . IMAP_MAILBOX_PHPT_PREFIX . $mailbox_suffix .'/', $value->name, $match) == 1) { + imap_deletemailbox($imap_stream, $value->name); + } +} + +imap_close($imap_stream, CL_EXPUNGE); diff --git a/ext/imap/tests/dovecot.conf b/ext/imap/tests/setup/dovecot.conf similarity index 100% rename from ext/imap/tests/dovecot.conf rename to ext/imap/tests/setup/dovecot.conf diff --git a/ext/imap/tests/dovecotpass b/ext/imap/tests/setup/dovecotpass similarity index 100% rename from ext/imap/tests/dovecotpass rename to ext/imap/tests/setup/dovecotpass diff --git a/ext/imap/tests/imap_include.inc b/ext/imap/tests/setup/imap_include.inc similarity index 50% rename from ext/imap/tests/imap_include.inc rename to ext/imap/tests/setup/imap_include.inc index e57d651697..33e4e5ca16 100644 --- a/ext/imap/tests/imap_include.inc +++ b/ext/imap/tests/setup/imap_include.inc @@ -1,31 +1,34 @@ $mf; - if ($mf == 'udate') { - if (($z >= $start_time) && ($z <= time())) { - echo "$mf is OK\n"; - } else { - echo "$mf is BAD ($z)\n"; - } - } else { - echo "$mf is $z\n"; +function displayOverviewFields($resp, array $fields = MANDATORY_OVERVIEW_FIELDS) { + global $start_time; + foreach ($fields as $mf) { + $z = $resp->$mf; + if ($mf == 'udate') { + if (($z >= $start_time) && ($z <= time())) { + echo "$mf is OK\n"; + } else { + echo "$mf is BAD ($z)\n"; + } + } else { + echo "$mf is $z\n"; + } } - } } @@ -60,33 +61,27 @@ function displayOverviewFields($resp, $fields=null) { * * @param string mailbox_suffix Suffix used to uniquely identify mailboxes * @param int message_count number of test msgs to be written to new mailbox - * - * @return IMAP stream to new mailbox on success; FALSE on failure + * @param null $new_mailbox + * @param bool $simpleMessages + * @return resource IMAP stream to new mailbox + * @throws Exception */ -function setup_test_mailbox($mailbox_suffix, $message_count, &$new_mailbox = null, $msg_type = "simple"){ - global $server, $default_mailbox, $username, $password; - +function setup_test_mailbox(string $mailbox_suffix, int $message_count, &$new_mailbox = null, bool $simpleMessages = true){ // open a stream to default mailbox - $imap_stream = imap_open($default_mailbox, $username, $password); + $imap_stream = imap_open(IMAP_DEFAULT_MAILBOX, IMAP_MAILBOX_USERNAME, IMAP_MAILBOX_PASSWORD); if ($imap_stream === false) { - echo "Cannot connect to IMAP server $server: " . imap_last_error() . "\n"; - return false; + throw new Exception("Cannot connect to IMAP server " . IMAP_SERVER . ": " . imap_last_error()); } 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; - } + $new_mailbox = create_mailbox($imap_stream, $mailbox_suffix, $message_count, $simpleMessages); - echo ".. mailbox '$new_mailbox' created\n"; + echo "New mailbox created\n"; // 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; + throw new Exception("Can't re-open '$new_mailbox' mailbox: " . imap_last_error()); } return $imap_stream; @@ -96,11 +91,14 @@ function setup_test_mailbox($mailbox_suffix, $message_count, &$new_mailbox = nul * Create mailbox and fill with generic emails * * @param resource $imap_stream - * @param string $mailbox + * @param string $mailbox_suffix + * @param int $message_count + * @param bool $simpleMessages + * @return string + * @throws Exception */ -function create_mailbox($imap_stream, $mailbox_suffix, $message_count, $msg_type= "simple"){ - global $default_mailbox, $mailbox_prefix; - $mailbox = $default_mailbox . "." . $mailbox_prefix . $mailbox_suffix; +function create_mailbox($imap_stream, string $mailbox_suffix, int $message_count, bool $simpleMessages = true): string { + $mailbox = IMAP_DEFAULT_MAILBOX . '.' . IMAP_MAILBOX_PHPT_PREFIX . $mailbox_suffix; $mailboxes = imap_getmailboxes($imap_stream, $mailbox, '*'); @@ -108,18 +106,18 @@ function create_mailbox($imap_stream, $mailbox_suffix, $message_count, $msg_type if ($mailboxes) { foreach($mailboxes as $value) { if ($value->name == $mailbox) { - exit ("TEST FAILED : Mailbox '$mailbox' already exists\n"); + throw new Exception("Mailbox '$mailbox' already exists"); } } } if (imap_createmailbox($imap_stream, $mailbox) === false) { - return false; + throw new Exception("Can't create a temporary mailbox: " . imap_last_error()); } // Add number of test msgs requested if ($message_count > 0) { - populate_mailbox($imap_stream, $mailbox, $message_count, $msg_type); + populate_mailbox($imap_stream, $mailbox, $message_count, $simpleMessages); } return $mailbox; @@ -130,21 +128,20 @@ function create_mailbox($imap_stream, $mailbox_suffix, $message_count, $msg_type * * @param resource $imap_stream * @param string $mailbox + * @param int $message_count + * @param bool $simpleMessages */ -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") { +function populate_mailbox($imap_stream, string $mailbox, int $message_count, bool $simpleMessages = true): void { + for ($i = 1; $i <= $message_count; $i++) { + if ($simpleMessages) { $msg = "From: foo@anywhere.com\r\n" - . "To: $users[0]@$domain\r\n" + . "To: ". IMAP_USERS[0] . "@" . IMAP_MAIL_DOMAIN . "\r\n" . "Subject: test$i\r\n" . "\r\n" - . "$i: this is a test message, please ignore\r\n"; + . "$i: this is a test message, please ignore\r\nnewline"; } else { $envelope["from"]= "foo@anywhere.com"; - $envelope["to"] = "$users[0]@$domain"; + $envelope["to"] = IMAP_USERS[0] . "@" . IMAP_MAIL_DOMAIN; $envelope["subject"] = "Test msg $i"; $part1["type"] = TYPEMULTIPART; @@ -181,16 +178,13 @@ function populate_mailbox($imap_stream, $mailbox, $message_count, $msg_type = "s * Get the mailbox name from a mailbox description, i.e strip off server details. * * @param string mailbox complete mailbox name - * @return mailbox name + * @return string mailbox name */ -function get_mailbox_name($mailbox){ +function get_mailbox_name(string $mailboxName): string { - if (preg_match('/\{.*?\}(.*)/', $mailbox, $match) != 1) { - echo "Unrecpognized mailbox name\n"; - return false; + if (preg_match('/\{.*?\}(.*)/', $mailboxName, $match) != 1) { + throw new Exception("Unrecognized mailbox name '$mailboxName'"); } return $match[1]; } - -?> diff --git a/ext/imap/tests/setup.sh b/ext/imap/tests/setup/setup.sh similarity index 52% rename from ext/imap/tests/setup.sh rename to ext/imap/tests/setup/setup.sh index 5cb18334a3..efa7c30310 100644 --- a/ext/imap/tests/setup.sh +++ b/ext/imap/tests/setup/setup.sh @@ -1,6 +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 cp ext/imap/tests/setup/dovecot.conf /etc/dovecot/dovecot.conf +sudo cp ext/imap/tests/setup/dovecotpass /etc/dovecot/dovecotpass sudo service dovecot start diff --git a/ext/imap/tests/setup/skipif.inc b/ext/imap/tests/setup/skipif.inc new file mode 100644 index 0000000000..c7dc24efd7 --- /dev/null +++ b/ext/imap/tests/setup/skipif.inc @@ -0,0 +1,13 @@ +