Permalink
Browse files

Add a few regression tests for CakeEmail.

  • Loading branch information...
1 parent bbef4aa commit 34eedcc017533fd4f97431ad9b38a5309c424f18 @markstory markstory committed Dec 27, 2011
Showing with 62 additions and 0 deletions.
  1. +62 −0 lib/Cake/Test/Case/Network/Email/CakeEmailTest.php
@@ -746,6 +746,68 @@ public function testSendWithoutTo() {
}
/**
+ * 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
*
* @return void

0 comments on commit 34eedcc

Please sign in to comment.