Skip to content

Commit

Permalink
Add a few regression tests for CakeEmail.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Dec 28, 2011
1 parent bbef4aa commit 34eedcc
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions lib/Cake/Test/Case/Network/Email/CakeEmailTest.php
Expand Up @@ -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
*
Expand Down

0 comments on commit 34eedcc

Please sign in to comment.