Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add tests for contentDisposition flag.

Fixes #3042
  • Loading branch information...
commit 6ce4a3a1ec5994e2b60180875812f6953d0490bf 1 parent 9deb966
@markstory markstory authored
View
5 lib/Cake/Network/Email/CakeEmail.php
@@ -1355,7 +1355,10 @@ protected function _attachFiles($boundary = null) {
$msg[] = '--' . $boundary;
$msg[] = 'Content-Type: ' . $fileInfo['mimetype'];
$msg[] = 'Content-Transfer-Encoding: base64';
- if (!isset($fileInfo['contentDisposition']) || $fileInfo['contentDisposition']) {
+ if (
+ !isset($fileInfo['contentDisposition']) ||
+ $fileInfo['contentDisposition']
+ ) {
$msg[] = 'Content-Disposition: attachment; filename="' . $filename . '"';
}
$msg[] = '';
View
48 lib/Cake/Test/Case/Network/Email/CakeEmailTest.php
@@ -640,13 +640,20 @@ public function testViewVars() {
*/
public function testAttachments() {
$this->CakeEmail->attachments(CAKE . 'basics.php');
- $expected = array('basics.php' => array('file' => CAKE . 'basics.php', 'mimetype' => 'application/octet-stream'));
+ $expected = array(
+ 'basics.php' => array(
+ 'file' => CAKE . 'basics.php',
+ 'mimetype' => 'application/octet-stream'
+ )
+ );
$this->assertSame($this->CakeEmail->attachments(), $expected);
$this->CakeEmail->attachments(array());
$this->assertSame($this->CakeEmail->attachments(), array());
- $this->CakeEmail->attachments(array(array('file' => CAKE . 'basics.php', 'mimetype' => 'text/plain')));
+ $this->CakeEmail->attachments(array(
+ array('file' => CAKE . 'basics.php', 'mimetype' => 'text/plain')
+ ));
$this->CakeEmail->addAttachments(CAKE . 'bootstrap.php');
$this->CakeEmail->addAttachments(array(CAKE . 'bootstrap.php'));
$this->CakeEmail->addAttachments(array('other.txt' => CAKE . 'bootstrap.php', 'license' => CAKE . 'LICENSE.txt'));
@@ -938,6 +945,43 @@ public function testSendWithInlineAttachments() {
}
/**
+ * Test disabling content-disposition.
+ *
+ * @return void
+ */
+ public function testSendWithNoContentDispositionAttachments() {
+ $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.png' => array(
+ 'file' => CAKE . 'VERSION.txt',
+ 'contentDisposition' => false
+ )
+ ));
+ $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" .
+ "\r\n";
+
+ $this->assertContains($expected, $result['message']);
+ $this->assertContains('--' . $boundary . '--', $result['message']);
+ }
+/**
* testSendWithLog method
*
* @return void
Please sign in to comment.
Something went wrong with that request. Please try again.