diff --git a/test/phpmailer_test.php b/test/phpmailer_test.php index ffbe4bd4..61456c47 100644 --- a/test/phpmailer_test.php +++ b/test/phpmailer_test.php @@ -141,15 +141,16 @@ class phpmailerTest extends TestCase $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; } @@ -242,14 +243,11 @@ class phpmailerTest extends TestCase 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); } } @@ -465,10 +463,11 @@ class phpmailerTest extends TestCase $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() { @@ -521,6 +520,17 @@ class phpmailerTest extends TestCase $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)'); + } } /** diff --git a/test/phpunit.php b/test/phpunit.php index 8c7256e3..7d1a64a3 100644 --- a/test/phpunit.php +++ b/test/phpunit.php @@ -34,7 +34,7 @@ error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE | /* interface Test { - function run(&$aTestResult); + function run($aTestResult); function countTestCases(); } */ @@ -103,7 +103,7 @@ class TestCase extends Assert /* implements Test */ { $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 @@ -114,7 +114,7 @@ class TestCase extends Assert /* implements Test */ { if (! $testResult) $testResult = $this->_createResult(); $this->fResult = $testResult; - $testResult->run(&$this); + $testResult->run($this); $this->fResult = 0; return $testResult; } @@ -149,7 +149,7 @@ class TestCase extends Assert /* implements Test */ { //printf("TestCase::fail(%s)
\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) { @@ -223,14 +223,14 @@ class TestSuite /* implements 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); } } @@ -294,7 +294,7 @@ class TestResult { /* 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); }