Skip to content
This repository
Browse code

Add a few regression tests for CakeEmail.

  • Loading branch information...
commit 34eedcc017533fd4f97431ad9b38a5309c424f18 1 parent bbef4aa
Mark Story authored December 26, 2011
62  lib/Cake/Test/Case/Network/Email/CakeEmailTest.php
@@ -746,6 +746,68 @@ public function testSendWithoutTo() {
746 746
 	}
747 747
 
748 748
 /**
  749
+ * Test send() with no template.
  750
+ *
  751
+ * @return void
  752
+ */
  753
+	public function testSendNoTemplateWithAttachments() {
  754
+		$this->CakeEmail->transport('debug');
  755
+		$this->CakeEmail->from('cake@cakephp.org');
  756
+		$this->CakeEmail->to('cake@cakephp.org');
  757
+		$this->CakeEmail->subject('My title');
  758
+		$this->CakeEmail->emailFormat('text');
  759
+		$this->CakeEmail->attachments(array(CAKE . 'basics.php'));
  760
+		$result = $this->CakeEmail->send('Hello');
  761
+
  762
+		$boundary = $this->CakeEmail->getBoundary();
  763
+		$this->assertContains('Content-Type: multipart/mixed; boundary="' . $boundary . '"', $result['headers']);
  764
+		$expected = "--$boundary\r\n" .
  765
+			"Content-Type: text/plain; charset=UTF-8\r\n" .
  766
+			"Content-Transfer-Encoding: 8bit\r\n" .
  767
+			"\r\n" .
  768
+			"Hello" .
  769
+			"\r\n" .
  770
+			"\r\n" .
  771
+			"\r\n" .
  772
+			"--$boundary\r\n" .
  773
+			"Content-Type: application/octet-stream\r\n" .
  774
+			"Content-Transfer-Encoding: base64\r\n" .
  775
+			"Content-Disposition: attachment; filename=\"basics.php\"\r\n\r\n";
  776
+		$this->assertContains($expected, $result['message']);
  777
+	}
  778
+
  779
+/**
  780
+ * Test send() with no template as both
  781
+ *
  782
+ * @return void
  783
+ */
  784
+	public function testSendNoTemplateWithAttachmentsAsBoth() {
  785
+		$this->CakeEmail->transport('debug');
  786
+		$this->CakeEmail->from('cake@cakephp.org');
  787
+		$this->CakeEmail->to('cake@cakephp.org');
  788
+		$this->CakeEmail->subject('My title');
  789
+		$this->CakeEmail->emailFormat('both');
  790
+		$this->CakeEmail->attachments(array(CAKE . 'VERSION.txt'));
  791
+		$result = $this->CakeEmail->send('Hello');
  792
+
  793
+		$boundary = $this->CakeEmail->getBoundary();
  794
+		$this->assertContains('Content-Type: multipart/mixed; boundary="' . $boundary . '"', $result['headers']);
  795
+		$expected = "--$boundary\r\n" .
  796
+			"Content-Type: multipart/alternative; boundary=\"alt-$boundary\"\r\n" .
  797
+			"Content-Transfer-Encoding: 8bit\r\n" .
  798
+			"\r\n" .
  799
+			"Hello" .
  800
+			"\r\n" .
  801
+			"\r\n" .
  802
+			"\r\n" .
  803
+			"--$boundary\r\n" .
  804
+			"Content-Type: application/octet-stream\r\n" .
  805
+			"Content-Transfer-Encoding: base64\r\n" .
  806
+			"Content-Disposition: attachment; filename=\"VERSION.txt\"\r\n\r\n";
  807
+		$this->assertContains($expected, $result['message']);
  808
+	}
  809
+
  810
+/**
749 811
  * testSendWithLog method
750 812
  *
751 813
  * @return void

0 notes on commit 34eedcc

Please sign in to comment.
Something went wrong with that request. Please try again.