Skip to content

Commit

Permalink
Update unit test class so it doesn't generate warnings for call-time …
Browse files Browse the repository at this point in the history
…pass-by-reference errors in PHP5

Fix attachment tests to use new GetAttachments function instead of trying to access the private $attachments property
Check that local dir is writable before trying to write file (and use neater PHP5 syntax)
Add tests for new duplicate address checking on AddAddress, AddCC, AddBCC
  • Loading branch information
Synchro committed Nov 20, 2008
1 parent 91b3277 commit 5aeead7
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 22 deletions.
40 changes: 25 additions & 15 deletions test/phpmailer_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,16 @@ function BuildBody() {
$ReportBody .= "Host: " . $this->Mail->Host . $eol;

// If attachments then create an attachment list
if(count($this->Mail->attachment) > 0)
$attachments = $this->Mail->GetAttachments();
if(count($attachments) > 0)
{
$ReportBody .= "Attachments:" . $eol;
$ReportBody .= $bullet_start;
for($i = 0; $i < count($this->Mail->attachment); $i++)
for($i = 0; $i < count($attachments); $i++)
{
$ReportBody .= $bullet . "Name: " . $this->Mail->attachment[$i][1] . ", ";
$ReportBody .= "Encoding: " . $this->Mail->attachment[$i][3] . ", ";
$ReportBody .= "Type: " . $this->Mail->attachment[$i][4] . $eol;
$ReportBody .= $bullet . "Name: " . $attachments[$i][1] . ", ";
$ReportBody .= "Encoding: " . $attachments[$i][3] . ", ";
$ReportBody .= "Type: " . $attachments[$i][4] . $eol;
}
$ReportBody .= $bullet_end . $eol;
}
Expand Down Expand Up @@ -242,14 +243,11 @@ function SetAddress($sAddress, $sName = "", $sType = "to") {
switch($sType)
{
case "to":
$this->Mail->AddAddress($sAddress, $sName);
break;
return $this->Mail->AddAddress($sAddress, $sName);
case "cc":
$this->Mail->AddCC($sAddress, $sName);
break;
return $this->Mail->AddCC($sAddress, $sName);
case "bcc":
$this->Mail->AddBCC($sAddress, $sName);
break;
return $this->Mail->AddBCC($sAddress, $sName);
}
}

Expand Down Expand Up @@ -465,10 +463,11 @@ function test_AltBody_Attachment() {

$this->BuildBody();
$this->assert($this->Mail->Send(), $this->Mail->ErrorInfo);

$fp = fopen("message.txt", "w");
fwrite($fp, $this->Mail->CreateHeader() . $this->Mail->CreateBody());
fclose($fp);
if (is_writable('.')) {
file_put_contents('message.txt', $this->Mail->CreateHeader() . $this->Mail->CreateBody());
} else {
$this->assert(false, 'Could not write local file - check permissions');
}
}

function test_MultipleSend() {
Expand Down Expand Up @@ -521,6 +520,17 @@ function test_Error() {
$this->Mail->AddAddress(get("mail_to"));
$this->assert($this->Mail->Send(), "Send failed");
}

function test_Addressing() {
$this->assert($this->Mail->AddAddress('a@example.com'), 'Addressing failed');
$this->assert(!$this->Mail->AddAddress('a@example.com'), 'Duplicate addressing failed');
$this->assert($this->Mail->AddCC('b@example.com'), 'CC addressing failed');
$this->assert(!$this->Mail->AddCC('b@example.com'), 'CC duplicate Addressing failed');
$this->assert(!$this->Mail->AddCC('a@example.com'), 'CC duplicate Addressing failed (2)');
$this->assert($this->Mail->AddBCC('c@example.com'), 'BCC addressing failed');
$this->assert(!$this->Mail->AddBCC('c@example.com'), 'BCC duplicate addressing failed');
$this->assert(!$this->Mail->AddBCC('a@example.com'), 'BCC duplicate Addressing failed (2)');
}
}

/**
Expand Down
14 changes: 7 additions & 7 deletions test/phpunit.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

/*
interface Test {
function run(&$aTestResult);
function run($aTestResult);
function countTestCases();
}
*/
Expand Down Expand Up @@ -103,7 +103,7 @@ function TestCase($name) {
$this->fName = $name;
}

function run($testResult=0) {
function run(&$testResult=0) {
/* Run this single test, by calling the run() method of the
TestResult object which will in turn call the runBare() method
of this object. That complication allows the TestResult object
Expand All @@ -114,7 +114,7 @@ function run($testResult=0) {
if (! $testResult)
$testResult = $this->_createResult();
$this->fResult = $testResult;
$testResult->run(&$this);
$testResult->run($this);
$this->fResult = 0;
return $testResult;
}
Expand Down Expand Up @@ -149,7 +149,7 @@ function fail($message=0) {
//printf("TestCase::fail(%s)<br>\n", ($message) ? $message : '');
/* JUnit throws AssertionFailedError here. We just record the
failure and carry on */
$this->fExceptions[] = new Exception(&$message);
$this->fExceptions[] = new Exception($message);
}

function error($message) {
Expand Down Expand Up @@ -223,14 +223,14 @@ function addTest($test) {
$this->fTests[] = $test;
}

function run(&$testResult) {
function run($testResult) {
/* Run all TestCases and TestSuites comprising this TestSuite,
accumulating results in the given TestResult object. */
reset($this->fTests);
while (list($na, $test) = each($this->fTests)) {
if ($testResult->shouldStop())
break;
$test->run(&$testResult);
$test->run($testResult);
}
}

Expand Down Expand Up @@ -294,7 +294,7 @@ function run($test) {
/* this is where JUnit would catch AssertionFailedError */
$exceptions = $test->getExceptions();
if ($exceptions)
$this->fFailures[] = new TestFailure(&$test, &$exceptions);
$this->fFailures[] = new TestFailure($test, $exceptions);
$this->_endTest($test);
}

Expand Down

0 comments on commit 5aeead7

Please sign in to comment.