0
0
mirror of https://github.com/PHPMailer/PHPMailer.git synced 2024-09-20 01:52:15 +02:00

Quotes, indents, add test for BCC-only

This commit is contained in:
Synchro 2013-03-06 17:34:28 +01:00
parent 9e308fea31
commit 9dd16cef4e

View File

@ -32,7 +32,7 @@ class phpmailerTest extends PHPUnit_Framework_TestCase
* @public
* @var string
*/
public $Host = "";
public $Host = '';
/**
* Holds the change log.
@ -66,18 +66,18 @@ class phpmailerTest extends PHPUnit_Framework_TestCase
$this->Mail = new PHPMailer;
$this->Mail->Priority = 3;
$this->Mail->Encoding = "8bit";
$this->Mail->CharSet = "iso-8859-1";
$this->Mail->Encoding = '8bit';
$this->Mail->CharSet = 'iso-8859-1';
if (array_key_exists('mail_from', $_REQUEST)) {
$this->Mail->From = $_REQUEST['mail_from'];
} else {
$this->Mail->From = 'unit_test@phpmailer.example.com';
}
$this->Mail->FromName = "Unit Tester";
$this->Mail->Sender = "";
$this->Mail->Subject = "Unit Test";
$this->Mail->Body = "";
$this->Mail->AltBody = "";
$this->Mail->FromName = 'Unit Tester';
$this->Mail->Sender = '';
$this->Mail->Subject = 'Unit Test';
$this->Mail->Body = '';
$this->Mail->AltBody = '';
$this->Mail->WordWrap = 0;
if (array_key_exists('mail_host', $_REQUEST)) {
$this->Mail->Host = $_REQUEST['mail_host'];
@ -89,19 +89,19 @@ class phpmailerTest extends PHPUnit_Framework_TestCase
} else {
$this->Mail->Port = 25;
}
$this->Mail->Helo = "localhost.localdomain";
$this->Mail->Helo = 'localhost.localdomain';
$this->Mail->SMTPAuth = false;
$this->Mail->Username = "";
$this->Mail->Password = "";
$this->Mail->Username = '';
$this->Mail->Password = '';
$this->Mail->PluginDir = $this->INCLUDE_DIR;
$this->Mail->AddReplyTo("no_reply@phpmailer.example.com", "Reply Guy");
$this->Mail->Sender = "unit_test@phpmailer.example.com";
$this->Mail->AddReplyTo('no_reply@phpmailer.example.com', 'Reply Guy');
$this->Mail->Sender = 'unit_test@phpmailer.example.com';
if (strlen($this->Mail->Host) > 0) {
$this->Mail->Mailer = "smtp";
$this->Mail->Mailer = 'smtp';
} else {
$this->Mail->Mailer = "mail";
$this->Mail->Sender = "unit_test@phpmailer.example.com";
$this->Mail->Mailer = 'mail';
$this->Mail->Sender = 'unit_test@phpmailer.example.com';
}
if (array_key_exists('mail_to', $_REQUEST)) {
@ -134,60 +134,60 @@ class phpmailerTest extends PHPUnit_Framework_TestCase
$this->CheckChanges();
// Determine line endings for message
if ($this->Mail->ContentType == "text/html" || strlen($this->Mail->AltBody) > 0) {
$eol = "<br/>";
$bullet = "<li>";
$bullet_start = "<ul>";
$bullet_end = "</ul>";
if ($this->Mail->ContentType == 'text/html' || strlen($this->Mail->AltBody) > 0) {
$eol = '<br/>';
$bullet = '<li>';
$bullet_start = '<ul>';
$bullet_end = '</ul>';
} else {
$eol = "\n";
$bullet = " - ";
$bullet_start = "";
$bullet_end = "";
$bullet = ' - ';
$bullet_start = '';
$bullet_end = '';
}
$ReportBody = "";
$ReportBody = '';
$ReportBody .= "---------------------" . $eol;
$ReportBody .= "Unit Test Information" . $eol;
$ReportBody .= "---------------------" . $eol;
$ReportBody .= "phpmailer version: " . $this->Mail->Version . $eol;
$ReportBody .= "Content Type: " . $this->Mail->ContentType . $eol;
$ReportBody .= '---------------------' . $eol;
$ReportBody .= 'Unit Test Information' . $eol;
$ReportBody .= '---------------------' . $eol;
$ReportBody .= 'phpmailer version: ' . $this->Mail->Version . $eol;
$ReportBody .= 'Content Type: ' . $this->Mail->ContentType . $eol;
if (strlen($this->Mail->Host) > 0) {
$ReportBody .= "Host: " . $this->Mail->Host . $eol;
$ReportBody .= 'Host: ' . $this->Mail->Host . $eol;
}
// If attachments then create an attachment list
$attachments = $this->Mail->GetAttachments();
if (count($attachments) > 0) {
$ReportBody .= "Attachments:" . $eol;
$ReportBody .= 'Attachments:' . $eol;
$ReportBody .= $bullet_start;
foreach ($attachments as $attachment) {
$ReportBody .= $bullet . "Name: " . $attachment[1] . ", ";
$ReportBody .= "Encoding: " . $attachment[3] . ", ";
$ReportBody .= "Type: " . $attachment[4] . $eol;
$ReportBody .= $bullet . 'Name: ' . $attachment[1] . ', ';
$ReportBody .= 'Encoding: ' . $attachment[3] . ', ';
$ReportBody .= 'Type: ' . $attachment[4] . $eol;
}
$ReportBody .= $bullet_end . $eol;
}
// If there are changes then list them
if (count($this->ChangeLog) > 0) {
$ReportBody .= "Changes" . $eol;
$ReportBody .= "-------" . $eol;
$ReportBody .= 'Changes' . $eol;
$ReportBody .= '-------' . $eol;
$ReportBody .= $bullet_start;
for ($i = 0; $i < count($this->ChangeLog); $i++) {
$ReportBody .= $bullet . $this->ChangeLog[$i][0] . " was changed to [" .
$this->ChangeLog[$i][1] . "]" . $eol;
$ReportBody .= $bullet . $this->ChangeLog[$i][0] . ' was changed to [' .
$this->ChangeLog[$i][1] . ']' . $eol;
}
$ReportBody .= $bullet_end . $eol . $eol;
}
// If there are notes then list them
if (count($this->NoteLog) > 0) {
$ReportBody .= "Notes" . $eol;
$ReportBody .= "-----" . $eol;
$ReportBody .= 'Notes' . $eol;
$ReportBody .= '-----' . $eol;
$ReportBody .= $bullet_start;
for ($i = 0; $i < count($this->NoteLog); $i++) {
@ -208,31 +208,31 @@ class phpmailerTest extends PHPUnit_Framework_TestCase
function CheckChanges()
{
if ($this->Mail->Priority != 3) {
$this->AddChange("Priority", $this->Mail->Priority);
$this->AddChange('Priority', $this->Mail->Priority);
}
if ($this->Mail->Encoding != "8bit") {
$this->AddChange("Encoding", $this->Mail->Encoding);
if ($this->Mail->Encoding != '8bit') {
$this->AddChange('Encoding', $this->Mail->Encoding);
}
if ($this->Mail->CharSet != "iso-8859-1") {
$this->AddChange("CharSet", $this->Mail->CharSet);
if ($this->Mail->CharSet != 'iso-8859-1') {
$this->AddChange('CharSet', $this->Mail->CharSet);
}
if ($this->Mail->Sender != "") {
$this->AddChange("Sender", $this->Mail->Sender);
if ($this->Mail->Sender != '') {
$this->AddChange('Sender', $this->Mail->Sender);
}
if ($this->Mail->WordWrap != 0) {
$this->AddChange("WordWrap", $this->Mail->WordWrap);
$this->AddChange('WordWrap', $this->Mail->WordWrap);
}
if ($this->Mail->Mailer != "mail") {
$this->AddChange("Mailer", $this->Mail->Mailer);
if ($this->Mail->Mailer != 'mail') {
$this->AddChange('Mailer', $this->Mail->Mailer);
}
if ($this->Mail->Port != 25) {
$this->AddChange("Port", $this->Mail->Port);
$this->AddChange('Port', $this->Mail->Port);
}
if ($this->Mail->Helo != "localhost.localdomain") {
$this->AddChange("Helo", $this->Mail->Helo);
if ($this->Mail->Helo != 'localhost.localdomain') {
$this->AddChange('Helo', $this->Mail->Helo);
}
if ($this->Mail->SMTPAuth) {
$this->AddChange("SMTPAuth", "true");
$this->AddChange('SMTPAuth', 'true');
}
}
@ -274,7 +274,7 @@ class phpmailerTest extends PHPUnit_Framework_TestCase
return $this->Mail->AddAddress($sAddress, $sName);
case 'cc':
return $this->Mail->AddCC($sAddress, $sName);
case "bcc":
case 'bcc':
return $this->Mail->AddBCC($sAddress, $sName);
}
return false;
@ -298,7 +298,7 @@ class phpmailerTest extends PHPUnit_Framework_TestCase
$this->Mail->Username = 'username';
$this->Mail->Password = 'password';
$this->Mail->Body = 'Test body';
$this->Mail->Subject .= ": Auth CRAM-MD5";
$this->Mail->Subject .= ': Auth CRAM-MD5';
$this->Mail->From = 'from@example.com';
$this->Mail->Sender = 'from@example.com';
$this->Mail->ClearAllRecipients();
@ -586,7 +586,6 @@ class phpmailerTest extends PHPUnit_Framework_TestCase
foreach ($validaddresses as $address) {
if (!PHPMailer::ValidateAddress($address)) {
$goodfails[] = $address;
//"Valid address <$address> failed validation"
}
}
$badpasses = array();
@ -617,14 +616,14 @@ class phpmailerTest extends PHPUnit_Framework_TestCase
{
$this->Mail->WordWrap = 40;
$my_body = "Here is the main body of this message. It should " .
"be quite a few lines. It should be wrapped at the " .
"40 characters. Make sure that it is.";
$my_body = 'Here is the main body of this message. It should ' .
'be quite a few lines. It should be wrapped at the ' .
'40 characters. Make sure that it is.';
$nBodyLen = strlen($my_body);
$my_body .= "\n\nThis is the above body length: " . $nBodyLen;
$this->Mail->Body = $my_body;
$this->Mail->Subject .= ": Wordwrap";
$this->Mail->Subject .= ': Wordwrap';
$this->BuildBody();
$this->assertTrue($this->Mail->Send(), $this->Mail->ErrorInfo);
@ -637,10 +636,10 @@ class phpmailerTest extends PHPUnit_Framework_TestCase
{
$this->Mail->Priority = 5;
$this->Mail->Body = "Here is the main body. There should be " .
"a reply to address in this message.";
$this->Mail->Subject .= ": Low Priority";
$this->Mail->AddReplyTo("nobody@nobody.com", "Nobody (Unit Test)");
$this->Mail->Body = 'Here is the main body. There should be ' .
'a reply to address in this message.';
$this->Mail->Subject .= ': Low Priority';
$this->Mail->AddReplyTo('nobody@nobody.com', 'Nobody (Unit Test)');
$this->BuildBody();
$this->assertTrue($this->Mail->Send(), $this->Mail->ErrorInfo);
@ -652,15 +651,15 @@ class phpmailerTest extends PHPUnit_Framework_TestCase
function test_Multiple_Plain_FileAttachment()
{
$this->Mail->Body = "Here is the text body";
$this->Mail->Subject .= ": Plain + Multiple FileAttachments";
$this->Mail->Body = 'Here is the text body';
$this->Mail->Subject .= ': Plain + Multiple FileAttachments';
if (!$this->Mail->AddAttachment("test.png")) {
if (!$this->Mail->AddAttachment('test.png')) {
$this->assertTrue(false, $this->Mail->ErrorInfo);
return;
}
if (!$this->Mail->AddAttachment(__FILE__, "test.txt")) {
if (!$this->Mail->AddAttachment(__FILE__, 'test.txt')) {
$this->assertTrue(false, $this->Mail->ErrorInfo);
return;
}
@ -675,14 +674,14 @@ class phpmailerTest extends PHPUnit_Framework_TestCase
function test_Plain_StringAttachment()
{
$this->Mail->Body = "Here is the text body";
$this->Mail->Subject .= ": Plain + StringAttachment";
$this->Mail->Body = 'Here is the text body';
$this->Mail->Subject .= ': Plain + StringAttachment';
$sAttachment = "These characters are the content of the " .
$sAttachment = 'These characters are the content of the ' .
"string attachment.\nThis might be taken from a " .
"database or some other such thing. ";
'database or some other such thing. ';
$this->Mail->AddStringAttachment($sAttachment, "string_attach.txt");
$this->Mail->AddStringAttachment($sAttachment, 'string_attach.txt');
$this->BuildBody();
$this->assertTrue($this->Mail->Send(), $this->Mail->ErrorInfo);
@ -694,9 +693,9 @@ class phpmailerTest extends PHPUnit_Framework_TestCase
function test_Quoted_Printable()
{
$this->Mail->Body = "Here is the main body";
$this->Mail->Subject .= ": Plain + Quoted-printable";
$this->Mail->Encoding = "quoted-printable";
$this->Mail->Body = 'Here is the main body';
$this->Mail->Subject .= ': Plain + Quoted-printable';
$this->Mail->Encoding = 'quoted-printable';
$this->BuildBody();
$this->assertTrue($this->Mail->Send(), $this->Mail->ErrorInfo);
@ -761,14 +760,14 @@ PHPMailer does HTML!
Thank you!
EOT;
$this->assertEquals($this->Mail->Body, $message, "Body not set by MsgHTML");
$this->assertEquals($this->Mail->AltBody, $plainmessage, "AltBody not set by MsgHTML");
$this->assertEquals($this->Mail->Body, $message, 'Body not set by MsgHTML');
$this->assertEquals($this->Mail->AltBody, $plainmessage, 'AltBody not set by MsgHTML');
//Make sure that changes to the original message are reflected when called again
$message = str_replace('PHPMailer', 'bananas', $message);
$plainmessage = str_replace('PHPMailer', 'bananas', $plainmessage);
$this->Mail->MsgHTML($message);
$this->assertEquals($this->Mail->Body, $message, "Body not updated by MsgHTML");
$this->assertEquals($this->Mail->AltBody, $plainmessage, "AltBody not updated by MsgHTML");
$this->assertEquals($this->Mail->Body, $message, 'Body not updated by MsgHTML');
$this->assertEquals($this->Mail->AltBody, $plainmessage, 'AltBody not updated by MsgHTML');
}
/**
* Simple HTML and attachment test
@ -776,11 +775,11 @@ EOT;
function test_HTML_Attachment()
{
$this->Mail->Body = "This is the <strong>HTML</strong> part of the email.";
$this->Mail->Subject .= ": HTML + Attachment";
$this->Mail->Body = 'This is the <strong>HTML</strong> part of the email.';
$this->Mail->Subject .= ': HTML + Attachment';
$this->Mail->IsHTML(true);
if (!$this->Mail->AddAttachment(__FILE__, "test_attach.txt")) {
if (!$this->Mail->AddAttachment(__FILE__, 'test_attach.txt')) {
$this->assertTrue(false, $this->Mail->ErrorInfo);
return;
}
@ -795,17 +794,17 @@ EOT;
function test_Embedded_Image()
{
$this->Mail->Body = "Embedded Image: <img alt=\"phpmailer\" src=\"cid:my-attach\">" .
"Here is an image!</a>";
$this->Mail->Subject .= ": Embedded Image";
$this->Mail->Body = 'Embedded Image: <img alt="phpmailer" src="cid:my-attach">' .
'Here is an image!</a>';
$this->Mail->Subject .= ': Embedded Image';
$this->Mail->IsHTML(true);
if (!$this->Mail->AddEmbeddedImage(
"test.png",
"my-attach",
"test.png",
"base64",
"image/png"
'test.png',
'my-attach',
'test.png',
'base64',
'image/png'
)
) {
$this->assertTrue(false, $this->Mail->ErrorInfo);
@ -826,24 +825,24 @@ EOT;
function test_Multi_Embedded_Image()
{
$this->Mail->Body = "Embedded Image: <img alt=\"phpmailer\" src=\"cid:my-attach\">" .
"Here is an image!</a>";
$this->Mail->Subject .= ": Embedded Image + Attachment";
$this->Mail->Body = 'Embedded Image: <img alt="phpmailer" src="cid:my-attach">' .
'Here is an image!</a>';
$this->Mail->Subject .= ': Embedded Image + Attachment';
$this->Mail->IsHTML(true);
if (!$this->Mail->AddEmbeddedImage(
"test.png",
"my-attach",
"test.png",
"base64",
"image/png"
'test.png',
'my-attach',
'test.png',
'base64',
'image/png'
)
) {
$this->assertTrue(false, $this->Mail->ErrorInfo);
return;
}
if (!$this->Mail->AddAttachment(__FILE__, "test.txt")) {
if (!$this->Mail->AddAttachment(__FILE__, 'test.txt')) {
$this->assertTrue(false, $this->Mail->ErrorInfo);
return;
}
@ -858,13 +857,13 @@ EOT;
function test_AltBody()
{
$this->Mail->Body = "This is the <strong>HTML</strong> part of the email.";
$this->Mail->AltBody = "Here is the text body of this message. " .
"It should be quite a few lines. It should be wrapped at the " .
"40 characters. Make sure that it is.";
$this->Mail->Body = 'This is the <strong>HTML</strong> part of the email.';
$this->Mail->AltBody = 'Here is the text body of this message. ' .
'It should be quite a few lines. It should be wrapped at the ' .
'40 characters. Make sure that it is.';
$this->Mail->WordWrap = 40;
$this->AddNote("This is a mulipart alternative email");
$this->Mail->Subject .= ": AltBody + Word Wrap";
$this->AddNote('This is a mulipart alternative email');
$this->Mail->Subject .= ': AltBody + Word Wrap';
$this->BuildBody();
$this->assertTrue($this->Mail->Send(), $this->Mail->ErrorInfo);
@ -876,12 +875,12 @@ EOT;
function test_AltBody_Attachment()
{
$this->Mail->Body = "This is the <strong>HTML</strong> part of the email.";
$this->Mail->AltBody = "This is the text part of the email.";
$this->Mail->Subject .= ": AltBody + Attachment";
$this->Mail->Body = 'This is the <strong>HTML</strong> part of the email.';
$this->Mail->AltBody = 'This is the text part of the email.';
$this->Mail->Subject .= ': AltBody + Attachment';
$this->Mail->IsHTML(true);
if (!$this->Mail->AddAttachment(__FILE__, "test_attach.txt")) {
if (!$this->Mail->AddAttachment(__FILE__, 'test_attach.txt')) {
$this->assertTrue(false, $this->Mail->ErrorInfo);
return;
}
@ -900,14 +899,14 @@ EOT;
*/
function test_MultipleSend()
{
$this->Mail->Body = "Sending two messages without keepalive";
$this->Mail->Body = 'Sending two messages without keepalive';
$this->BuildBody();
$subject = $this->Mail->Subject;
$this->Mail->Subject = $subject . ": SMTP 1";
$this->Mail->Subject = $subject . ': SMTP 1';
$this->assertTrue($this->Mail->Send(), $this->Mail->ErrorInfo);
$this->Mail->Subject = $subject . ": SMTP 2";
$this->Mail->Subject = $subject . ': SMTP 2';
$this->Mail->Sender = 'blah@example.com';
$this->assertTrue($this->Mail->Send(), $this->Mail->ErrorInfo);
}
@ -917,11 +916,11 @@ EOT;
*/
function test_SendmailSend()
{
$this->Mail->Body = "Sending via sendmail";
$this->Mail->Body = 'Sending via sendmail';
$this->BuildBody();
$subject = $this->Mail->Subject;
$this->Mail->Subject = $subject . ": sendmail";
$this->Mail->Subject = $subject . ': sendmail';
$this->Mail->IsSendmail();
$this->assertTrue($this->Mail->Send(), $this->Mail->ErrorInfo);
}
@ -935,11 +934,11 @@ EOT;
if (strpos($sendmail, '/') === false) { //No path in sendmail_path
ini_set('sendmail_path', '/usr/sbin/sendmail -t -i ');
}
$this->Mail->Body = "Sending via mail()";
$this->Mail->Body = 'Sending via mail()';
$this->BuildBody();
$subject = $this->Mail->Subject;
$this->Mail->Subject = $subject . ": mail()";
$this->Mail->Subject = $subject . ': mail()';
$this->Mail->IsMail();
$this->assertTrue($this->Mail->Send(), $this->Mail->ErrorInfo);
}
@ -949,15 +948,15 @@ EOT;
*/
function test_SmtpKeepAlive()
{
$this->Mail->Body = "This was done using the SMTP keep-alive.";
$this->Mail->Body = 'This was done using the SMTP keep-alive.';
$this->BuildBody();
$subject = $this->Mail->Subject;
$this->Mail->SMTPKeepAlive = true;
$this->Mail->Subject = $subject . ": SMTP keep-alive 1";
$this->Mail->Subject = $subject . ': SMTP keep-alive 1';
$this->assertTrue($this->Mail->Send(), $this->Mail->ErrorInfo);
$this->Mail->Subject = $subject . ": SMTP keep-alive 2";
$this->Mail->Subject = $subject . ': SMTP keep-alive 2';
$this->assertTrue($this->Mail->Send(), $this->Mail->ErrorInfo);
$this->Mail->SmtpClose();
}
@ -968,27 +967,40 @@ EOT;
*/
function test_DenialOfServiceAttack()
{
$this->Mail->Body = "This should no longer cause a denial of service.";
$this->Mail->Body = 'This should no longer cause a denial of service.';
$this->BuildBody();
$this->Mail->Subject = str_repeat("A", 998);
$this->Mail->Subject = str_repeat('A', 998);
$this->assertTrue($this->Mail->Send(), $this->Mail->ErrorInfo);
}
/**
* Tests this denial of service attack:
* https://sourceforge.net/p/phpmailer/bugs/383/
* According to the ticket, this should get stuck in a loop, though I can't make it happen.
*/
function test_DenialOfServiceAttack2()
{
//Encoding name longer than 68 chars
$this->Mail->Encoding = '1234567890123456789012345678901234567890123456789012345678901234567890';
//Call WrapText with a zero length value
$t = $this->Mail->WrapText(str_repeat('This should no longer cause a denial of service. ', 30), 0);
}
/**
* Test error handling
*/
function test_Error()
{
$this->Mail->Subject .= ": This should be sent";
$this->Mail->Subject .= ': This should be sent';
$this->BuildBody();
$this->Mail->ClearAllRecipients(); // no addresses should cause an error
$this->assertTrue($this->Mail->IsError() == false, "Error found");
$this->assertTrue($this->Mail->Send() == false, "Send succeeded");
$this->assertTrue($this->Mail->IsError(), "No error found");
$this->assertTrue($this->Mail->IsError() == false, 'Error found');
$this->assertTrue($this->Mail->Send() == false, 'Send succeeded');
$this->assertTrue($this->Mail->IsError(), 'No error found');
$this->assertEquals('You must provide at least one recipient email address.', $this->Mail->ErrorInfo);
$this->Mail->AddAddress($_REQUEST['mail_to']);
$this->assertTrue($this->Mail->Send(), "Send failed");
$this->assertTrue($this->Mail->Send(), 'Send failed');
}
/**
@ -1013,6 +1025,18 @@ EOT;
$this->Mail->ClearReplyTos();
}
/**
* Test BCC-only addressing
*/
function test_BCCAddressing()
{
$this->Mail->Subject .= ': BCC-only addressing';
$this->BuildBody();
$this->Mail->ClearAllRecipients();
$this->assertTrue($this->Mail->AddBCC('a@example.com'), 'BCC addressing failed');
$this->assertTrue($this->Mail->Send(), 'Send failed');
}
/**
* Encoding tests
*/