Skip to content
This repository
Browse code

Add tests for contentDisposition flag.

Fixes #3042
  • Loading branch information...
commit 6ce4a3a1ec5994e2b60180875812f6953d0490bf 1 parent 9deb966
Mark Story authored July 21, 2012
5  lib/Cake/Network/Email/CakeEmail.php
@@ -1355,7 +1355,10 @@ protected function _attachFiles($boundary = null) {
1355 1355
 			$msg[] = '--' . $boundary;
1356 1356
 			$msg[] = 'Content-Type: ' . $fileInfo['mimetype'];
1357 1357
 			$msg[] = 'Content-Transfer-Encoding: base64';
1358  
-			if (!isset($fileInfo['contentDisposition']) || $fileInfo['contentDisposition']) {
  1358
+			if (
  1359
+				!isset($fileInfo['contentDisposition']) ||
  1360
+				$fileInfo['contentDisposition']
  1361
+			) {
1359 1362
 				$msg[] = 'Content-Disposition: attachment; filename="' . $filename . '"';
1360 1363
 			}
1361 1364
 			$msg[] = '';
48  lib/Cake/Test/Case/Network/Email/CakeEmailTest.php
@@ -640,13 +640,20 @@ public function testViewVars() {
640 640
  */
641 641
 	public function testAttachments() {
642 642
 		$this->CakeEmail->attachments(CAKE . 'basics.php');
643  
-		$expected = array('basics.php' => array('file' => CAKE . 'basics.php', 'mimetype' => 'application/octet-stream'));
  643
+		$expected = array(
  644
+			'basics.php' => array(
  645
+				'file' => CAKE . 'basics.php',
  646
+				'mimetype' => 'application/octet-stream'
  647
+			)
  648
+		);
644 649
 		$this->assertSame($this->CakeEmail->attachments(), $expected);
645 650
 
646 651
 		$this->CakeEmail->attachments(array());
647 652
 		$this->assertSame($this->CakeEmail->attachments(), array());
648 653
 
649  
-		$this->CakeEmail->attachments(array(array('file' => CAKE . 'basics.php', 'mimetype' => 'text/plain')));
  654
+		$this->CakeEmail->attachments(array(
  655
+			array('file' => CAKE . 'basics.php', 'mimetype' => 'text/plain')
  656
+		));
650 657
 		$this->CakeEmail->addAttachments(CAKE . 'bootstrap.php');
651 658
 		$this->CakeEmail->addAttachments(array(CAKE . 'bootstrap.php'));
652 659
 		$this->CakeEmail->addAttachments(array('other.txt' => CAKE . 'bootstrap.php', 'license' => CAKE . 'LICENSE.txt'));
@@ -938,6 +945,43 @@ public function testSendWithInlineAttachments() {
938 945
 	}
939 946
 
940 947
 /**
  948
+ * Test disabling content-disposition.
  949
+ *
  950
+ * @return void
  951
+ */
  952
+	public function testSendWithNoContentDispositionAttachments() {
  953
+		$this->CakeEmail->transport('debug');
  954
+		$this->CakeEmail->from('cake@cakephp.org');
  955
+		$this->CakeEmail->to('cake@cakephp.org');
  956
+		$this->CakeEmail->subject('My title');
  957
+		$this->CakeEmail->emailFormat('text');
  958
+		$this->CakeEmail->attachments(array(
  959
+			'cake.png' => array(
  960
+				'file' => CAKE . 'VERSION.txt',
  961
+				'contentDisposition' => false
  962
+			)
  963
+		));
  964
+		$result = $this->CakeEmail->send('Hello');
  965
+
  966
+		$boundary = $this->CakeEmail->getBoundary();
  967
+		$this->assertContains('Content-Type: multipart/mixed; boundary="' . $boundary . '"', $result['headers']);
  968
+		$expected = "--$boundary\r\n" .
  969
+			"Content-Type: text/plain; charset=UTF-8\r\n" .
  970
+			"Content-Transfer-Encoding: 8bit\r\n" .
  971
+			"\r\n" .
  972
+			"Hello" .
  973
+			"\r\n" .
  974
+			"\r\n" .
  975
+			"\r\n" .
  976
+			"--{$boundary}\r\n" .
  977
+			"Content-Type: application/octet-stream\r\n" .
  978
+			"Content-Transfer-Encoding: base64\r\n" .
  979
+			"\r\n";
  980
+
  981
+		$this->assertContains($expected, $result['message']);
  982
+		$this->assertContains('--' . $boundary . '--', $result['message']);
  983
+	}
  984
+/**
941 985
  * testSendWithLog method
942 986
  *
943 987
  * @return void

0 notes on commit 6ce4a3a

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