From 34eedcc017533fd4f97431ad9b38a5309c424f18 Mon Sep 17 00:00:00 2001 From: Mark Story Date: Mon, 26 Dec 2011 19:36:35 -0500 Subject: [PATCH] Add a few regression tests for CakeEmail. --- .../Test/Case/Network/Email/CakeEmailTest.php | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/lib/Cake/Test/Case/Network/Email/CakeEmailTest.php b/lib/Cake/Test/Case/Network/Email/CakeEmailTest.php index 701e29cb288..4ee443c4e93 100644 --- a/lib/Cake/Test/Case/Network/Email/CakeEmailTest.php +++ b/lib/Cake/Test/Case/Network/Email/CakeEmailTest.php @@ -745,6 +745,68 @@ public function testSendWithoutTo() { $this->CakeEmail->send("Forgot to set To"); } +/** + * Test send() with no template. + * + * @return void + */ + public function testSendNoTemplateWithAttachments() { + $this->CakeEmail->transport('debug'); + $this->CakeEmail->from('cake@cakephp.org'); + $this->CakeEmail->to('cake@cakephp.org'); + $this->CakeEmail->subject('My title'); + $this->CakeEmail->emailFormat('text'); + $this->CakeEmail->attachments(array(CAKE . 'basics.php')); + $result = $this->CakeEmail->send('Hello'); + + $boundary = $this->CakeEmail->getBoundary(); + $this->assertContains('Content-Type: multipart/mixed; boundary="' . $boundary . '"', $result['headers']); + $expected = "--$boundary\r\n" . + "Content-Type: text/plain; charset=UTF-8\r\n" . + "Content-Transfer-Encoding: 8bit\r\n" . + "\r\n" . + "Hello" . + "\r\n" . + "\r\n" . + "\r\n" . + "--$boundary\r\n" . + "Content-Type: application/octet-stream\r\n" . + "Content-Transfer-Encoding: base64\r\n" . + "Content-Disposition: attachment; filename=\"basics.php\"\r\n\r\n"; + $this->assertContains($expected, $result['message']); + } + +/** + * Test send() with no template as both + * + * @return void + */ + public function testSendNoTemplateWithAttachmentsAsBoth() { + $this->CakeEmail->transport('debug'); + $this->CakeEmail->from('cake@cakephp.org'); + $this->CakeEmail->to('cake@cakephp.org'); + $this->CakeEmail->subject('My title'); + $this->CakeEmail->emailFormat('both'); + $this->CakeEmail->attachments(array(CAKE . 'VERSION.txt')); + $result = $this->CakeEmail->send('Hello'); + + $boundary = $this->CakeEmail->getBoundary(); + $this->assertContains('Content-Type: multipart/mixed; boundary="' . $boundary . '"', $result['headers']); + $expected = "--$boundary\r\n" . + "Content-Type: multipart/alternative; boundary=\"alt-$boundary\"\r\n" . + "Content-Transfer-Encoding: 8bit\r\n" . + "\r\n" . + "Hello" . + "\r\n" . + "\r\n" . + "\r\n" . + "--$boundary\r\n" . + "Content-Type: application/octet-stream\r\n" . + "Content-Transfer-Encoding: base64\r\n" . + "Content-Disposition: attachment; filename=\"VERSION.txt\"\r\n\r\n"; + $this->assertContains($expected, $result['message']); + } + /** * testSendWithLog method *