]> granicus.if.org Git - php/commitdiff
Modernize IMAP tests
authorGeorge Peter Banyard <girgias@php.net>
Tue, 3 Nov 2020 09:49:18 +0000 (09:49 +0000)
committerGeorge Peter Banyard <girgias@php.net>
Tue, 3 Nov 2020 09:50:42 +0000 (09:50 +0000)
Use constants when appropriate, drop some ouputs which depends on env vars

Enable parallel testing.

Closes GH-6380

61 files changed:
azure/apt.yml
azure/setup.yml
ext/imap/tests/CONFLICTS [deleted file]
ext/imap/tests/README.md
ext/imap/tests/bug31142_2.phpt
ext/imap/tests/bug32589.phpt
ext/imap/tests/bug35669.phpt
ext/imap/tests/bug44098.phpt
ext/imap/tests/bug45705_1.phpt
ext/imap/tests/bug45705_2.phpt
ext/imap/tests/bug53377.phpt
ext/imap/tests/bug63126.phpt
ext/imap/tests/bug64076.phpt
ext/imap/tests/bug77020.phpt
ext/imap/tests/bug77153.phpt
ext/imap/tests/bug80213.phpt
ext/imap/tests/bug80226.phpt
ext/imap/tests/clean.inc [deleted file]
ext/imap/tests/imap_append_basic.phpt
ext/imap/tests/imap_body.phpt
ext/imap/tests/imap_body_basic.phpt
ext/imap/tests/imap_bodystruct_basic.phpt
ext/imap/tests/imap_clearflag_full_basic.phpt
ext/imap/tests/imap_close_basic.phpt
ext/imap/tests/imap_close_variation4.phpt
ext/imap/tests/imap_createmailbox_basic.phpt
ext/imap/tests/imap_errors_basic.phpt
ext/imap/tests/imap_fetch_overview_basic.phpt
ext/imap/tests/imap_fetch_overview_variation3.phpt
ext/imap/tests/imap_fetch_overview_variation5.phpt
ext/imap/tests/imap_fetch_overview_variation6.phpt
ext/imap/tests/imap_fetchbody_basic.phpt
ext/imap/tests/imap_fetchbody_variation4.phpt
ext/imap/tests/imap_fetchbody_variation6.phpt
ext/imap/tests/imap_fetchheader_basic.phpt
ext/imap/tests/imap_fetchheader_variation3.phpt
ext/imap/tests/imap_fetchheader_variation5.phpt
ext/imap/tests/imap_fetchstructure_basic.phpt
ext/imap/tests/imap_gc_error.phpt
ext/imap/tests/imap_getsubscribed_basic.phpt
ext/imap/tests/imap_headerinfo_basic.phpt
ext/imap/tests/imap_list_basic.phpt
ext/imap/tests/imap_lsub_basic.phpt
ext/imap/tests/imap_mail_copy_basic.phpt
ext/imap/tests/imap_mail_move_basic.phpt
ext/imap/tests/imap_mutf7_to_utf8.phpt
ext/imap/tests/imap_open_error.phpt
ext/imap/tests/imap_renamemailbox_basic.phpt
ext/imap/tests/imap_rfc822_parse_headers_basic.phpt
ext/imap/tests/imap_savebody_basic.phpt
ext/imap/tests/imap_timeout_basic.phpt
ext/imap/tests/imap_undelete_basic.phpt
ext/imap/tests/imap_utf8.phpt
ext/imap/tests/imap_utf8_to_mutf7_basic.phpt
ext/imap/tests/setup/clean.inc [new file with mode: 0644]
ext/imap/tests/setup/dovecot.conf [moved from ext/imap/tests/dovecot.conf with 100% similarity]
ext/imap/tests/setup/dovecotpass [moved from ext/imap/tests/dovecotpass with 100% similarity]
ext/imap/tests/setup/imap_include.inc [moved from ext/imap/tests/imap_include.inc with 50% similarity]
ext/imap/tests/setup/setup.sh [moved from ext/imap/tests/setup.sh with 52% similarity]
ext/imap/tests/setup/skipif.inc [new file with mode: 0644]
ext/imap/tests/skipif.inc [deleted file]

index 71f58ce8da2ade07d86c75e0330fe3208dca7e17..aa27d4a5513d546d7e34da985f64f7354031d580 100644 (file)
@@ -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'
index e0b4dc79da991fe2f3e4737c3599fee8f773134f..489df881596fb02c0894bdc711a50603501c2b74 100644 (file)
@@ -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 (file)
index c301c0f..0000000
+++ /dev/null
@@ -1 +0,0 @@
-imap
index 6324ab7f9e60b5820bc4e5d62f87e665c312ebe6..1dee1d2663cb02bdc34f5834c9de0ca97fd2351a 100644 (file)
@@ -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.
index 004c054963d287a075babd3d9f6f97df44bb4a7f..dbb4c9a6ad269111ada730ceef3194f3a333a1c0 100644 (file)
@@ -2,9 +2,7 @@
 Bug #31142 test #2 (imap_mail_compose() generates incorrect output)
 --SKIPIF--
 <?php
-        if (!extension_loaded("imap")) {
-                die("skip imap extension not available");
-        }
+extension_loaded('imap') or die('skip imap extension not available in this build');
 ?>
 --FILE--
 <?php
index 52a73c6f237b328a9d583a514d2f98ac7bcc97a1..ad49915018ae5084cab3b88873f6483d833d0006 100644 (file)
@@ -2,9 +2,7 @@
 Bug #32589 (crash inside imap_mail_compose() function)
 --SKIPIF--
 <?php
-        if (!extension_loaded("imap")) {
-                die("skip imap extension not available");
-        }
+extension_loaded('imap') or die('skip imap extension not available in this build');
 ?>
 --FILE--
 <?php
index fc7a135bcebba6f5ca41858cbc7e43616d893980..50da33a42d0bec0719c096675e7440b641502db1 100644 (file)
@@ -2,9 +2,7 @@
 Bug #35669 (imap_mail_compose() crashes with multipart-multiboundary-email)
 --SKIPIF--
 <?php
-        if (!extension_loaded("imap")) {
-                die("skip imap extension not available");
-        }
+extension_loaded('imap') or die('skip imap extension not available in this build');
 ?>
 --FILE--
 <?php
index 2a0f5cef44ab8d8cc4ec9a4b073c5ac891984ffc..2e0f025d6a494f5990aeca3df0280de1a999bd47 100644 (file)
@@ -2,19 +2,14 @@
 Bug #44098 (imap_utf8() returns only capital letters)
 --SKIPIF--
 <?php
-        if (!extension_loaded("imap")) {
-                die("skip imap extension not available");
-        }
+extension_loaded('imap') or die('skip imap extension not available in this build');
 ?>
 --FILE--
 <?php
 $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";
-} else {
-    echo "ok";
-}
+var_dump($res);
+
 ?>
 --EXPECT--
-ok
+string(17) "Luzon®14 dot CoM"
index 05d3a0a2f6b9de7c08aa091e7e1719f82fbecb99..b8d33e675839e2ced214dbc5a6ab55b0a45b8bbd 100644 (file)
@@ -2,9 +2,7 @@
 Bug #45705 test #1 (imap rfc822_parse_adrlist() modifies passed address parameter)
 --SKIPIF--
 <?php
-    if (!extension_loaded("imap")) {
-        die("skip imap extension not available");
-    }
+extension_loaded('imap') or die('skip imap extension not available in this build');
 ?>
 --FILE--
 <?php
index 97c4118614c5311a1a307b73eda0590f8b8e021d..a4e7828d1f76ce45c8db714e9bf97280613b5c05 100644 (file)
@@ -2,9 +2,7 @@
 Bug #45705 test #2 (imap rfc822_parse_adrlist() modifies passed address parameter)
 --SKIPIF--
 <?php
-    if (!extension_loaded("imap")) {
-        die("skip imap extension not available");
-    }
+extension_loaded('imap') or die('skip imap extension not available in this build');
 ?>
 --FILE--
 <?php
index a5073690461304e3897ab77c57fa98fb8519431b..083d951c20ca591d0a44025fa93a0fb7c7018bba 100644 (file)
@@ -2,9 +2,7 @@
 Bug #53377 (imap_mime_header_decode() doesn't ignore \t during long MIME header unfolding)
 --SKIPIF--
 <?php
-        if (!extension_loaded("imap")) {
-                die("skip imap extension not available");
-        }
+extension_loaded('imap') or die('skip imap extension not available in this build');
 ?>
 --FILE--
 <?php
index 8eea34cf1d197e27bd904457f1792245b29c0f0d..8297b509ae61e9f79aee03deb6225815ae94d897 100644 (file)
@@ -4,11 +4,11 @@ imap_open() DISABLE_AUTHENTICATOR ignores array param
 <?php
 extension_loaded('imap') or die('skip imap extension not available in this build');
 
-require_once(__DIR__.'/imap_include.inc');
+require_once(__DIR__. '/setup/imap_include.inc');
 
-$in = @imap_open($default_mailbox, $username, $password, OP_HALFOPEN, 1);
+$in = @imap_open(IMAP_SERVER_DEBUG, IMAP_MAILBOX_USERNAME, IMAP_MAILBOX_PASSWORD, OP_HALFOPEN, 1);
 if (!$in) {
-    die("skip could not connect to mailbox $default_mailbox");
+    die("skip could not connect to mailbox " . IMAP_SERVER_DEBUG);
 }
 $kerberos = false;
 if (is_array($errors = imap_errors())) {
@@ -22,16 +22,19 @@ if (!$kerberos) {
     die("skip need a GSSAPI/Kerberos aware server");
 }
 ?>
+--CONFLICTS--
+defaultmailbox
 --FILE--
 <?php
+// TODO Test Kerberos on CI
 $tests = array(
     'Array'  => 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) {
index ccafcfe2513b7573004ec5a7681f1dfbd31c8813..7e9ee6fd04da27f43604c0f4020fa841d8f51847 100644 (file)
@@ -2,22 +2,23 @@
 Bug #64076 (imap_sort() does not return FALSE on failure)
 --SKIPIF--
 <?php
-require_once __DIR__ . '/skipif.inc';
+require_once __DIR__ . '/setup/skipif.inc';
 ?>
 --FILE--
 <?php
-require_once __DIR__ . '/imap_include.inc';
-$stream = setup_test_mailbox('', 2);
+require_once __DIR__ . '/setup/imap_include.inc';
+$stream = setup_test_mailbox('bug64076', 2);
 imap_errors(); // clear error stack
 var_dump(imap_sort($stream, SORTFROM, 0, 0, 'UNSUPPORTED SEARCH CRITERIUM'));
 var_dump(imap_errors() !== false);
 ?>
 --CLEAN--
 <?php
-require_once __DIR__ . '/clean.inc';
+$mailbox_suffix = 'bug64076';
+require_once(__DIR__ . '/setup/clean.inc');
 ?>
 --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)
index 43c8133700b73dd02703943e5c289753f1ebf7b1..d8286549830cba28f38f9f6c5d522d2723200208 100644 (file)
@@ -6,8 +6,8 @@ if (!extension_loaded('imap')) die('skip imap extension not available');
 ?>
 --FILE--
 <?php
-imap_mail('1', 1, NULL);
+@imap_mail('1', 1, NULL);
+echo 'done'
 ?>
 --EXPECTF--
-Warning: imap_mail(): No message string in mail command in %s on line %d
-%S
+%Adone
index 7b759621fe16f2f1125db5ed679c14a0c3cf9525..359923ca830262d39d381834f9f841013348ee43 100644 (file)
@@ -1,10 +1,8 @@
---TEST--                                 
+--TEST--
 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");
-        }
+extension_loaded('imap') or die('skip imap extension not available in this build');
 ?>
 --FILE--
 <?php
@@ -21,4 +19,4 @@ bool(false)
 --CLEAN--
 <?php
 if(file_exists(__DIR__ . '/__bug')) unlink(__DIR__ . '/__bug');
-?>
\ No newline at end of file
+?>
index 9a7961df776d721301507317426f65a4ca6417bf..5bad48f306d3964d624ccd0c6118f8a08f0bf317 100644 (file)
@@ -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
index 95ec23517851a0d231ed93d317083e0378c4419b..36dd97cf6ac373ce04fc30db12c125a8ff1744e3 100644 (file)
@@ -2,12 +2,16 @@
 Bug #80226 (imap_sort() leaks sortpgm memory)
 --SKIPIF--
 <?php
-require_once(__DIR__.'/skipif.inc');
+require_once(__DIR__.'/setup/skipif.inc');
 ?>
+--CONFLICTS--
+defaultmailbox
 --FILE--
 <?php
-require_once(__DIR__.'/imap_include.inc');
-$stream = imap_open($default_mailbox, $username, $password);
-imap_sort($stream, SORTFROM, 0);
+require_once(__DIR__.'/setup/imap_include.inc');
+$stream = imap_open(IMAP_DEFAULT_MAILBOX, IMAP_MAILBOX_USERNAME, IMAP_MAILBOX_PASSWORD);
+var_dump(imap_sort($stream, SORTFROM, 0));
 ?>
 --EXPECT--
+array(0) {
+}
diff --git a/ext/imap/tests/clean.inc b/ext/imap/tests/clean.inc
deleted file mode 100644 (file)
index 8bc566b..0000000
+++ /dev/null
@@ -1,25 +0,0 @@
-<?php
-include_once(dirname(__FILE__) . '/imap_include.inc');
-
-$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);
-}
-
-$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);
-?>
index e75b452596e744cbe11db52ea81d2a364fc3c211..ab2e46886e8fef74f9ff355883439810b1c08280 100644 (file)
@@ -2,22 +2,19 @@
 Test imap_append() function : basic functionality
 --SKIPIF--
 <?php
-require_once(__DIR__.'/skipif.inc');
+require_once(__DIR__. '/setup/skipif.inc');
 ?>
 --FILE--
 <?php
 echo "*** Testing imap_append() : basic functionality ***\n";
 
-require_once(__DIR__.'/imap_include.inc');
+require_once(__DIR__. '/setup/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");
-}
+$imap_stream = setup_test_mailbox("imapappendbaisc", 0);
 
 $mb_details = imap_mailboxmsginfo($imap_stream);
-echo "Add a couple of msgs to new mailbox " . $mb_details->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--
 <?php
-require_once('clean.inc');
+$mailbox_suffix = 'imapappendbaisc';
+require_once(__DIR__ . '/setup/clean.inc');
 ?>
 --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
index 6c2f6293984ca1750cea05a82e7530038d190a6f..de07a5c5797702d0d66680141cca4d2f7aac0a77 100644 (file)
@@ -5,14 +5,17 @@ Paul Sohier
 #phptestfest utrecht
 --SKIPIF--
 <?php
-require_once(__DIR__.'/skipif.inc');
+require_once(__DIR__.'/setup/skipif.inc');
 ?>
+--CONFLICTS--
+# Might not be needed
+defaultmailbox
 --FILE--
 <?php
 
-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());
+require_once(__DIR__.'/setup/imap_include.inc');
+$stream_id = imap_open(IMAP_SERVER, IMAP_MAILBOX_USERNAME, IMAP_MAILBOX_PASSWORD) or
+    die("Cannot connect to mailbox ". IMAP_SERVER. ": " . imap_last_error());
 
 try {
     imap_body($stream_id,-1);
index 3034785a90f139125a5c728d049db1dfe1436f92..6a411bc9088b77ad06c03750afeb72c0e7a6a8e3 100644 (file)
@@ -2,16 +2,16 @@
 Test imap_body() function : basic functionality
 --SKIPIF--
 <?php
-require_once(__DIR__.'/skipif.inc');
+require_once(__DIR__.'/setup/skipif.inc');
 ?>
 --FILE--
 <?php
 echo "*** Testing imap_body() : basic functionality ***\n";
 
-require_once(__DIR__.'/imap_include.inc');
+require_once(__DIR__.'/setup/imap_include.inc');
 
 echo "Create a new mailbox for test\n";
-$imap_stream = setup_test_mailbox("", 1);
+$imap_stream = setup_test_mailbox("imapbodybasic", 1);
 if (!is_resource($imap_stream)) {
     exit("TEST FAILED: Unable to create test mailbox\n");
 }
@@ -29,15 +29,16 @@ imap_close($imap_stream);
 ?>
 --CLEAN--
 <?php
-require_once('clean.inc');
+$mailbox_suffix = 'imapbodybasic';
+require_once __DIR__.'/setup/clean.inc';
 ?>
 --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"
index 56c88399c35f9deb8371e7e5828e0080f5999f8d..5670fc4ad18a79ac8ce199a3669455422e7d2982 100644 (file)
@@ -2,15 +2,15 @@
 Test imap_bodystruct() function : basic functionality
 --SKIPIF--
 <?php
-require_once(__DIR__.'/skipif.inc');
+require_once(__DIR__.'/setup/skipif.inc');
 ?>
 --FILE--
 <?php
 echo "*** Testing string imap_bodystruct : basic functionality ***\n";
-require_once(__DIR__.'/imap_include.inc');
+require_once(__DIR__.'/setup/imap_include.inc');
 
 echo "Create a new mailbox for test and add a multipart msgs\n";
-$imap_stream = setup_test_mailbox("", 1, $mailbox, "multipart");
+$imap_stream = setup_test_mailbox("imapbodystructbasic", 1, $mailbox, "multipart");
 if (!is_resource($imap_stream)) {
     exit("TEST FAILED: Unable to create test mailbox\n");
 }
@@ -65,13 +65,14 @@ return $result;
 ?>
 --CLEAN--
 <?php
-require_once('clean.inc');
+$mailbox_suffix = 'imapbodystructbasic';
+require_once(__DIR__ . '/setup/clean.inc');
 ?>
---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
index cc949385fc1d216c8ba8fe61c527e390f4edf1e8..bcf168b18b29d9d42249bd2862a86080712452da 100644 (file)
@@ -2,16 +2,16 @@
 Test imap_clearflag_full() function : basic functionality
 --SKIPIF--
 <?php
-require_once(__DIR__.'/skipif.inc');
+require_once(__DIR__.'/setup/skipif.inc');
 ?>
 --FILE--
 <?php
 echo "*** Testing imap_clearflag_full() : basic functionality ***\n";
 
-require_once(__DIR__.'/imap_include.inc');
+require_once(__DIR__.'/setup/imap_include.inc');
 
 echo "Create a new mailbox for test\n";
-$imap_stream = setup_test_mailbox("", 10);
+$imap_stream = setup_test_mailbox("imapclearflagfullbasic", 10);
 if (!is_resource($imap_stream)) {
     exit("TEST FAILED: Unable to create test mailbox\n");
 }
@@ -44,13 +44,14 @@ imap_close($imap_stream);
 ?>
 --CLEAN--
 <?php
-require_once('clean.inc');
+$mailbox_suffix = 'imapclearflagfullbasic';
+require_once(__DIR__ . '/setup/clean.inc');
 ?>
---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)
index 57b2e7eab19a09d5dbc693d8304aa4030b200e5f..c962b62f7f8e09c3a6bbdb9453de145be1e194cc 100644 (file)
@@ -2,17 +2,17 @@
 Test imap_close() function : basic functionality
 --SKIPIF--
 <?php
-require_once(__DIR__.'/skipif.inc');
+require_once(__DIR__.'/setup/skipif.inc');
 ?>
 --FILE--
 <?php
 echo "*** Testing imap_close() : basic functionality ***\n";
 
 // include file for required variables in imap_open()
-require_once(__DIR__.'/imap_include.inc');
+require_once(__DIR__.'/setup/imap_include.inc');
 
 // Initialize required variables
-$stream_id = setup_test_mailbox('', 3, $mailbox); // set up temp mailbox with 3 messages
+$stream_id = setup_test_mailbox('imapclosebasic', 3, $mailbox); // set up temp mailbox with 3 messages
 $options = CL_EXPUNGE;
 
 // mark messages in inbox for deletion
@@ -25,7 +25,7 @@ echo "\n-- Call to imap_close() with all possible arguments --\n";
 var_dump( imap_close($stream_id, $options) );
 
 // check that CL_EXPUNGE worked
-$stream_id = imap_open($mailbox, $username, $password);
+$stream_id = imap_open($mailbox, IMAP_MAILBOX_USERNAME, IMAP_MAILBOX_PASSWORD);
 echo "There are now " . imap_num_msg($stream_id) . " msgs in mailbox '$mailbox'\n";
 
 // Calling imap_close() with mandatory arguments
@@ -34,16 +34,17 @@ var_dump( imap_close($stream_id) );
 ?>
 --CLEAN--
 <?php
-require_once(__DIR__.'/clean.inc');
+$mailbox_suffix = 'imapclosebasic';
+require_once(__DIR__.'/setup/clean.inc');
 ?>
 --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)
index b57f607f88ede36ea59fbce421e3924715a80c24..cf6f72873a9de90a29cf25ac56ce744b1b5cd6e1 100644 (file)
@@ -2,8 +2,11 @@
 Test imap_close() function : usage variations - different ints as $flags arg
 --SKIPIF--
 <?php
-require_once(__DIR__.'/skipif.inc');
+require_once(__DIR__.'/setup/skipif.inc');
 ?>
+--CONFLICTS--
+# It should be possible to use a custom mailbox instead of conflicting with the default one
+defaultmailbox
 --FILE--
 <?php
 /*
@@ -13,11 +16,11 @@ require_once(__DIR__.'/skipif.inc');
 
 echo "*** Testing imap_close() : usage variations ***\n";
 
-require_once(__DIR__.'/imap_include.inc');
+require_once(__DIR__.'/setup/imap_include.inc');
 
 $inputs = array (0, 3.2768e4, -32768, PHP_INT_MAX, -PHP_INT_MAX);
 
-$stream_id = setup_test_mailbox('', 3, $mailbox); // set up temp mailbox with 3 messages
+$stream_id = setup_test_mailbox('imapclosevar4', 3, $mailbox); // set up temp mailbox with 3 messages
 
 // loop through each element of $inputs to check the behavior of imap_close()
 $iterator = 1;
@@ -40,7 +43,7 @@ foreach($inputs as $input) {
         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);
+        $imap_stream = imap_open($mailbox, IMAP_MAILBOX_USERNAME, IMAP_MAILBOX_PASSWORD);
         $num_msg = imap_num_msg($imap_stream);
         if ($num_msg != 0) {
             echo "CL_EXPUNGE was not set, $num_msg msgs in mailbox\n";
@@ -53,19 +56,20 @@ foreach($inputs as $input) {
     $iterator++;
 
     // get $stream_id for next iteration
-    $stream_id = imap_open($mailbox, $username, $password);
+    $stream_id = imap_open($mailbox, IMAP_MAILBOX_USERNAME, IMAP_MAILBOX_PASSWORD);
     populate_mailbox($stream_id, $mailbox, 3);
 
 };
 ?>
 --CLEAN--
 <?php
-require_once(__DIR__.'/clean.inc');
+$mailbox_suffix = 'imapclosevar4';
+require_once(__DIR__.'/setup/clean.inc');
 ?>
---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)
index 84db5cbd31a4902c86cd6e71869f4cb3c357146f..691b535630050cdd36144fb68f8b3d52e8564c72 100644 (file)
@@ -2,22 +2,24 @@
 Test imap_createmailbox() function : basic functionality
 --SKIPIF--
 <?php
-require_once(__DIR__.'/skipif.inc');
+require_once __DIR__.'/setup/skipif.inc';
 ?>
+--CONFLICTS--
+defaultmailbox
 --FILE--
 <?php
 echo "*** Testing imap_createmailbox() : basic functionality ***\n";
 
-require_once(__DIR__.'/imap_include.inc');
+require_once __DIR__.'/setup/imap_include.inc';
 
-$imap_stream = imap_open($default_mailbox, $username, $password) or
-    die("Cannot connect to mailbox $default_mailbox: " . imap_last_error());
+$imap_stream = imap_open(IMAP_DEFAULT_MAILBOX, IMAP_MAILBOX_USERNAME, IMAP_MAILBOX_PASSWORD) or
+    die("Cannot connect to mailbox ". IMAP_DEFAULT_MAILBOX. ": " . imap_last_error());
 
 $newname = "phpnewbox";
 
 echo "Newname will be '$newname'\n";
 
-$newbox = imap_utf7_encode($server.$newname);
+$newbox = imap_utf7_encode(IMAP_SERVER.$newname);
 if (imap_createmailbox($imap_stream, $newbox)) {
 
     echo "Add a couple of msgs to '$newname' mailbox\n";
@@ -48,6 +50,11 @@ if (imap_createmailbox($imap_stream, $newbox)) {
 
 imap_close($imap_stream);
 
+?>
+--CLEAN--
+<?php
+$mailbox_suffix = '';
+require_once __DIR__ . '/setup/clean.inc';
 ?>
 --EXPECTF--
 *** Testing imap_createmailbox() : basic functionality ***
index c89719376658d53a5896bf3eebc457944e94c58b..f691a5c70521b6e9fea7d9e6c96e47e9c94f9ac0 100644 (file)
@@ -2,16 +2,16 @@
 Test imap_errors() function : invalid password
 --SKIPIF--
 <?php
-require_once(__DIR__.'/skipif.inc');
+require_once __DIR__.'/setup/skipif.inc';
 ?>
 --FILE--
 <?php
 echo "*** Testing imap_errors() : invalid password ***\n";
-require_once(__DIR__.'/imap_include.inc');
+require_once __DIR__.'/setup/imap_include.inc';
 $password = "bogus"; // invalid password to use in this test
 
 echo "Issue opening with invalid password, 1 retry\n";
-$mbox = imap_open($default_mailbox, $username, $password, OP_READONLY, 1);
+$mbox = imap_open(IMAP_DEFAULT_MAILBOX, IMAP_MAILBOX_USERNAME, $password, OP_READONLY, 1);
 
 echo "List any errors\n";
 var_dump(imap_errors());
index a9fe85c45e9d8a8bf26d25e3e62b923aaa73e68a..4b294b06fc990b9f3ac6c3feb26a7b0783691665 100644 (file)
@@ -2,16 +2,18 @@
 Test imap_fetch_overview() function : basic functionality
 --SKIPIF--
 <?php
-require_once(__DIR__.'/skipif.inc');
+require_once(__DIR__.'/setup/skipif.inc');
 ?>
+--CONFLICTS--
+defaultmailbox
 --FILE--
 <?php
 echo "*** Testing imap_fetch_overview() : basic functionality ***\n";
 
-require_once(__DIR__.'/imap_include.inc');
+require_once __DIR__.'/setup/imap_include.inc';
 
 // create a new mailbox and add two new messages to it
-$stream_id = setup_test_mailbox('', 2, $mailbox, 'notSimple');
+$stream_id = setup_test_mailbox('', 2, $mailbox, false);
 
 // get UID for new message
 $msg_no = imap_uid($stream_id, 1);
@@ -40,12 +42,13 @@ imap_close($stream_id);
 ?>
 --CLEAN--
 <?php
-require_once(__DIR__.'/clean.inc');
+$mailbox_suffix = '';
+require_once __DIR__.'/setup/clean.inc';
 ?>
 --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 --
 
index f4168873887c2abe1509c04eb327123fd77abffa..ada23d4f2aecd15984c86129211977a4565b8fd6 100644 (file)
@@ -2,8 +2,10 @@
 Test imap_fetch_overview() function : usage variations - FT_UID option
 --SKIPIF--
 <?php
-require_once(__DIR__.'/skipif.inc');
+require_once(__DIR__.'/setup/skipif.inc');
 ?>
+--CONFLICTS--
+defaultmailbox
 --FILE--
 <?php
 /*
@@ -14,19 +16,20 @@ require_once(__DIR__.'/skipif.inc');
 
 echo "*** Testing imap_fetch_overview() : usage variations ***\n";
 
-require_once(__DIR__.'/imap_include.inc');
+require_once __DIR__.'/setup/imap_include.inc';
 
 // Initialise required variables
 $stream_id = setup_test_mailbox('', 1); // set up temporary mailbox with one simple message
 $msg_no = 1;
 $msg_uid = imap_uid($stream_id, $msg_no);
 
-$flags = array ('1',
-                  true,
-                  1.000000000000001,
-                  0.00001e5,
-                  245
-                 );
+$flags = [
+    '1',
+    true,
+    1.000000000000001,
+    0.00001e5,
+    245,
+];
 
 imap_check($stream_id);
 foreach($flags as $option) {
@@ -45,12 +48,13 @@ foreach($flags as $option) {
 ?>
 --CLEAN--
 <?php
-require_once(__DIR__.'/clean.inc');
+$mailbox_suffix = '';
+require_once(__DIR__.'/setup/clean.inc');
 ?>
---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
index 9774e682c1afcf0a6b907257002d06fd6a274926..00c7602a23c3f52559a2e94256c80bad7620aa2d 100644 (file)
@@ -2,8 +2,10 @@
 Test imap_fetch_overview() function : usage variations - $msg_no argument
 --SKIPIF--
 <?php
-require_once(__DIR__.'/skipif.inc');
+require_once(__DIR__.'/setup/skipif.inc');
 ?>
+--CONFLICTS--
+defaultmailbox
 --FILE--
 <?php
 /*
@@ -12,25 +14,31 @@ require_once(__DIR__.'/skipif.inc');
  */
 
 echo "*** Testing imap_fetch_overview() : usage variations ***\n";
-require_once(__DIR__.'/imap_include.inc');
+require_once __DIR__.'/setup/imap_include.inc';
 
-$stream_id = setup_test_mailbox('', 3, $mailbox, 'notSimple'); // set up temp mailbox with 3 msgs
+$stream_id = setup_test_mailbox('', 3, $mailbox, false); // set up temp mailbox with 3 msgs
 
-$sequences = array (0,     4,     '4', // out of range
-                    '2',   '1,3', '1, 2',
-                    '1:3'); // pass uid without setting FT_UID option
+$sequences = [
+    0,
+    4, // out of range
+    '4', // out of range
+    '2',
+    '1,3',
+    '1, 2',
+    '1:3', // pass uid without setting FT_UID option
+];
 
-foreach($sequences as $msg_no) {
+foreach ($sequences as $msg_no) {
     echo "\n-- \$msg_no is $msg_no --\n";
-        $overview = imap_fetch_overview($stream_id, $msg_no);
+    $overview = imap_fetch_overview($stream_id, $msg_no);
     if (!$overview) {
         echo imap_last_error() . "\n";
-        } else {
+    } else {
         foreach($overview as $ov) {
             echo "\n";
             displayOverviewFields($ov);
-             }
         }
+    }
 }
 
 // clear error stack
@@ -38,12 +46,13 @@ imap_errors();
 ?>
 --CLEAN--
 <?php
-require_once(__DIR__.'/clean.inc');
+$mailbox_suffix = '';
+require_once(__DIR__.'/setup/clean.inc');
 ?>
 --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
index 256f6310820b9f38b2b591ea56003c9d1e0ea353..a779c2546062cee1307f224c751b5fa743644bbf 100644 (file)
@@ -2,8 +2,10 @@
 Test imap_fetch_overview() function : usage variations - multipart message
 --SKIPIF--
 <?php
-require_once(__DIR__.'/skipif.inc');
+require_once(__DIR__.'/setup/skipif.inc');
 ?>
+--CONFLICTS--
+defaultmailbox
 --FILE--
 <?php
 /*
@@ -12,7 +14,7 @@ require_once(__DIR__.'/skipif.inc');
 
 echo "*** Testing imap_fetch_overview() : usage variations ***\n";
 
-require_once(__DIR__.'/imap_include.inc');
+require_once __DIR__.'/setup/imap_include.inc';
 
 $stream_id = setup_test_mailbox('', 0, $mailbox); // setup temp mailbox
 create_multipart_message($stream_id, $mailbox);
@@ -37,7 +39,7 @@ displayOverviewFields($a[0]);
 function create_multipart_message($imap_stream, $mailbox) {
     global $users, $domain;
     $envelope["from"]= "foo@anywhere.com";
-    $envelope["to"]  = "$users[0]@$domain";
+    $envelope["to"]  = IMAP_USERS[0] . '@' . IMAP_MAIL_DOMAIN;
     $envelope["subject"] = "Test msg 1";
 
     $part1["type"] = TYPEMULTIPART;
@@ -82,12 +84,13 @@ function create_multipart_message($imap_stream, $mailbox) {
 ?>
 --CLEAN--
 <?php
-require_once(__DIR__.'/clean.inc');
+$mailbox_suffix = '';
+require_once(__DIR__.'/setup/clean.inc');
 ?>
 --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
index 3c16f939c8fb3a31d51894038c77561c80609f7f..c07813ef7b401df83196859f7f518a0f19a4cebe 100644 (file)
@@ -2,8 +2,10 @@
 Test imap_fetchbody() function : basic functionality
 --SKIPIF--
 <?php
-require_once(__DIR__.'/skipif.inc');
+require_once(__DIR__.'/setup/skipif.inc');
 ?>
+--CONFLICTS--
+defaultmailbox
 --FILE--
 <?php
 /*           [, int $options])
@@ -12,12 +14,12 @@ require_once(__DIR__.'/skipif.inc');
  */
 
 echo "*** Testing imap_fetchbody() : basic functionality ***\n";
-require_once(__DIR__.'/imap_include.inc');
+require_once(__DIR__.'/setup/imap_include.inc');
 
 // Initialise all required variables
 
 // set up mailbox with one message
-$stream_id = setup_test_mailbox('', 1, $mailbox, 'notSimple');
+$stream_id = setup_test_mailbox('', 1, $mailbox, false);
 
 $msg_no = 1;
 $section = '2';
@@ -57,12 +59,13 @@ var_dump( $overview[0]->seen );
 ?>
 --CLEAN--
 <?php
-require_once(__DIR__.'/clean.inc');
+$mailbox_suffix = '';
+require_once(__DIR__.'/setup/clean.inc');
 ?>
 --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 --
index df5d8956706eab8979ea0b6a31d9ccbf2875a89a..5e25dd1126b4f80fc641b20ccdcd1818d8d6e72c 100644 (file)
@@ -2,7 +2,7 @@
 Test imap_fetchbody() function : usage variations - FT_UID option
 --SKIPIF--
 <?php
-require_once(__DIR__.'/skipif.inc');
+require_once(__DIR__.'/setup/skipif.inc');
 ?>
 --FILE--
 <?php
@@ -13,10 +13,10 @@ require_once(__DIR__.'/skipif.inc');
  */
 echo "*** Testing imap_fetchbody() : usage variations ***\n";
 
-require_once(__DIR__.'/imap_include.inc');
+require_once(__DIR__.'/setup/imap_include.inc');
 
 // Initialise required variables
-$stream_id = setup_test_mailbox('', 1); // set up temporary mailbox with one simple message
+$stream_id = setup_test_mailbox('imapfetchbodyvar4', 1); // set up temporary mailbox with one simple message
 $msg_no = 1;
 $msg_uid = imap_uid($stream_id, $msg_no);
 $section = 1;
@@ -47,12 +47,13 @@ foreach($flags as $option) {
 ?>
 --CLEAN--
 <?php
-require_once(__DIR__.'/clean.inc');
+$mailbox_suffix = 'imapfetchbodyvar4';
+require_once(__DIR__.'/setup/clean.inc');
 ?>
---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
index 8b3d73540a2c41c27df0150ba9c538f8ff574a85..7889c40193342cd5fa2fe79b8e70cc8371ae2d72 100644 (file)
@@ -2,7 +2,7 @@
 Test imap_fetchbody() function : usage variations - $message_num arg
 --SKIPIF--
 <?php
-require_once(__DIR__.'/skipif.inc');
+require_once(__DIR__.'/setup/skipif.inc');
 ?>
 --FILE--
 <?php
@@ -13,10 +13,10 @@ require_once(__DIR__.'/skipif.inc');
 
 echo "*** Testing imap_fetchbody() : usage variations ***\n";
 
-require_once(__DIR__.'/imap_include.inc');
+require_once(__DIR__.'/setup/imap_include.inc');
 
 //Initialise required variables
-$stream_id = setup_test_mailbox('', 3); // set up temp mailbox with  simple msgs
+$stream_id = setup_test_mailbox('imapfetchbodyvar6', 3); // set up temp mailbox with  simple msgs
 $section = 1;
 
 $sequences = [0, /* out of range */ 4, 1];
@@ -32,12 +32,13 @@ foreach($sequences as $message_num) {
 ?>
 --CLEAN--
 <?php
-require_once(__DIR__.'/clean.inc');
+$mailbox_suffix = 'imapfetchbodyvar6';
+require_once(__DIR__.'/setup/clean.inc');
 ?>
 --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"
index 44f7de5a393a6f4809a35526976e130c30bf28a1..dc934e00cf2744c246ee959c9efee7bfdecf90e2 100644 (file)
@@ -2,15 +2,15 @@
 Test imap_fetchheader() function : basic function
 --SKIPIF--
 <?php
-require_once(__DIR__.'/skipif.inc');
+require_once(__DIR__.'/setup/skipif.inc');
 ?>
 --FILE--
 <?php
 echo "*** Testing imap_fetchheader() : basic functionality ***\n";
-require_once(__DIR__.'/imap_include.inc');
+require_once(__DIR__.'/setup/imap_include.inc');
 
 // Initialise all required variables
-$stream_id = setup_test_mailbox('', 1, $mailbox, 'multiPart'); // setup temp mailbox with 1 msg
+$stream_id = setup_test_mailbox('imapfetchheaderbasic', 1, $mailbox, false); // setup temp mailbox with 1 msg
 $msg_no = 1;
 $options = array('FT_UID' => FT_UID, 'FT_INTERNAL' => FT_INTERNAL,
                  'FT_PREFETCHTEXT' => FT_PREFETCHTEXT);
@@ -33,12 +33,13 @@ var_dump( imap_fetchheader($stream_id, $msg_no) );
 ?>
 --CLEAN--
 <?php
-require_once(__DIR__.'/clean.inc');
+$mailbox_suffix = 'imapfetchheaderbasic';
+require_once(__DIR__.'/setup/clean.inc');
 ?>
 --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 --
index a457db0491cdb52b3cd323081055026169a09f2c..1289087b7d4a612c3f881b9c25f4366d0cc69698 100644 (file)
@@ -2,7 +2,7 @@
 Test imap_fetchheader() function : usage variations - FT_UID option
 --SKIPIF--
 <?php
-require_once(__DIR__.'/skipif.inc');
+require_once(__DIR__.'/setup/skipif.inc');
 ?>
 --FILE--
 <?php
@@ -14,10 +14,10 @@ require_once(__DIR__.'/skipif.inc');
 
 echo "*** Testing imap_fetchheader() : usage variations ***\n";
 
-require_once(__DIR__.'/imap_include.inc');
+require_once(__DIR__.'/setup/imap_include.inc');
 
 // Initialise required variables
-$stream_id = setup_test_mailbox('', 1); // set up temporary mailbox with one simple message
+$stream_id = setup_test_mailbox('imapfetchheadervar3', 1); // set up temporary mailbox with one simple message
 $msg_no = 1;
 $msg_uid = imap_uid($stream_id, $msg_no);
 
@@ -44,12 +44,13 @@ foreach($flags as $option) {
 ?>
 --CLEAN--
 <?php
-require_once(__DIR__.'/clean.inc');
+$mailbox_suffix = 'imapfetchheadervar3';
+require_once(__DIR__ . '/setup/clean.inc');
 ?>
---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
index cb00986a06ff3d0d22e28f2980421ee76e274c33..eb6493017b721a32a611223a1baabfa2edd8ca69 100644 (file)
@@ -2,7 +2,7 @@
 Test imap_fetchheader() function : usage variations - $message_num argument
 --SKIPIF--
 <?php
-require_once(__DIR__.'/skipif.inc');
+require_once(__DIR__.'/setup/skipif.inc');
 ?>
 --FILE--
 <?php
@@ -13,9 +13,9 @@ require_once(__DIR__.'/skipif.inc');
 
 echo "*** Testing imap_fetchheader() : usage variations ***\n";
 
-require_once(__DIR__.'/imap_include.inc');
+require_once(__DIR__.'/setup/imap_include.inc');
 
-$stream_id = setup_test_mailbox('', 3, $mailbox, 'notSimple'); // set up temp mailbox with 3 msgs
+$stream_id = setup_test_mailbox('imapfetchheadervar5', 3, $mailbox, false); // set up temp mailbox with 3 msgs
 
 $sequences = [0, /* out of range */ 4, 1];
 
@@ -33,12 +33,13 @@ imap_errors();
 ?>
 --CLEAN--
 <?php
-require_once(__DIR__.'/clean.inc');
+$mailbox_suffix = 'imapfetchheadervar5';
+require_once(__DIR__.'/setup/clean.inc');
 ?>
 --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
index 24cd2307dd5af16e3859f3c1d841129469d584ed..2eb730c8902da1caf4800455af7ea4aa92f1445a 100644 (file)
@@ -4,13 +4,13 @@ imap_fetchstructure() function : basic functionality
 Olivier Doucet
 --SKIPIF--
 <?php
-require_once(__DIR__.'/skipif.inc');
+require_once(__DIR__.'/setup/skipif.inc');
 ?>
 --FILE--
 <?php
 
-require_once(__DIR__.'/imap_include.inc');
-$stream_id = setup_test_mailbox('', 1);
+require_once(__DIR__.'/setup/imap_include.inc');
+$stream_id = setup_test_mailbox('imapfetchstructurebasic', 1);
 
 try {
     imap_fetchstructure($stream_id,0);
@@ -38,11 +38,12 @@ imap_close($stream_id);
 ?>
 --CLEAN--
 <?php
-require_once('clean.inc');
+$mailbox_suffix = 'imapfetchstructurebasic';
+require_once('setup/clean.inc');
 ?>
 --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)
index 5b5b65d2714226907f3c84efa25ab21ade742ea9..81b4a4bab63f41a25109dfd16620ab008fa612cc 100644 (file)
@@ -1,18 +1,18 @@
 --TEST--
-imap_gc() incorrect parameter count
+imap_gc() ValueError
 --CREDITS--
 Paul Sohier
 #phptestfest utrecht
 --SKIPIF--
 <?php
-require_once(__DIR__.'/skipif.inc');
+require_once(__DIR__.'/setup/skipif.inc');
 ?>
 --FILE--
 <?php
 
-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());
+require_once(__DIR__.'/setup/imap_include.inc');
+$stream_id = imap_open(IMAP_DEFAULT_MAILBOX, IMAP_MAILBOX_USERNAME, IMAP_MAILBOX_PASSWORD) or
+    die("Cannot connect to mailbox ". IMAP_DEFAULT_MAILBOX .": " . imap_last_error());
 
 try {
     imap_gc($stream_id, -1);
index 8e5d85383daef70b3bcca94186abc3f044c9b654..a1519042f134db19f6f6c928979bd6f66bced3f5 100644 (file)
@@ -4,27 +4,29 @@ imap_getsubscribed() function : basic functionality
 Olivier Doucet
 --SKIPIF--
 <?php
-require_once(__DIR__.'/skipif.inc');
+require_once(__DIR__.'/setup/skipif.inc');
 if (getenv("SKIP_ASAN")) die("skip asan chokes on this: 'LeakSanitizer does not work under ptrace (strace, gdb, etc)'");
 ?>
+--CONFLICTS--
+defaultmailbox
 --FILE--
 <?php
 
-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());
+require_once(__DIR__.'/setup/imap_include.inc');
+$stream_id = imap_open(IMAP_DEFAULT_MAILBOX, IMAP_MAILBOX_USERNAME, IMAP_MAILBOX_PASSWORD) or
+    die("Cannot connect to mailbox ". IMAP_DEFAULT_MAILBOX. ": " . imap_last_error());
 
-var_dump(imap_getsubscribed($stream_id,$default_mailbox,'ezDvfXvbvcxSerz'));
+var_dump(imap_getsubscribed($stream_id, IMAP_DEFAULT_MAILBOX, 'ezDvfXvbvcxSerz'));
 
 
 echo "Checking OK\n";
 
-$newbox = $default_mailbox . "." . $mailbox_prefix;
+$newbox = IMAP_DEFAULT_MAILBOX . "." . IMAP_MAILBOX_PHPT_PREFIX;
 
 imap_createmailbox($stream_id, $newbox);
 imap_subscribe($stream_id, $newbox);
 
-$z = imap_getsubscribed($stream_id,$default_mailbox,'*');
+$z = imap_getsubscribed($stream_id, IMAP_DEFAULT_MAILBOX, '*');
 
 var_dump(is_array($z));
 var_dump($z[0]);
@@ -33,7 +35,8 @@ imap_close($stream_id);
 ?>
 --CLEAN--
 <?php
-require_once('clean.inc');
+$mailbox_suffix = '';
+require_once(__DIR__ . '/setup/clean.inc');
 ?>
 --EXPECTF--
 bool(false)
index 056a46523c95aa679a8dcb9862e816ec4d3e61d7..0d84aee44bd252d12ce499183ccfe55d89d81d3a 100644 (file)
@@ -4,13 +4,13 @@ imap_headerinfo() function : basic functionality
 Olivier Doucet
 --SKIPIF--
 <?php
-require_once(__DIR__.'/skipif.inc');
+require_once(__DIR__.'/setup/skipif.inc');
 ?>
 --FILE--
 <?php
 
-require_once(__DIR__.'/imap_include.inc');
-$stream_id = setup_test_mailbox('', 1);
+require_once(__DIR__.'/setup/imap_include.inc');
+$stream_id = setup_test_mailbox('imapheaderinfobasic', 1);
 
 $z = imap_headerinfo($stream_id, 1);
 
@@ -85,11 +85,12 @@ imap_close($stream_id);
 ?>
 --CLEAN--
 <?php
-require_once('clean.inc');
+$mailbox_suffix = 'imapheaderinfobasic';
+require_once('setup/clean.inc');
 ?>
 --EXPECTF--
 Create a temporary mailbox and add 1 msgs
-.. mailbox '{%s}%s' created
+New mailbox created
 Check general fields
 bool(true)
 bool(true)
index addcf70e775ba88482e80895d26161dd17cabd7c..e11c6c1bd09f5e7d09a96b025ed7d2cc3e281ef9 100644 (file)
@@ -4,20 +4,22 @@ imap_list() function : basic functionality
 Olivier Doucet
 --SKIPIF--
 <?php
-require_once(__DIR__.'/skipif.inc');
+require_once(__DIR__.'/setup/skipif.inc');
 ?>
 --FILE--
 <?php
 
-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());
+require_once(__DIR__.'/setup/imap_include.inc');
+$stream_id = imap_open(IMAP_DEFAULT_MAILBOX, IMAP_MAILBOX_USERNAME, IMAP_MAILBOX_PASSWORD) or
+    die("Cannot connect to mailbox " .IMAP_DEFAULT_MAILBOX.": " . imap_last_error());
 
-imap_list($stream_id,$default_mailbox,'ezerz');
+imap_list($stream_id, IMAP_DEFAULT_MAILBOX,'ezerz');
 
 
-$z = imap_list($stream_id,$default_mailbox,'*');
+$z = imap_list($stream_id, IMAP_DEFAULT_MAILBOX,'*');
 var_dump(is_array($z));
+
+// e.g. "{127.0.0.1:143/norsh}INBOX"
 var_dump($z[0]);
 
 imap_close($stream_id);
index 3cd4722e1f6a1a2e8b05f9ca37d3b1cb8f936157..2fff7eeac8fe8703556d591c5283b3f432b59c85 100644 (file)
@@ -4,36 +4,41 @@ imap_lsub() function : basic functionality
 Olivier Doucet
 --SKIPIF--
 <?php
-require_once(__DIR__.'/skipif.inc');
+require_once(__DIR__.'/setup/skipif.inc');
 if (getenv("SKIP_ASAN")) die("skip leak sanitizer crashes");
 ?>
+--CONFLICTS--
+defaultmailbox
 --FILE--
 <?php
 
-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());
+require_once(__DIR__.'/setup/imap_include.inc');
+$stream_id = imap_open(IMAP_DEFAULT_MAILBOX, IMAP_MAILBOX_USERNAME, IMAP_MAILBOX_PASSWORD) or
+    die("Cannot connect to mailbox " .IMAP_DEFAULT_MAILBOX. ": " . imap_last_error());
 
-var_dump(imap_lsub($stream_id,$default_mailbox,'ezDvfXvbvcxSerz'));
+var_dump(imap_lsub($stream_id, IMAP_DEFAULT_MAILBOX, 'ezDvfXvbvcxSerz'));
 
 
 echo "Checking OK\n";
 
-$newbox = $default_mailbox . "." . $mailbox_prefix;
+$newbox = IMAP_DEFAULT_MAILBOX . "." . IMAP_MAILBOX_PHPT_PREFIX;
 
 imap_createmailbox($stream_id, $newbox);
 imap_subscribe($stream_id, $newbox);
 
-$z = imap_lsub($stream_id,$default_mailbox,'*');
+$z = imap_lsub($stream_id, IMAP_DEFAULT_MAILBOX, '*');
 
 var_dump(is_array($z));
+
+// e.g. "{127.0.0.1:143/norsh}INBOX.phpttest"
 var_dump($z[0]);
 
 imap_close($stream_id);
 ?>
 --CLEAN--
 <?php
-require_once('clean.inc');
+$mailbox_suffix = '';
+require_once(__DIR__.'/setup/clean.inc');
 ?>
 --EXPECTF--
 bool(false)
index 25725478a63a1e035d2a303329a671027a41dd9e..689f75667eca5a34efc786934f6f4d9d1619c981 100644 (file)
@@ -4,13 +4,15 @@ Test imap_mail_copy() function : basic functionality
 Olivier Doucet
 --SKIPIF--
 <?php
-require_once(__DIR__.'/skipif.inc');
+require_once(__DIR__.'/setup/skipif.inc');
 ?>
+--CONFLICTS--
+defaultmailbox
 --FILE--
 <?php
 echo "*** Testing imap_mail_copy() : basic functionality ***\n";
 
-require_once(__DIR__.'/imap_include.inc');
+require_once(__DIR__.'/setup/imap_include.inc');
 
 
 echo "Create a new mailbox for test\n";
@@ -22,18 +24,19 @@ if (!is_resource($imap_stream)) {
 $check = imap_check($imap_stream);
 echo "Msg Count in new mailbox: ". $check->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--
 <?php
-require_once('clean.inc');
+$mailbox_suffix = '';
+require_once('setup/clean.inc');
 ?>
---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)
index 3988951f12ee6581b32512cf3e6db116f03038bb..4c07c85a78c4401b935dcfa010f5667ee875de03 100644 (file)
@@ -4,13 +4,15 @@ Test imap_mail_move() function : basic functionality
 Olivier Doucet
 --SKIPIF--
 <?php
-require_once(__DIR__.'/skipif.inc');
+require_once(__DIR__.'/setup/skipif.inc');
 ?>
+--CONFLICTS--
+defaultmailbox
 --FILE--
 <?php
 echo "*** Testing imap_mail_move() : basic functionality ***\n";
 
-require_once(__DIR__.'/imap_include.inc');
+require_once(__DIR__.'/setup/imap_include.inc');
 
 
 echo "Create a new mailbox for test\n";
@@ -22,18 +24,19 @@ if (!is_resource($imap_stream)) {
 $check = imap_check($imap_stream);
 echo "Msg Count in new mailbox: ". $check->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--
 <?php
-require_once('clean.inc');
+$mailbox_suffix = '';
+require_once(__DIR__.'/setup/clean.inc');
 ?>
---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)
index f45361f4a90b21e3cf062c309afe7b64df1d3dc5..835a25428f0a482bf41e61051cf7023bb2cfb396 100644 (file)
@@ -2,7 +2,6 @@
 imap_mutf7_to_utf8
 --SKIPIF--
 <?php if (!extension_loaded("imap")) print "skip"; ?>
-<?php if (!function_exists("imap_mutf7_to_utf8")) print "skip"; ?>
 --FILE--
 <?php
 
index be1063fadc5433ed397dfef7b42e1c8068e51cd3..5ef4a2918d8d6a7dbcc10034e42519cce009890f 100644 (file)
@@ -5,7 +5,7 @@ Paul Sohier
 #phptestfest utrecht
 --SKIPIF--
 <?php
-require_once(__DIR__.'/skipif.inc');
+require_once(__DIR__.'/setup/skipif.inc');
 if (getenv("SKIP_ASAN")) die("skip leak sanitizer crashes");
 ?>
 --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;
 }
index c6b1812d165b5f35d7f4bb60826adffc43ad599e..f727f217291fc772596a839b73f6f53351b3b6b3 100644 (file)
@@ -4,20 +4,20 @@ imap_renamemailbox() function : basic functionality
 Olivier Doucet
 --SKIPIF--
 <?php
-require_once(__DIR__.'/skipif.inc');
+require_once(__DIR__.'/setup/skipif.inc');
 ?>
 --FILE--
 <?php
 
-require_once(__DIR__.'/imap_include.inc');
+require_once(__DIR__.'/setup/imap_include.inc');
 
-$stream_id = setup_test_mailbox('', 1);
+$stream_id = setup_test_mailbox('imaprenamemailbox', 1);
 
 if (!is_resource($stream_id)) {
     exit("TEST FAILED: Unable to create test mailbox\n");
 }
 
-$newbox = $default_mailbox . "." . $mailbox_prefix;
+$newbox = IMAP_DEFAULT_MAILBOX . "." . IMAP_MAILBOX_PHPT_PREFIX;
 
 //commented because of bug #49901
 //$ancError = error_reporting(0);
@@ -34,11 +34,12 @@ imap_close($stream_id);
 ?>
 --CLEAN--
 <?php
-require_once('clean.inc');
+$mailbox_suffix = 'imaprenamemailbox';
+require_once('setup/clean.inc');
 ?>
---EXPECTF--
+--EXPECT--
 Create a temporary mailbox and add 1 msgs
-.. mailbox '{%s}%s' created
+New mailbox created
 Checking OK
 bool(true)
 bool(true)
index 87dc4aaf05b7585564797687df51eb0ab27f5536..fd2dfb939dc61bbf12747ee350d7084ccbcd06b3 100644 (file)
@@ -4,13 +4,13 @@ imap_rfc822_parse_headers() function : basic functionality
 Olivier Doucet
 --SKIPIF--
 <?php
-require_once(__DIR__.'/skipif.inc');
+require_once(__DIR__.'/setup/skipif.inc');
 ?>
 --FILE--
 <?php
 
-require_once(__DIR__.'/imap_include.inc');
-$stream_id = setup_test_mailbox('', 1);
+require_once(__DIR__.'/setup/imap_include.inc');
+$stream_id = setup_test_mailbox('imaprfc822parseheadersbasic', 1);
 
 $z = imap_headerinfo($stream_id, 1);
 
@@ -85,11 +85,12 @@ imap_close($stream_id);
 ?>
 --CLEAN--
 <?php
-require_once('clean.inc');
+$mailbox_suffix = 'imaprfc822parseheadersbasic';
+require_once(__DIR__ . '/setup/clean.inc');
 ?>
 --EXPECTF--
 Create a temporary mailbox and add 1 msgs
-.. mailbox '{%s}%s' created
+New mailbox created
 Check general fields
 bool(true)
 bool(true)
index ccbaa1ba66cc43184e2b0111856118443ab8d7f9..38be6ab4a054c530f053858505eeea30da1d9007 100644 (file)
@@ -4,13 +4,13 @@ imap_savebody() function : basic functionality
 Olivier Doucet
 --SKIPIF--
 <?php
-require_once(__DIR__.'/skipif.inc');
+require_once(__DIR__.'/setup/skipif.inc');
 ?>
 --FILE--
 <?php
 
-require_once(__DIR__.'/imap_include.inc');
-$stream_id = setup_test_mailbox('', 1);
+require_once(__DIR__.'/setup/imap_include.inc');
+$stream_id = setup_test_mailbox('imapsavebodybasic', 1);
 
 $file = __DIR__.'/tmpsavebody.txt';
 
@@ -31,11 +31,12 @@ imap_close($stream_id);
 --CLEAN--
 <?php
 @unlink(__DIR__.'/tmpsavebody.txt');
-require_once('clean.inc');
+$mailbox_suffix = 'imapsavebodybasic';
+require_once(__DIR__ . '/setup/clean.inc');
 ?>
 --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)
index f9618c3e3a33d908d346e784851311363b9a3bd4..e449c3fdecf00614e5d43a98cc7ed4ea97779905 100644 (file)
@@ -4,7 +4,7 @@ imap_timeout() function : basic functionality
 Olivier Doucet
 --SKIPIF--
 <?php
-require_once(__DIR__.'/skipif.inc');
+require_once(__DIR__.'/setup/skipif.inc');
 ?>
 --FILE--
 <?php
index 7cc9ff38476f32fcdefde77a0d2136a9e3f128d1..b792fd093eb7f012fc04fc32de495e92a44156ec 100644 (file)
@@ -4,13 +4,13 @@ imap_undelete() function : basic functionality
 Olivier Doucet
 --SKIPIF--
 <?php
-require_once(__DIR__.'/skipif.inc');
+require_once(__DIR__.'/setup/skipif.inc');
 ?>
 --FILE--
 <?php
 
-require_once(__DIR__.'/imap_include.inc');
-$stream_id = setup_test_mailbox('', 1);
+require_once(__DIR__.'/setup/imap_include.inc');
+$stream_id = setup_test_mailbox('imapundeletebasic', 1);
 
 imap_delete($stream_id, 1);
 
@@ -21,9 +21,10 @@ imap_close($stream_id);
 ?>
 --CLEAN--
 <?php
-require_once('clean.inc');
+$mailbox_suffix = 'imapundeletebasic';
+require_once(__DIR__ . '/setup/clean.inc');
 ?>
---EXPECTF--
+--EXPECT--
 Create a temporary mailbox and add 1 msgs
-.. mailbox '{%s}%s' created
+New mailbox created
 bool(true)
index a82c3721c350a3e9a79386ff71f02d940628209e..522d4d6f5608a97d3feb2a000fa5d976e7fb0842 100644 (file)
@@ -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
index 8037ae9491f0e2c4fb49e1bcbe54773490a0608b..c0f3b06dc9a346c67337c8dbe759ead04d94da15 100644 (file)
@@ -2,7 +2,6 @@
 imap_utf8_to_mutf7
 --SKIPIF--
 <?php if (!extension_loaded("imap")) print "skip imap extension not loaded"; ?>
-<?php if (!function_exists("imap_utf8_to_mutf7")) print "skip imap_utf8_to_mutf7() not available"; ?>
 --FILE--
 <?php
 
diff --git a/ext/imap/tests/setup/clean.inc b/ext/imap/tests/setup/clean.inc
new file mode 100644 (file)
index 0000000..d96b7f1
--- /dev/null
@@ -0,0 +1,23 @@
+<?php
+require_once 'imap_include.inc';
+
+$imap_stream = imap_open(IMAP_DEFAULT_MAILBOX, IMAP_MAILBOX_USERNAME, IMAP_MAILBOX_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);
+}
+
+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);
similarity index 50%
rename from ext/imap/tests/imap_include.inc
rename to ext/imap/tests/setup/imap_include.inc
index e57d6516979f20dea915877a034e42ca4e71fb55..33e4e5ca16f7f016fb8701d1bee9de0824da2607 100644 (file)
@@ -1,31 +1,34 @@
 <?php
-// Change these to make tests run successfully
-$server   = '{127.0.0.1:143/norsh}';
-$default_mailbox = $server . "INBOX";
-$domain = "something.com";
-$admin_user = "webmaster"; // a user with admin access
-$username = "$admin_user@$domain";
-$password = 'p4ssw0rd';
-$users = array("webmaster", "info", "admin", "foo"); // tests require 4 valid userids
-$mailbox_prefix = "phpttest"; // name used for test mailbox
+/** If required change these values to make the test runs */
+const IMAP_SERVER_NO_DEBUG = '{127.0.0.1:143/norsh}';
+const IMAP_SERVER_DEBUG = '{127.0.0.1:143/debug/norsh}';
+const IMAP_SERVER = IMAP_SERVER_DEBUG;
+const IMAP_DEFAULT_MAILBOX = IMAP_SERVER . 'INBOX';
+const IMAP_MAIL_DOMAIN = 'something.com';
+const IMAP_ADMIN_USER = 'webmaster'; // a user with admin access
+const IMAP_MAILBOX_USERNAME = IMAP_ADMIN_USER . '@' . IMAP_MAIL_DOMAIN;
+const IMAP_MAILBOX_PASSWORD = 'p4ssw0rd';
+const IMAP_MAILBOX_PHPT_PREFIX = 'phpttest';
+/** Tests require 4 valid userids */
+const IMAP_USERS = ["webmaster", "info", "admin", "foo"];
+
+/** list of fields to expect */
+const MANDATORY_OVERVIEW_FIELDS = [
+    'size',
+    'uid',
+    'msgno',
+    'recent',
+    'flagged',
+    'answered',
+    'deleted',
+    'seen',
+    'draft',
+    'udate',
+];
 
 // record test start time (used by displayOverviewFields())
 $start_time = time();
 
-// list of fields to expect
-$mandatory_overview_fields = array(
-                    'size',
-                    'uid',
-                    'msgno',
-                    'recent',
-                    'flagged',
-                    'answered',
-                    'deleted',
-                    'seen',
-                    'draft',
-                    'udate',
-                   );
-
 /**
  * Display all fields in an element from an imap_fetch_overview() response
  *
@@ -33,25 +36,23 @@ $mandatory_overview_fields = array(
  * server with its clock synced to the current system, which is consistent with
  * setup instructions in ext/imap/tests/README.md
  *
- * @param array resp element from the return value of imap_fetch_overview()
+ * @param $resp
+ * @param string[] $fields
  */
-function displayOverviewFields($resp, $fields=null) {
-  global $mandatory_overview_fields;
-  global $start_time;
-
-  foreach ($fields ? $fields : $mandatory_overview_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";
+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];
 }
-
-?>
similarity index 52%
rename from ext/imap/tests/setup.sh
rename to ext/imap/tests/setup/setup.sh
index 5cb18334a3f95906f418aff74210461dc6ef23bc..efa7c30310c6692050527e854e11201dc1aec74e 100644 (file)
@@ -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 (file)
index 0000000..c7dc24e
--- /dev/null
@@ -0,0 +1,13 @@
+<?php
+extension_loaded('imap') or die('skip imap extension not available in this build');
+
+include __DIR__ . '/imap_include.inc';
+
+$options = OP_HALFOPEN; // this should be enough to verify server present
+$retries = 0; // don't retry connect on failure
+
+$mbox = @imap_open(IMAP_SERVER, IMAP_MAILBOX_USERNAME, IMAP_MAILBOX_PASSWORD, $options, $retries);
+if (!$mbox) {
+    die("skip could not connect to mailbox " . IMAP_SERVER);
+}
+imap_close($mbox);
diff --git a/ext/imap/tests/skipif.inc b/ext/imap/tests/skipif.inc
deleted file mode 100644 (file)
index 2167ad1..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-<?php
-extension_loaded('imap') or die('skip imap extension not available in this build');
-
-// Change these to make tests run successfully
-$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
-$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");
-}
-imap_close($mbox);
-?>