added some mail tests. Tested on windows, linux and linux 64bit

This commit is contained in:
Dave Kelsey 2009-01-23 17:12:15 +00:00
parent 6776d26fdc
commit 0fe72d9026
21 changed files with 1445 additions and 0 deletions

View File

@ -0,0 +1,25 @@
--TEST--
Test ezmlm_hash() function : basic functionality
--SKIPIF--
<?php
if (PHP_INT_SIZE != 4) die("skip this test is for 32bit platform only");
?>
--FILE--
<?php
/* Prototype : int ezmlm_hash ( string $addr )
* Description: Calculate the hash value needed by EZMLM.
* Source code: ext/standard/mail.c
*/
echo "*** Testing ezmlm_hash() : basic functionality ***\n";
var_dump(ezmlm_hash(b"webmaster@somewhere.com"));
var_dump(ezmlm_hash(b"foo@somewhere.com"));
?>
===Done===
--EXPECT--
*** Testing ezmlm_hash() : basic functionality ***
int(1)
int(7)
===Done===

View File

@ -0,0 +1,25 @@
--TEST--
Test ezmlm_hash() function : basic functionality
--SKIPIF--
<?php
if (PHP_INT_SIZE != 8) die("skip this test is for 64bit platform only");
?>
--FILE--
<?php
/* Prototype : int ezmlm_hash ( string $addr )
* Description: Calculate the hash value needed by EZMLM.
* Source code: ext/standard/mail.c
*/
echo "*** Testing ezmlm_hash() : basic functionality ***\n";
var_dump(ezmlm_hash(b"webmaster@somewhere.com"));
var_dump(ezmlm_hash(b"foo@somewhere.com"));
?>
===Done===
--EXPECT--
*** Testing ezmlm_hash() : basic functionality ***
int(27)
int(48)
===Done===

View File

@ -0,0 +1,66 @@
--TEST--
Test ezmlm_hash() function : error conditions
--FILE--
<?php
/* Prototype : int ezmlm_hash ( string $addr )
* Description: Calculate the hash value needed by EZMLM.
* Source code: ext/standard/mail.c
*/
echo "*** Testing ezmlm_hash() : error conditions ***\n";
echo "\n-- Testing ezmlm_hash() function with fewer than expected no. of arguments --\n";
var_dump( ezmlm_hash() );
echo "\n-- Testing ezmlm_hash() function with more than expected no. of arguments --\n";
$extra_arg = 10;
var_dump( ezmlm_hash("webmaster@something.com", $extra_arg) );
echo "\n-- Testing ezmlm_hash() function with invalid input - ARRAY --\n";
$array_arg = array(1,2,3,4);
$extra_arg = 10;
var_dump( ezmlm_hash($array_arg) );
echo "\n-- Testing ezmlm_hash() function with invalid input - OBJECT without 'cast_object' method --\n";
class sample {
}
$obj_arg = new sample();
var_dump( ezmlm_hash($obj_arg) );
echo "\n-- Testing ezmlm_hash() function with invalid input - RESOURCE --\n";
$file_handle = fopen(__FILE__, "r");
$extra_arg = 10;
var_dump( ezmlm_hash($file_handle) );
fclose($file_handle);
?>
===DONE===
--EXPECTF--
*** Testing ezmlm_hash() : error conditions ***
-- Testing ezmlm_hash() function with fewer than expected no. of arguments --
Warning: ezmlm_hash() expects exactly 1 parameter, 0 given in %s on line %d
NULL
-- Testing ezmlm_hash() function with more than expected no. of arguments --
Warning: ezmlm_hash() expects exactly 1 parameter, 2 given in %s on line %d
NULL
-- Testing ezmlm_hash() function with invalid input - ARRAY --
Warning: ezmlm_hash() expects parameter 1 to be binary string, array given in %s on line %d
NULL
-- Testing ezmlm_hash() function with invalid input - OBJECT without 'cast_object' method --
Warning: ezmlm_hash() expects parameter 1 to be binary string, object given in %s on line %d
NULL
-- Testing ezmlm_hash() function with invalid input - RESOURCE --
Warning: ezmlm_hash() expects parameter 1 to be binary string, resource given in %s on line %d
NULL
===DONE===

View File

@ -0,0 +1,193 @@
--TEST--
Test explode() function : usage variations - test values for $delimiter argument
--FILE--
<?php
/* Prototype : array explode ( string $delimiter , string $string [, int $limit ] )
* Description: Split a string by string.
* Source code: ext/standard/string.c
*/
echo "*** Testing explode() function: with unexpected inputs for 'delimiter' argument ***\n";
//get an unset variable
$unset_var = 'string_val';
unset($unset_var);
//defining a class
class sample {
public function __toString() {
return "sample object";
}
}
//getting the resource
$file_handle = fopen(__FILE__, "r");
// array with different values for $delimeter
$delimeters = array (
// integer values
0,
1,
255,
256,
PHP_INT_MAX,
-PHP_INT_MAX,
// float values
10.5,
-20.5,
10.1234567e10,
// array values
array(),
array(0),
array(1, 2),
// boolean values
true,
false,
TRUE,
FALSE,
// null values
NULL,
null,
// objects
new sample(),
// resource
$file_handle,
// undefined variable
@$undefined_var,
// unset variable
@$unset_var
);
// loop through with each element of the $delimeters array to test explode() function
$count = 1;
$string = "piece1 piece2 piece3 piece4 piece5 piece6";
$limit = 5;
foreach($delimeters as $delimeter) {
echo "-- Iteration $count --\n";
var_dump( explode($delimeter, $string, $limit) );
$count ++;
}
fclose($file_handle); //closing the file handle
?>
===Done===
--EXPECTF--
*** Testing explode() function: with unexpected inputs for 'delimiter' argument ***
-- Iteration 1 --
array(1) {
[0]=>
unicode(41) "piece1 piece2 piece3 piece4 piece5 piece6"
}
-- Iteration 2 --
array(2) {
[0]=>
unicode(5) "piece"
[1]=>
unicode(35) " piece2 piece3 piece4 piece5 piece6"
}
-- Iteration 3 --
array(1) {
[0]=>
unicode(41) "piece1 piece2 piece3 piece4 piece5 piece6"
}
-- Iteration 4 --
array(1) {
[0]=>
unicode(41) "piece1 piece2 piece3 piece4 piece5 piece6"
}
-- Iteration 5 --
array(1) {
[0]=>
unicode(41) "piece1 piece2 piece3 piece4 piece5 piece6"
}
-- Iteration 6 --
array(1) {
[0]=>
unicode(41) "piece1 piece2 piece3 piece4 piece5 piece6"
}
-- Iteration 7 --
array(1) {
[0]=>
unicode(41) "piece1 piece2 piece3 piece4 piece5 piece6"
}
-- Iteration 8 --
array(1) {
[0]=>
unicode(41) "piece1 piece2 piece3 piece4 piece5 piece6"
}
-- Iteration 9 --
array(1) {
[0]=>
unicode(41) "piece1 piece2 piece3 piece4 piece5 piece6"
}
-- Iteration 10 --
Warning: explode() expects parameter 1 to be string (Unicode or binary), array given in %s on line %d
NULL
-- Iteration 11 --
Warning: explode() expects parameter 1 to be string (Unicode or binary), array given in %s on line %d
NULL
-- Iteration 12 --
Warning: explode() expects parameter 1 to be string (Unicode or binary), array given in %s on line %d
NULL
-- Iteration 13 --
array(2) {
[0]=>
unicode(5) "piece"
[1]=>
unicode(35) " piece2 piece3 piece4 piece5 piece6"
}
-- Iteration 14 --
Warning: explode(): Empty delimiter in %s on line %d
bool(false)
-- Iteration 15 --
array(2) {
[0]=>
unicode(5) "piece"
[1]=>
unicode(35) " piece2 piece3 piece4 piece5 piece6"
}
-- Iteration 16 --
Warning: explode(): Empty delimiter in %s on line %d
bool(false)
-- Iteration 17 --
Warning: explode(): Empty delimiter in %s on line %d
bool(false)
-- Iteration 18 --
Warning: explode(): Empty delimiter in %s on line %d
bool(false)
-- Iteration 19 --
array(1) {
[0]=>
unicode(41) "piece1 piece2 piece3 piece4 piece5 piece6"
}
-- Iteration 20 --
Warning: explode() expects parameter 1 to be string (Unicode or binary), resource given in %s on line %d
NULL
-- Iteration 21 --
Warning: explode(): Empty delimiter in %s on line %d
bool(false)
-- Iteration 22 --
Warning: explode(): Empty delimiter in %s on line %d
bool(false)
===Done===

View File

@ -0,0 +1,59 @@
--TEST--
Test mail() function : basic functionality
--INI--
sendmail_path=tee mailBasic.out >/dev/null
--SKIPIF--
<?php
if(substr(PHP_OS, 0, 3) == "WIN")
die("skip Won't run on Windows");
?>
--FILE--
<?php
/* Prototype : int mail(string to, string subject, string message [, string additional_headers [, string additional_parameters]])
* Description: Send an email message
* Source code: ext/standard/mail.c
* Alias to functions:
*/
echo "*** Testing mail() : basic functionality ***\n";
// Initialise all required variables
$to = 'user@company.com';
$subject = 'Test Subject';
$message = 'A Message';
$additional_headers = 'KHeaders';
$outFile = "mailBasic.out";
@unlink($outFile);
echo "-- All Mail Content Parameters --\n";
// Calling mail() with all additional headers
var_dump( mail($to, $subject, $message, $additional_headers) );
echo file_get_contents($outFile);
unlink($outFile);
echo "\n-- Mandatory Parameters --\n";
// Calling mail() with mandatory arguments
var_dump( mail($to, $subject, $message) );
echo file_get_contents($outFile);
unlink($outFile);
?>
===DONE===
--EXPECT--
*** Testing mail() : basic functionality ***
-- All Mail Content Parameters --
bool(true)
To: user@company.com
Subject: Test Subject
KHeaders
A Message
-- Mandatory Parameters --
bool(true)
To: user@company.com
Subject: Test Subject
A Message
===DONE===

View File

@ -0,0 +1,43 @@
--TEST--
Test mail() function : basic functionality
--INI--
sendmail_path=echo --- > mailBasic2.out
--SKIPIF--
<?php
if(substr(PHP_OS, 0, 3) == "WIN")
die("skip Won't run on Windows");
?>
--FILE--
<?php
/* Prototype : int mail(string to, string subject, string message [, string additional_headers [, string additional_parameters]])
* Description: Send an email message
* Source code: ext/standard/mail.c
* Alias to functions:
*/
echo "*** Testing mail() : basic functionality ***\n";
// Initialise all required variables
$to = 'user@company.com';
$subject = 'Test Subject';
$message = 'A Message';
$additional_headers = 'KHeaders';
$additional_parameters = "Extras";
$outFile = "mailBasic2.out";
@unlink($outFile);
echo "-- extra parameters --\n";
// Calling mail() with all possible arguments
var_dump( mail($to, $subject, $message, $additional_headers, $additional_parameters) );
sleep(1);
echo file_get_contents($outFile);
//unlink($outFile);
?>
===DONE===
--EXPECT--
*** Testing mail() : basic functionality ***
-- extra parameters --
bool(true)
--- Extras
===DONE===

View File

@ -0,0 +1,35 @@
--TEST--
Test mail() function : basic functionality
--INI--
sendmail_path="exit -1"
--SKIPIF--
<?php
if(substr(PHP_OS, 0, 3) == "WIN")
die("skip Won't run on Windows");
?>
--FILE--
<?php
/* Prototype : int mail(string to, string subject, string message [, string additional_headers [, string additional_parameters]])
* Description: Send an email message
* Source code: ext/standard/mail.c
* Alias to functions:
*/
echo "*** Testing mail() : basic functionality ***\n";
// Initialise all required variables
$to = 'user@company.com';
$subject = 'Test Subject';
$message = 'A Message';
echo "-- failure --\n";
var_dump( mail($to, $subject, $message) );
?>
===DONE===
--EXPECT--
*** Testing mail() : basic functionality ***
-- failure --
bool(false)
===DONE===

View File

@ -0,0 +1,36 @@
--TEST--
Test mail() function : basic functionality
--INI--
sendmail_path="exit -2"
--SKIPIF--
<?php
if(substr(PHP_OS, 0, 3) == "WIN")
die("skip Won't run on Windows");
?>
--FILE--
<?php
/* Prototype : int mail(string to, string subject, string message [, string additional_headers [, string additional_parameters]])
* Description: Send an email message
* Source code: ext/standard/mail.c
* Alias to functions:
*/
echo "*** Testing mail() : basic functionality ***\n";
// Initialise all required variables
$to = 'user@company.com';
$subject = 'Test Subject';
$message = 'A Message';
echo "-- failure --\n";
var_dump( mail($to, $subject, $message) );
?>
===DONE===
--EXPECT--
*** Testing mail() : basic functionality ***
-- failure --
bool(false)
===DONE===

View File

@ -0,0 +1,34 @@
--TEST--
Test mail() function : basic functionality
--INI--
sendmail_path="exit 1"
--SKIPIF--
<?php
if(substr(PHP_OS, 0, 3) == "WIN")
die("skip Won't run on Windows");
?>
--FILE--
<?php
/* Prototype : int mail(string to, string subject, string message [, string additional_headers [, string additional_parameters]])
* Description: Send an email message
* Source code: ext/standard/mail.c
* Alias to functions:
*/
echo "*** Testing mail() : basic functionality ***\n";
// Initialise all required variables
$to = 'user@company.com';
$subject = 'Test Subject';
$message = 'A Message';
echo "-- failure --\n";
var_dump( mail($to, $subject, $message) );
?>
===DONE===
--EXPECT--
*** Testing mail() : basic functionality ***
-- failure --
bool(false)
===DONE===

View File

@ -0,0 +1,95 @@
--TEST--
Test mail() function : basic functionality
--SKIPIF--
<?php
if( substr(PHP_OS, 0, 3) != 'WIN' ) {
die('skip...Windows only test');
}
require_once(dirname(__FILE__).'/mail_skipif.inc');
?>
--INI--
max_execution_time = 120
--FILE--
<?php
/* Prototype : int mail(string to, string subject, string message [, string additional_headers [, string additional_parameters]])
* Description: Send an email message
* Source code: ext/standard/mail.c
* Alias to functions:
*/
error_reporting(E_ALL & ~E_STRICT);
ini_set("SMTP", "localhost");
ini_set("smtp_port", 25);
ini_set("sendmail_from", "user@company.com");
echo "*** Testing mail() : basic functionality ***\n";
require_once(dirname(__FILE__).'/mail_include.inc');
$subject_prefix = "!**PHPT**!";
$to = "$username";
$subject = "$subject_prefix: Basic PHPT test for mail() function";
$message = <<<HERE
Description
bool mail ( string \$to , string \$subject , string \$message [, string \$additional_headers [, string \$additional_parameters]] )
Send an email message
HERE;
$res = mail($to, $subject, $message);
if ($res !== true) {
exit("TEST FAILED : Unable to send test email\n");
} else {
echo "Msg sent OK\n";
}
// Search for email message on the mail server using imap.
$imap_stream = imap_open($default_mailbox, $username, $password);
if ($imap_stream === false) {
echo "Cannot connect to IMAP server $server: " . imap_last_error() . "\n";
return false;
}
$found = false;
$repeat_count = 20; // we will repeat a max of 20 times
while (!$found && $repeat_count > 0) {
// sleep for a while to allow msg to be delivered
sleep(1);
$current_msg_count = imap_check($imap_stream)->Nmsgs;
// Iterate over recent msgs to find the one we sent above
for ($i = 1; $i <= $current_msg_count; $i++) {
// get hdr details
$hdr = imap_headerinfo($imap_stream, $i);
if (substr($hdr->Subject, 0 , strlen($subject_prefix)) == $subject_prefix) {
echo "Id of msg just sent is $i\n";
echo ".. delete it\n";
imap_delete($imap_stream, $i);
$found = true;
break;
}
}
$repeat_count -= 1;
}
if (!$found) {
echo "TEST FAILED: email not delivered\n";
} else {
echo "TEST PASSED: Msgs sent and deleted OK\n";
}
imap_close($imap_stream, CL_EXPUNGE);
?>
===Done===
--EXPECTF--
*** Testing mail() : basic functionality ***
Msg sent OK
Id of msg just sent is %d
.. delete it
TEST PASSED: Msgs sent and deleted OK
===Done===

View File

@ -0,0 +1,93 @@
--TEST--
Test mail() function : basic functionality
--SKIPIF--
<?php
if( substr(PHP_OS, 0, 3) != 'WIN' ) {
die('skip...Windows only test');
}
require_once(dirname(__FILE__).'/mail_skipif.inc');
?>
--INI--
max_execution_time = 120
--FILE--
<?php
/* Prototype : int mail(string to, string subject, string message [, string additional_headers [, string additional_parameters]])
* Description: Send an email message
* Source code: ext/standard/mail.c
* Alias to functions:
*/
error_reporting(E_ALL & ~E_STRICT);
echo "*** Testing mail() : basic functionality ***\n";
require_once(dirname(__FILE__).'/mail_include.inc');
$subject_prefix = "!**PHPT**!";
$to = "$username";
$subject = "$subject_prefix: Basic PHPT test for mail() function";
$message = <<<HERE
Description
bool mail ( string \$to , string \$subject , string \$message [, string \$additional_headers [, string \$additional_parameters]] )
Send an email message
HERE;
$extra_headers = "from: user@company.com";
$res = mail($to, $subject, $message, $extra_headers);
if ($res !== true) {
exit("TEST FAILED : Unable to send test email\n");
} else {
echo "Msg sent OK\n";
}
// Search for email message on the mail server using imap.
$imap_stream = imap_open($default_mailbox, $username, $password);
if ($imap_stream === false) {
echo "Cannot connect to IMAP server $server: " . imap_last_error() . "\n";
return false;
}
$found = false;
$repeat_count = 20; // we will repeat a max of 20 times
while (!$found && $repeat_count > 0) {
// sleep for a while to allow msg to be delivered
sleep(1);
$current_msg_count = imap_check($imap_stream)->Nmsgs;
// Iterate over recent msgs to find the one we sent above
for ($i = 1; $i <= $current_msg_count; $i++) {
// get hdr details
$hdr = imap_headerinfo($imap_stream, $i);
if (substr($hdr->Subject, 0 , strlen($subject_prefix)) == $subject_prefix) {
echo "Id of msg just sent is $i\n";
echo ".. delete it\n";
imap_delete($imap_stream, $i);
$found = true;
break;
}
}
$repeat_count -= 1;
}
if (!$found) {
echo "TEST FAILED: email not delivered\n";
} else {
echo "TEST PASSED: Msgs sent and deleted OK\n";
}
imap_close($imap_stream, CL_EXPUNGE);
?>
===Done===
--EXPECTF--
*** Testing mail() : basic functionality ***
Msg sent OK
Id of msg just sent is %d
.. delete it
TEST PASSED: Msgs sent and deleted OK
===Done===

View File

@ -0,0 +1,93 @@
--TEST--
Test mail() function : basic functionality
--SKIPIF--
<?php
if( substr(PHP_OS, 0, 3) != 'WIN' ) {
die('skip...Windows only test');
}
require_once(dirname(__FILE__).'/mail_skipif.inc');
?>
--INI--
max_execution_time = 120
--FILE--
<?php
/* Prototype : int mail(string to, string subject, string message [, string additional_headers [, string additional_parameters]])
* Description: Send an email message
* Source code: ext/standard/mail.c
* Alias to functions:
*/
error_reporting(E_ALL & ~E_STRICT);
echo "*** Testing mail() : basic functionality ***\n";
require_once(dirname(__FILE__).'/mail_include.inc');
$subject_prefix = "!**PHPT**!";
$to = "$username";
$subject = "$subject_prefix: Basic PHPT test for mail() function";
$message = <<<HERE
Description
bool mail ( string \$to , string \$subject , string \$message [, string \$additional_headers [, string \$additional_parameters]] )
Send an email message
HERE;
$extra_headers = "FRom: user@company.com";
$res = mail($to, $subject, $message, $extra_headers);
if ($res !== true) {
exit("TEST FAILED : Unable to send test email\n");
} else {
echo "Msg sent OK\n";
}
// Search for email message on the mail server using imap.
$imap_stream = imap_open($default_mailbox, $username, $password);
if ($imap_stream === false) {
echo "Cannot connect to IMAP server $server: " . imap_last_error() . "\n";
return false;
}
$found = false;
$repeat_count = 20; // we will repeat a max of 20 times
while (!$found && $repeat_count > 0) {
// sleep for a while to allow msg to be delivered
sleep(1);
$current_msg_count = imap_check($imap_stream)->Nmsgs;
// Iterate over recent msgs to find the one we sent above
for ($i = 1; $i <= $current_msg_count; $i++) {
// get hdr details
$hdr = imap_headerinfo($imap_stream, $i);
if (substr($hdr->Subject, 0 , strlen($subject_prefix)) == $subject_prefix) {
echo "Id of msg just sent is $i\n";
echo ".. delete it\n";
imap_delete($imap_stream, $i);
$found = true;
break;
}
}
$repeat_count -= 1;
}
if (!$found) {
echo "TEST FAILED: email not delivered\n";
} else {
echo "TEST PASSED: Msgs sent and deleted OK\n";
}
imap_close($imap_stream, CL_EXPUNGE);
?>
===Done===
--EXPECTF--
*** Testing mail() : basic functionality ***
Msg sent OK
Id of msg just sent is %d
.. delete it
TEST PASSED: Msgs sent and deleted OK
===Done===

View File

@ -0,0 +1,94 @@
--TEST--
Test mail() function : basic functionality
--SKIPIF--
<?php
if( substr(PHP_OS, 0, 3) != 'WIN' ) {
die('skip...Windows only test');
}
require_once(dirname(__FILE__).'/mail_skipif.inc');
?>
--INI--
max_execution_time = 120
--FILE--
<?php
/* Prototype : int mail(string to, string subject, string message [, string additional_headers [, string additional_parameters]])
* Description: Send an email message
* Source code: ext/standard/mail.c
* Alias to functions:
*/
error_reporting(E_ALL & ~E_STRICT);
echo "*** Testing mail() : basic functionality ***\n";
require_once(dirname(__FILE__).'/mail_include.inc');
$subject_prefix = "!**PHPT**!";
$to = "$username";
$subject = "$subject_prefix: Basic PHPT test for mail() function";
$message = <<<HERE
Description
bool mail ( string \$to , string \$subject , string \$message [, string \$additional_headers [, string \$additional_parameters]] )
Send an email message
HERE;
$extra_headers = "from: user@company.com";
$extra_parameters = "addons"; // should be ignored
$res = mail($to, $subject, $message, $extra_headers, $extra_parameters);
if ($res !== true) {
exit("TEST FAILED : Unable to send test email\n");
} else {
echo "Msg sent OK\n";
}
// Search for email message on the mail server using imap.
$imap_stream = imap_open($default_mailbox, $username, $password);
if ($imap_stream === false) {
echo "Cannot connect to IMAP server $server: " . imap_last_error() . "\n";
return false;
}
$found = false;
$repeat_count = 20; // we will repeat a max of 20 times
while (!$found && $repeat_count > 0) {
// sleep for a while to allow msg to be delivered
sleep(1);
$current_msg_count = imap_check($imap_stream)->Nmsgs;
// Iterate over recent msgs to find the one we sent above
for ($i = 1; $i <= $current_msg_count; $i++) {
// get hdr details
$hdr = imap_headerinfo($imap_stream, $i);
if (substr($hdr->Subject, 0 , strlen($subject_prefix)) == $subject_prefix) {
echo "Id of msg just sent is $i\n";
echo ".. delete it\n";
imap_delete($imap_stream, $i);
$found = true;
break;
}
}
$repeat_count -= 1;
}
if (!$found) {
echo "TEST FAILED: email not delivered\n";
} else {
echo "TEST PASSED: Msgs sent and deleted OK\n";
}
imap_close($imap_stream, CL_EXPUNGE);
?>
===Done===
--EXPECTF--
*** Testing mail() : basic functionality ***
Msg sent OK
Id of msg just sent is %d
.. delete it
TEST PASSED: Msgs sent and deleted OK
===Done===

View File

@ -0,0 +1,44 @@
--TEST--
Test mail() function : error conditions
--FILE--
<?php
/* Prototype : int mail(string to, string subject, string message [, string additional_headers [, string additional_parameters]])
* Description: Send an email message
* Source code: ext/standard/mail.c
* Alias to functions:
*/
echo "*** Testing mail() : error conditions ***\n";
//Test mail with one more than the expected number of arguments
echo "\n-- Testing mail() function with more than expected no. of arguments --\n";
$to = 'string_val';
$subject = 'string_val';
$message = 'string_val';
$additional_headers = 'string_val';
$additional_parameters = 'string_val';
$extra_arg = 10;
var_dump( mail($to, $subject, $message, $additional_headers, $additional_parameters, $extra_arg) );
// Testing mail with one less than the expected number of arguments
echo "\n-- Testing mail() function with less than expected no. of arguments --\n";
$to = 'string_val';
$subject = 'string_val';
var_dump( mail($to, $subject) );
?>
===DONE===
--EXPECTF--
*** Testing mail() : error conditions ***
-- Testing mail() function with more than expected no. of arguments --
Warning: mail() expects at most 5 parameters, 6 given in %s on line %d
NULL
-- Testing mail() function with less than expected no. of arguments --
Warning: mail() expects at least 3 parameters, 2 given in %s on line %d
NULL
===DONE===

View File

@ -0,0 +1,150 @@
<?php
// Change these to make tests run successfully
$server = '{localhost}';
$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
/**
* Create a test mailbox and populate with msgs
*
* @para, 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 sucesss; FALSE on failure
*/
function setup_test_mailbox($mailbox_suffix, $message_count, &$new_mailbox = null, $msg_type = "simple"){
global $server, $default_mailbox, $username, $password;
// open a stream to default mailbox
$imap_stream = imap_open($default_mailbox, $username, $password);
if ($imap_stream === false) {
echo "Cannot connect to IMAP server $server: " . imap_last_error() . "\n";
return false;
}
echo "Create a temporary mailbox and add " . $message_count . " msgs\n";
$new_mailbox = create_mailbox($imap_stream, $mailbox_suffix, $message_count, $msg_type);
if ($new_mailbox === false) {
echo "Cant create a temporary mailbox: " . imap_last_error(). "\n";
return false;
}
echo ".. mailbox '$new_mailbox' created\n";
// reopen stream to new mailbox
if (imap_reopen($imap_stream, $new_mailbox) === false) {
echo "cant re-open '$new_mailbox' mailbox: " . imap_last_error() . "\n";
return false;
}
return $imap_stream;
}
/**
* Create mailbox and fill with generic emails
*
* @param resource $imap_stream
* @param string $mailbox
*/
function create_mailbox($imap_stream, $mailbox_suffix, $message_count, $msg_type= "simple"){
global $default_mailbox, $mailbox_prefix;
$mailbox = $default_mailbox . "." . $mailbox_prefix . $mailbox_suffix;
$mailboxes = imap_getmailboxes($imap_stream, $mailbox, '*');
// check mailbox does not already exist
if ($mailboxes) {
foreach($mailboxes as $value) {
if ($value->name == $mailbox) {
exit ("TEST FAILED : Mailbox '$mailbox' already exists\n");
}
}
}
if (imap_createmailbox($imap_stream, $mailbox) === false) {
return false;
}
// Add number of test msgs requested
if ($message_count > 0) {
populate_mailbox($imap_stream, $mailbox, $message_count, $msg_type);
}
return $mailbox;
}
/**
* Populate a mailbox with generic emails
*
* @param resource $imap_stream
* @param string $mailbox
*/
function populate_mailbox($imap_stream, $mailbox, $message_count, $msg_type = "simple"){
global $users, $domain;
for($i = 1; $i <= $message_count; $i++) {
if ($msg_type == "simple") {
$msg = "From: foo@anywhere.com\r\n"
. "To: $users[0]@$domain\r\n"
. "Subject: test$i\r\n"
. "\r\n"
. "$i: this is a test message, please ignore\r\n";
} else {
$envelope["from"]= "foo@anywhere.com";
$envelope["to"] = "$users[0]@$domain";
$envelope["subject"] = "Test msg $i";
$part1["type"] = TYPEMULTIPART;
$part1["subtype"] = "mixed";
$part2["type"] = TYPETEXT;
$part2["subtype"] = "plain";
$part2["description"] = "imap_mail_compose() function";
$part2["contents.data"] = "message 1:xxxxxxxxxxxxxxxxxxxxxxxxxx";
$part3["type"] = TYPETEXT;
$part3["subtype"] = "plain";
$part3["description"] = "Example";
$part3["contents.data"] = "message 2:yyyyyyyyyyyyyyyyyyyyyyyyyy";
$part4["type"] = TYPETEXT;
$part4["subtype"] = "plain";
$part4["description"] = "Return Values";
$part4["contents.data"] = "message 3:zzzzzzzzzzzzzzzzzzzzzzzzzz";
$body[1] = $part1;
$body[2] = $part2;
$body[3] = $part3;
$body[4] = $part4;
$msg = imap_mail_compose($envelope, $body);
}
imap_append($imap_stream, $mailbox, $msg);
}
}
/**
* Get the mailbox name from a mailbox decription, i.e strip off server details.
*
* @param string mailbox complete mailbox name
* @return mailbox name
*/
function get_mailbox_name($mailbox){
if (preg_match('/\{.*?\}(.*)/', $mailbox, $match) != 1) {
echo "Unrecpognized mailbox name\n";
return false;
}
return $match[1];
}
?>

View File

@ -0,0 +1,16 @@
<?php
extension_loaded('imap') or die('skip imap extension not available in this build');
// Change these to make tests run successfully
$mailbox = '{localhost}';
$username = 'webmaster@something.com';
$password = 'p4ssw0rd';
$options = OP_HALFOPEN; // this should be enough to verify server present
$retries = 0; // dont 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);
?>

View File

@ -0,0 +1,30 @@
--TEST--
Test mail() function : variation invalid program for sendmail
--INI--
sendmail_path=rubbish 2>/dev/null
--SKIPIF--
<?php
if(substr(PHP_OS, 0, 3) == "WIN")
die("skip Won't run on Windows");
?>
--FILE--
<?php
/* Prototype : int mail(string to, string subject, string message [, string additional_headers [, string additional_parameters]])
* Description: Send an email message
* Source code: ext/standard/mail.c
* Alias to functions:
*/
echo "*** Testing mail() : variation ***\n";
// Initialise all required variables
$to = 'user@company.com';
$subject = 'Test Subject';
$message = 'A Message';
var_dump( mail($to, $subject, $message) );
?>
===DONE===
--EXPECT--
*** Testing mail() : variation ***
bool(false)
===DONE===

View File

@ -0,0 +1,39 @@
--TEST--
Test mail() function : variation force extra parameters
--INI--
sendmail_path=echo --- > mailBasic2.out
mail.force_extra_parameters="forced params"
--SKIPIF--
<?php
if(substr(PHP_OS, 0, 3) == "WIN")
die("skip Won't run on Windows");
?>
--FILE--
<?php
/* Prototype : int mail(string to, string subject, string message [, string additional_headers [, string additional_parameters]])
* Description: Send an email message
* Source code: ext/standard/mail.c
* Alias to functions:
*/
echo "*** Testing mail() : basic functionality ***\n";
// Initialise all required variables
$to = 'user@company.com';
$subject = 'Test Subject';
$message = 'A Message';
$outFile = "mailBasic2.out";
@unlink($outFile);
var_dump( mail($to, $subject, $message) );
echo file_get_contents($outFile);
unlink($outFile);
?>
===DONE===
--EXPECT--
*** Testing mail() : basic functionality ***
bool(true)
--- forced params
===DONE===

View File

@ -0,0 +1,92 @@
--TEST--
Test mail() function : basic functionality
--SKIPIF--
<?php
if( substr(PHP_OS, 0, 3) != 'WIN' ) {
die('skip...Windows only test');
}
require_once(dirname(__FILE__).'/mail_skipif.inc');
?>
--INI--
max_execution_time = 120
--FILE--
<?php
/* Prototype : int mail(string to, string subject, string message [, string additional_headers [, string additional_parameters]])
* Description: Send an email message
* Source code: ext/standard/mail.c
* Alias to functions:
*/
error_reporting(E_ALL & ~E_STRICT);
ini_set("SMTP", "localhost");
ini_set("smtp_port", 2525);
ini_set("sendmail_from", "user@company.com");
echo "*** Testing mail() : basic functionality ***\n";
require_once(dirname(__FILE__).'/mail_include.inc');
$subject_prefix = "!**PHPT**!";
$to = "$username";
$subject = "$subject_prefix: Basic PHPT test for mail() function";
$message = <<<HERE
Description
bool mail ( string \$to , string \$subject , string \$message [, string \$additional_headers [, string \$additional_parameters]] )
Send an email message
HERE;
$res = mail($to, $subject, $message);
if ($res !== true) {
exit("TEST COMPLETED : Unable to send test email\n");
} else {
echo "Msg sent OK\n";
}
// Search for email message on the mail server using imap.
$imap_stream = imap_open($default_mailbox, $username, $password);
if ($imap_stream === false) {
echo "Cannot connect to IMAP server $server: " . imap_last_error() . "\n";
return false;
}
$found = false;
$repeat_count = 20; // we will repeat a max of 20 times
while (!$found && $repeat_count > 0) {
// sleep for a while to allow msg to be delivered
sleep(1);
$current_msg_count = imap_check($imap_stream)->Nmsgs;
// Iterate over recent msgs to find the one we sent above
for ($i = 1; $i <= $current_msg_count; $i++) {
// get hdr details
$hdr = imap_headerinfo($imap_stream, $i);
if (substr($hdr->Subject, 0 , strlen($subject_prefix)) == $subject_prefix) {
echo "Id of msg just sent is $i\n";
echo ".. delete it\n";
imap_delete($imap_stream, $i);
$found = true;
break;
}
}
$repeat_count -= 1;
}
if (!$found) {
echo "TEST FAILED: email not delivered\n";
} else {
echo "TEST PASSED: Msgs sent and deleted OK\n";
}
imap_close($imap_stream, CL_EXPUNGE);
?>
===Done===
--EXPECTF--
*** Testing mail() : basic functionality ***
Warning: mail(): Failed to connect to mailserver at "localhost" port 2525, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in %s on line %d
TEST COMPLETED : Unable to send test email

View File

@ -0,0 +1,92 @@
--TEST--
Test mail() function : basic functionality
--SKIPIF--
<?php
if( substr(PHP_OS, 0, 3) != 'WIN' ) {
die('skip...Windows only test');
}
require_once(dirname(__FILE__).'/mail_skipif.inc');
?>
--INI--
max_execution_time = 120
--FILE--
<?php
/* Prototype : int mail(string to, string subject, string message [, string additional_headers [, string additional_parameters]])
* Description: Send an email message
* Source code: ext/standard/mail.c
* Alias to functions:
*/
error_reporting(E_ALL & ~E_STRICT);
ini_set("SMTP", "localplace");
ini_set("smtp_port", 25);
ini_set("sendmail_from", "user@company.com");
echo "*** Testing mail() : basic functionality ***\n";
require_once(dirname(__FILE__).'/mail_include.inc');
$subject_prefix = "!**PHPT**!";
$to = "$username";
$subject = "$subject_prefix: Basic PHPT test for mail() function";
$message = <<<HERE
Description
bool mail ( string \$to , string \$subject , string \$message [, string \$additional_headers [, string \$additional_parameters]] )
Send an email message
HERE;
$res = mail($to, $subject, $message);
if ($res !== true) {
exit("TEST COMPLETED : Unable to send test email\n");
} else {
echo "Msg sent OK\n";
}
// Search for email message on the mail server using imap.
$imap_stream = imap_open($default_mailbox, $username, $password);
if ($imap_stream === false) {
echo "Cannot connect to IMAP server $server: " . imap_last_error() . "\n";
return false;
}
$found = false;
$repeat_count = 20; // we will repeat a max of 20 times
while (!$found && $repeat_count > 0) {
// sleep for a while to allow msg to be delivered
sleep(1);
$current_msg_count = imap_check($imap_stream)->Nmsgs;
// Iterate over recent msgs to find the one we sent above
for ($i = 1; $i <= $current_msg_count; $i++) {
// get hdr details
$hdr = imap_headerinfo($imap_stream, $i);
if (substr($hdr->Subject, 0 , strlen($subject_prefix)) == $subject_prefix) {
echo "Id of msg just sent is $i\n";
echo ".. delete it\n";
imap_delete($imap_stream, $i);
$found = true;
break;
}
}
$repeat_count -= 1;
}
if (!$found) {
echo "TEST FAILED: email not delivered\n";
} else {
echo "TEST PASSED: Msgs sent and deleted OK\n";
}
imap_close($imap_stream, CL_EXPUNGE);
?>
===Done===
--EXPECTF--
*** Testing mail() : basic functionality ***
Warning: mail(): Failed to connect to mailserver at "localplace" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in %s on line %d
TEST COMPLETED : Unable to send test email

View File

@ -0,0 +1,91 @@
--TEST--
Test mail() function : basic functionality
--SKIPIF--
<?php
if( substr(PHP_OS, 0, 3) != 'WIN' ) {
die('skip...Windows only test');
}
require_once(dirname(__FILE__).'/mail_skipif.inc');
?>
--INI--
max_execution_time = 120
--FILE--
<?php
/* Prototype : int mail(string to, string subject, string message [, string additional_headers [, string additional_parameters]])
* Description: Send an email message
* Source code: ext/standard/mail.c
* Alias to functions:
*/
error_reporting(E_ALL & ~E_STRICT);
ini_set("SMTP", "localhost");
ini_set("smtp_port", 25);
echo "*** Testing mail() : basic functionality ***\n";
require_once(dirname(__FILE__).'/mail_include.inc');
$subject_prefix = "!**PHPT**!";
$to = "$username";
$subject = "$subject_prefix: Basic PHPT test for mail() function";
$message = <<<HERE
Description
bool mail ( string \$to , string \$subject , string \$message [, string \$additional_headers [, string \$additional_parameters]] )
Send an email message
HERE;
$res = mail($to, $subject, $message);
if ($res !== true) {
exit("TEST COMPLETED : Unable to send test email\n");
} else {
echo "Msg sent OK\n";
}
// Search for email message on the mail server using imap.
$imap_stream = imap_open($default_mailbox, $username, $password);
if ($imap_stream === false) {
echo "Cannot connect to IMAP server $server: " . imap_last_error() . "\n";
return false;
}
$found = false;
$repeat_count = 20; // we will repeat a max of 20 times
while (!$found && $repeat_count > 0) {
// sleep for a while to allow msg to be delivered
sleep(1);
$current_msg_count = imap_check($imap_stream)->Nmsgs;
// Iterate over recent msgs to find the one we sent above
for ($i = 1; $i <= $current_msg_count; $i++) {
// get hdr details
$hdr = imap_headerinfo($imap_stream, $i);
if (substr($hdr->Subject, 0 , strlen($subject_prefix)) == $subject_prefix) {
echo "Id of msg just sent is $i\n";
echo ".. delete it\n";
imap_delete($imap_stream, $i);
$found = true;
break;
}
}
$repeat_count -= 1;
}
if (!$found) {
echo "TEST FAILED: email not delivered\n";
} else {
echo "TEST PASSED: Msgs sent and deleted OK\n";
}
imap_close($imap_stream, CL_EXPUNGE);
?>
===Done===
--EXPECTF--
*** Testing mail() : basic functionality ***
Warning: mail(): "sendmail_from" not set in php.ini or custom "From:" header missing in %s on line %d
TEST COMPLETED : Unable to send test email