sendPlain( '', 'tom@jones ', "What is the of testing?", $testMessage, null, array('CC' => 'admin@silverstripe.com', 'bcc' => 'andrew@thing.com') ); $this->assertEquals('email@silverstripe.com', $to); $this->assertEquals('=?UTF-8?B?V2hhdCBpcyB0aGUgPHB1cnBvc2U+IG9mIHRlc3Rpbmc/?=', $subjectEncoded); $this->assertEquals('=?UTF-8?B?'. base64_encode('What is the of testing?').'?=', $subjectEncoded); $this->assertEquals(<<assertEquals($testMessage, quoted_printable_decode($fullBody)); $this->assertEquals(<< X-Mailer: SilverStripe Mailer - version 2006.06.21 X-Priority: 3 Bcc: andrew@thing.com Cc: admin@silverstripe.com PHP , Convert::nl2os($headersEncoded) ); $this->assertEquals('tom@silverstripe.com', $bounceAddress); // Test override bounce email and alternate encoding $mailer->setBounceEmail('bounce@silverstripe.com'); $mailer->setMessageEncoding('base64'); list($to, $subjectEncoded, $fullBody, $headersEncoded, $bounceAddress) = $mailer->sendPlain( '', 'tom@jones ', "What is the of testing?", $testMessage, null, array('CC' => 'admin@silverstripe.com', 'bcc' => 'andrew@thing.com') ); $this->assertEquals('bounce@silverstripe.com', $bounceAddress); $this->assertEquals(<<assertEquals($testMessage, base64_decode($fullBody)); } /** * Test HTML messages */ public function testSendHTML() { $mailer = new MailerTest_MockMailer(); // Test with default encoding $testMessageHTML = "

The majority of the answers so far are saying that private methods are " . "implementation details which don't (or at least shouldn't) ". "matter so long as the public interface is well-tested & working

". "

That's absolutely correct if your only purpose for testing is to guarantee that the ". "public interface works.

"; $testMessagePlain = Convert::xml2raw($testMessageHTML); $this->assertTrue(stripos($testMessagePlain, '&#') === false); list($to, $subjectEncoded, $fullBody, $headersEncoded, $bounceAddress) = $mailer->sendHTML( '', 'tom@jones ', "What is the of testing?", $testMessageHTML, null, array('CC' => 'admin@silverstripe.com', 'bcc' => 'andrew@thing.com') ); $this->assertEquals('email@silverstripe.com', $to); $this->assertEquals('=?UTF-8?B?V2hhdCBpcyB0aGUgPHB1cnBvc2U+IG9mIHRlc3Rpbmc/?=', $subjectEncoded); $this->assertEquals('=?UTF-8?B?'. base64_encode('What is the of testing?').'?=', $subjectEncoded); $this->assertEquals(Convert::nl2os(<<=0A=0A=0A=0A=0A=0A=0A

The majority of the answers so far are saying that priva= te methods are implementation details which don't (or at least shouldn't) matter so long as the public i= nterface is well-tested & working

That's absolutely correct = if your only purpose for testing is to guarantee that the public interface = works.

=0A=0A ------=_NextPart_000000000000-- PHP ), Convert::nl2os($this->normaliseDivisions($fullBody)) ); // Check that the messages exist in the output $this->assertTrue(stripos($fullBody, quoted_printable_encode($testMessagePlain)) !== false); $this->assertEquals(<< X-Mailer: SilverStripe Mailer - version 2006.06.21 X-Priority: 3 Bcc: andrew@thing.com Cc: admin@silverstripe.com PHP , Convert::nl2os($this->normaliseDivisions($headersEncoded)) ); $this->assertEquals('tom@silverstripe.com', $bounceAddress); // Test override bounce email and alternate encoding $mailer->setBounceEmail('bounce@silverstripe.com'); $mailer->setMessageEncoding('base64'); list($to, $subjectEncoded, $fullBody, $headersEncoded, $bounceAddress) = $mailer->sendHTML( '', 'tom@jones ', "What is the of testing?", $testMessageHTML, null, array('CC' => 'admin@silverstripe.com', 'bcc' => 'andrew@thing.com') ); $this->assertEquals('bounce@silverstripe.com', $bounceAddress); $this->assertEquals(<<normaliseDivisions($fullBody)) ); // Check that the text message version is somewhere in there $this->assertTrue(stripos($fullBody, chunk_split(base64_encode($testMessagePlain), 60)) !== false); } } /** * Mocks the sending of emails without actually sending anything */ class MailerTest_MockMailer extends Mailer implements TestOnly { protected function email($to, $subjectEncoded, $fullBody, $headersEncoded, $bounceAddress) { return array($to, $subjectEncoded, $fullBody, $headersEncoded, $bounceAddress); } }