2008-05-30 11:40:08 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2009-03-18 17:55:58 +00:00
|
|
|
* EmailComponentTest file
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2009-03-18 17:55:58 +00:00
|
|
|
* Series of tests for email component.
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2010-10-03 16:31:21 +00:00
|
|
|
* PHP 5
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2010-05-19 01:15:13 +00:00
|
|
|
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
|
2012-03-13 02:46:07 +00:00
|
|
|
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2010-10-03 16:31:21 +00:00
|
|
|
* Licensed under The MIT License
|
|
|
|
* Redistributions of files must retain the above copyright notice
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2012-03-13 02:46:07 +00:00
|
|
|
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2010-05-19 01:15:13 +00:00
|
|
|
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Controller.Component
|
2008-10-30 17:30:26 +00:00
|
|
|
* @since CakePHP(tm) v 1.2.0.5347
|
2010-10-03 16:27:27 +00:00
|
|
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-12-09 05:55:24 +00:00
|
|
|
App::uses('Controller', 'Controller');
|
|
|
|
App::uses('EmailComponent', 'Controller/Component');
|
2011-04-17 17:54:38 +00:00
|
|
|
App::uses('AbstractTransport', 'Network/Email');
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-04-24 18:20:51 +00:00
|
|
|
/**
|
|
|
|
* EmailTestComponent class
|
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Controller.Component
|
2009-04-24 18:20:51 +00:00
|
|
|
*/
|
|
|
|
class EmailTestComponent extends EmailComponent {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-07-02 02:58:43 +00:00
|
|
|
/**
|
|
|
|
* Convenience method for testing.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function strip($content, $message = false) {
|
2009-03-22 04:19:20 +00:00
|
|
|
return parent::_strip($content, $message);
|
2009-07-02 02:58:43 +00:00
|
|
|
}
|
2010-09-02 15:16:10 +00:00
|
|
|
|
2009-04-24 18:20:51 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2011-04-17 17:54:38 +00:00
|
|
|
/**
|
|
|
|
* DebugCompTransport class
|
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Controller.Component
|
2011-04-17 17:54:38 +00:00
|
|
|
*/
|
|
|
|
class DebugCompTransport extends AbstractTransport {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Last email
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
public static $lastEmail = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Send mail
|
|
|
|
*
|
|
|
|
* @params object $email CakeEmail
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
public function send(CakeEmail $email) {
|
2011-11-22 16:21:00 +00:00
|
|
|
$email->addHeaders(array('Date' => EmailComponentTest::$sentDate));
|
2011-04-17 17:54:38 +00:00
|
|
|
$headers = $email->getHeaders(array_fill_keys(array('from', 'replyTo', 'readReceipt', 'returnPath', 'to', 'cc', 'bcc', 'subject'), true));
|
|
|
|
$to = $headers['To'];
|
|
|
|
$subject = $headers['Subject'];
|
|
|
|
unset($headers['To'], $headers['Subject']);
|
|
|
|
|
|
|
|
$message = implode("\n", $email->message());
|
|
|
|
|
|
|
|
$last = '<pre>';
|
|
|
|
$last .= sprintf("%s %s\n", 'To:', $to);
|
|
|
|
$last .= sprintf("%s %s\n", 'From:', $headers['From']);
|
|
|
|
$last .= sprintf("%s %s\n", 'Subject:', $subject);
|
|
|
|
$last .= sprintf("%s\n\n%s", 'Header:', $this->_headersToString($headers, "\n"));
|
|
|
|
$last .= sprintf("%s\n\n%s", 'Message:', $message);
|
|
|
|
$last .= '</pre>';
|
|
|
|
|
|
|
|
self::$lastEmail = $last;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* EmailTestController class
|
2008-06-11 08:54:27 +00:00
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Controller.Component
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
class EmailTestController extends Controller {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* name property
|
2008-06-11 08:54:27 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var string 'EmailTest'
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $name = 'EmailTest';
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* uses property
|
2008-06-11 08:54:27 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var mixed null
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $uses = null;
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* components property
|
2008-06-11 08:54:27 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var array
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $components = array('Session', 'EmailTest');
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* EmailTest class
|
2008-06-11 08:54:27 +00:00
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Controller.Component
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2009-03-18 17:55:58 +00:00
|
|
|
class EmailComponentTest extends CakeTestCase {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-03-18 17:55:58 +00:00
|
|
|
/**
|
|
|
|
* Controller property
|
|
|
|
*
|
|
|
|
* @var EmailTestController
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $Controller;
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* name property
|
2008-06-11 08:54:27 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var string 'Email'
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $name = 'Email';
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2011-11-22 16:21:00 +00:00
|
|
|
/**
|
|
|
|
* sentDate
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
public static $sentDate = null;
|
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* setUp method
|
2008-06-11 08:54:27 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function setUp() {
|
2012-04-16 02:20:34 +00:00
|
|
|
parent::setUp();
|
|
|
|
|
2009-03-21 23:55:39 +00:00
|
|
|
Configure::write('App.encoding', 'UTF-8');
|
|
|
|
|
2010-06-10 13:42:13 +00:00
|
|
|
$this->Controller = new EmailTestController();
|
2010-07-05 00:31:23 +00:00
|
|
|
$this->Controller->Components->init($this->Controller);
|
2009-04-24 18:20:51 +00:00
|
|
|
$this->Controller->EmailTest->initialize($this->Controller, array());
|
2009-03-21 23:55:39 +00:00
|
|
|
|
2011-11-22 16:21:00 +00:00
|
|
|
self::$sentDate = date(DATE_RFC2822);
|
|
|
|
|
2009-06-11 16:13:16 +00:00
|
|
|
App::build(array(
|
2012-03-12 02:20:25 +00:00
|
|
|
'View' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS)
|
2009-06-11 16:13:16 +00:00
|
|
|
));
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testSendFormats method
|
2008-06-11 08:54:27 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testSendFormats() {
|
2011-04-17 17:54:38 +00:00
|
|
|
$this->Controller->EmailTest->to = 'postmaster@example.com';
|
2009-04-24 18:20:51 +00:00
|
|
|
$this->Controller->EmailTest->from = 'noreply@example.com';
|
|
|
|
$this->Controller->EmailTest->subject = 'Cake SMTP test';
|
|
|
|
$this->Controller->EmailTest->replyTo = 'noreply@example.com';
|
|
|
|
$this->Controller->EmailTest->template = null;
|
2011-04-17 17:54:38 +00:00
|
|
|
$this->Controller->EmailTest->delivery = 'DebugComp';
|
2010-01-24 22:29:53 +00:00
|
|
|
$this->Controller->EmailTest->messageId = false;
|
2008-11-11 19:52:41 +00:00
|
|
|
|
2011-11-22 16:21:00 +00:00
|
|
|
$date = self::$sentDate;
|
2008-11-11 19:52:41 +00:00
|
|
|
$message = <<<MSGBLOC
|
2011-04-17 17:54:38 +00:00
|
|
|
<pre>To: postmaster@example.com
|
2008-05-30 11:40:08 +00:00
|
|
|
From: noreply@example.com
|
|
|
|
Subject: Cake SMTP test
|
|
|
|
Header:
|
|
|
|
|
|
|
|
From: noreply@example.com
|
|
|
|
Reply-To: noreply@example.com
|
|
|
|
X-Mailer: CakePHP Email Component
|
2011-04-17 17:54:38 +00:00
|
|
|
Date: $date
|
2011-04-21 04:09:33 +00:00
|
|
|
MIME-Version: 1.0
|
2008-07-24 13:54:39 +00:00
|
|
|
Content-Type: {CONTENTTYPE}
|
2011-10-22 13:28:47 +00:00
|
|
|
Content-Transfer-Encoding: 8bitMessage:
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
This is the body of the message
|
|
|
|
|
|
|
|
</pre>
|
2008-07-24 13:54:39 +00:00
|
|
|
MSGBLOC;
|
2011-04-17 17:54:38 +00:00
|
|
|
|
2009-04-24 18:20:51 +00:00
|
|
|
$this->Controller->EmailTest->sendAs = 'text';
|
2008-11-11 19:52:41 +00:00
|
|
|
$expect = str_replace('{CONTENTTYPE}', 'text/plain; charset=UTF-8', $message);
|
2009-04-24 18:20:51 +00:00
|
|
|
$this->assertTrue($this->Controller->EmailTest->send('This is the body of the message'));
|
2012-02-06 16:16:08 +00:00
|
|
|
$this->assertTextEquals(DebugCompTransport::$lastEmail, $expect);
|
2008-11-11 19:52:41 +00:00
|
|
|
|
2009-04-24 18:20:51 +00:00
|
|
|
$this->Controller->EmailTest->sendAs = 'html';
|
2008-11-11 19:52:41 +00:00
|
|
|
$expect = str_replace('{CONTENTTYPE}', 'text/html; charset=UTF-8', $message);
|
2009-04-24 18:20:51 +00:00
|
|
|
$this->assertTrue($this->Controller->EmailTest->send('This is the body of the message'));
|
2012-02-06 16:16:08 +00:00
|
|
|
$this->assertTextEquals(DebugCompTransport::$lastEmail, $expect);
|
2008-07-24 13:54:39 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-07-24 13:54:39 +00:00
|
|
|
/**
|
|
|
|
* testTemplates method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testTemplates() {
|
2010-12-27 20:12:27 +00:00
|
|
|
ClassRegistry::flush();
|
|
|
|
|
2011-04-17 17:54:38 +00:00
|
|
|
$this->Controller->EmailTest->to = 'postmaster@example.com';
|
2009-04-24 18:20:51 +00:00
|
|
|
$this->Controller->EmailTest->from = 'noreply@example.com';
|
|
|
|
$this->Controller->EmailTest->subject = 'Cake SMTP test';
|
|
|
|
$this->Controller->EmailTest->replyTo = 'noreply@example.com';
|
2008-08-05 17:02:22 +00:00
|
|
|
|
2011-04-17 17:54:38 +00:00
|
|
|
$this->Controller->EmailTest->delivery = 'DebugComp';
|
2010-01-24 22:29:53 +00:00
|
|
|
$this->Controller->EmailTest->messageId = false;
|
2008-07-24 13:54:39 +00:00
|
|
|
|
2011-11-22 16:21:00 +00:00
|
|
|
$date = self::$sentDate;
|
2008-11-11 19:52:41 +00:00
|
|
|
$header = <<<HEADBLOC
|
2011-04-17 17:54:38 +00:00
|
|
|
To: postmaster@example.com
|
2008-07-24 13:54:39 +00:00
|
|
|
From: noreply@example.com
|
|
|
|
Subject: Cake SMTP test
|
|
|
|
Header:
|
|
|
|
|
|
|
|
From: noreply@example.com
|
|
|
|
Reply-To: noreply@example.com
|
|
|
|
X-Mailer: CakePHP Email Component
|
2011-04-17 17:54:38 +00:00
|
|
|
Date: $date
|
2011-04-21 04:09:33 +00:00
|
|
|
MIME-Version: 1.0
|
2008-07-24 13:54:39 +00:00
|
|
|
Content-Type: {CONTENTTYPE}
|
2011-10-22 13:28:47 +00:00
|
|
|
Content-Transfer-Encoding: 8bitMessage:
|
2008-07-24 13:54:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
HEADBLOC;
|
|
|
|
|
2009-04-24 18:20:51 +00:00
|
|
|
$this->Controller->EmailTest->layout = 'default';
|
|
|
|
$this->Controller->EmailTest->template = 'default';
|
2011-04-17 21:30:21 +00:00
|
|
|
$this->Controller->set('title_for_layout', 'Email Test');
|
2008-08-05 17:02:22 +00:00
|
|
|
|
2008-11-11 19:52:41 +00:00
|
|
|
$text = <<<TEXTBLOC
|
2008-07-24 13:54:39 +00:00
|
|
|
|
|
|
|
This is the body of the message
|
|
|
|
|
|
|
|
This email was sent using the CakePHP Framework, http://cakephp.org.
|
|
|
|
TEXTBLOC;
|
|
|
|
|
2008-11-11 19:52:41 +00:00
|
|
|
$html = <<<HTMLBLOC
|
2008-07-24 13:54:39 +00:00
|
|
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
|
|
|
|
|
|
|
|
<html>
|
|
|
|
<head>
|
2009-11-03 22:39:59 +00:00
|
|
|
<title>Email Test</title>
|
2008-07-24 13:54:39 +00:00
|
|
|
</head>
|
|
|
|
|
|
|
|
<body>
|
|
|
|
<p> This is the body of the message</p><p> </p>
|
2008-08-05 17:02:22 +00:00
|
|
|
<p>This email was sent using the <a href="http://cakephp.org">CakePHP Framework</a></p>
|
2008-07-24 13:54:39 +00:00
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
HTMLBLOC;
|
|
|
|
|
2009-04-24 18:20:51 +00:00
|
|
|
$this->Controller->EmailTest->sendAs = 'text';
|
2008-11-11 19:52:41 +00:00
|
|
|
$expect = '<pre>' . str_replace('{CONTENTTYPE}', 'text/plain; charset=UTF-8', $header) . $text . "\n" . '</pre>';
|
2009-04-24 18:20:51 +00:00
|
|
|
$this->assertTrue($this->Controller->EmailTest->send('This is the body of the message'));
|
2012-02-06 16:16:08 +00:00
|
|
|
$this->assertTextEquals(DebugCompTransport::$lastEmail, $expect);
|
2008-11-11 19:52:41 +00:00
|
|
|
|
2009-04-24 18:20:51 +00:00
|
|
|
$this->Controller->EmailTest->sendAs = 'html';
|
2008-11-11 19:52:41 +00:00
|
|
|
$expect = '<pre>' . str_replace('{CONTENTTYPE}', 'text/html; charset=UTF-8', $header) . $html . "\n" . '</pre>';
|
2009-04-24 18:20:51 +00:00
|
|
|
$this->assertTrue($this->Controller->EmailTest->send('This is the body of the message'));
|
2012-02-06 16:16:08 +00:00
|
|
|
$this->assertTextEquals(DebugCompTransport::$lastEmail, $expect);
|
2008-11-11 19:52:41 +00:00
|
|
|
|
2009-04-24 18:20:51 +00:00
|
|
|
$this->Controller->EmailTest->sendAs = 'both';
|
2011-12-28 04:38:21 +00:00
|
|
|
$expect = str_replace('{CONTENTTYPE}', 'multipart/mixed; boundary="{boundary}"', $header);
|
|
|
|
$expect .= "--{boundary}\n" .
|
|
|
|
'Content-Type: multipart/alternative; boundary="alt-{boundary}"' . "\n\n" .
|
|
|
|
'--alt-{boundary}' . "\n" .
|
|
|
|
'Content-Type: text/plain; charset=UTF-8' . "\n" .
|
|
|
|
'Content-Transfer-Encoding: 8bit' . "\n\n" .
|
|
|
|
$text .
|
|
|
|
"\n\n" .
|
|
|
|
'--alt-{boundary}' . "\n" .
|
|
|
|
'Content-Type: text/html; charset=UTF-8' . "\n" .
|
2012-03-12 02:20:25 +00:00
|
|
|
'Content-Transfer-Encoding: 8bit' . "\n\n" .
|
2011-12-28 04:38:21 +00:00
|
|
|
$html .
|
2012-03-12 02:20:25 +00:00
|
|
|
"\n\n" .
|
|
|
|
'--alt-{boundary}--' . "\n\n\n" .
|
2011-12-28 04:38:21 +00:00
|
|
|
'--{boundary}--' . "\n";
|
|
|
|
|
|
|
|
$expect = '<pre>' . $expect . '</pre>';
|
2009-07-22 16:04:53 +00:00
|
|
|
|
2009-04-24 18:20:51 +00:00
|
|
|
$this->assertTrue($this->Controller->EmailTest->send('This is the body of the message'));
|
2012-02-06 16:16:08 +00:00
|
|
|
$this->assertTextEquals(
|
|
|
|
$expect,
|
2011-12-28 04:38:21 +00:00
|
|
|
preg_replace('/[a-z0-9]{32}/i', '{boundary}', DebugCompTransport::$lastEmail)
|
|
|
|
);
|
2008-11-11 19:52:41 +00:00
|
|
|
|
|
|
|
$html = <<<HTMLBLOC
|
2008-07-24 13:54:39 +00:00
|
|
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
|
|
|
|
|
|
|
|
<html>
|
|
|
|
<head>
|
2009-11-03 22:39:59 +00:00
|
|
|
<title>Email Test</title>
|
2008-07-24 13:54:39 +00:00
|
|
|
</head>
|
|
|
|
|
|
|
|
<body>
|
|
|
|
<p> This is the body of the message</p><p> </p>
|
|
|
|
<p>This email was sent using the CakePHP Framework</p>
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
|
|
|
|
HTMLBLOC;
|
|
|
|
|
2009-04-24 18:20:51 +00:00
|
|
|
$this->Controller->EmailTest->sendAs = 'html';
|
2009-08-03 01:09:33 +00:00
|
|
|
$expect = '<pre>' . str_replace('{CONTENTTYPE}', 'text/html; charset=UTF-8', $header) . $html . '</pre>';
|
2009-04-24 18:20:51 +00:00
|
|
|
$this->assertTrue($this->Controller->EmailTest->send('This is the body of the message', 'default', 'thin'));
|
2012-02-06 16:16:08 +00:00
|
|
|
$this->assertTextEquals(DebugCompTransport::$lastEmail, $expect);
|
2010-12-10 03:34:20 +00:00
|
|
|
}
|
2008-08-05 17:02:22 +00:00
|
|
|
|
2010-12-10 03:34:20 +00:00
|
|
|
/**
|
|
|
|
* test that elements used in email templates get helpers.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testTemplateNestedElements() {
|
2011-04-17 17:54:38 +00:00
|
|
|
$this->Controller->EmailTest->to = 'postmaster@example.com';
|
2010-12-10 03:34:20 +00:00
|
|
|
$this->Controller->EmailTest->from = 'noreply@example.com';
|
|
|
|
$this->Controller->EmailTest->subject = 'Cake SMTP test';
|
|
|
|
$this->Controller->EmailTest->replyTo = 'noreply@example.com';
|
2008-08-05 17:02:22 +00:00
|
|
|
|
2011-04-17 17:54:38 +00:00
|
|
|
$this->Controller->EmailTest->delivery = 'DebugComp';
|
2010-12-10 03:34:20 +00:00
|
|
|
$this->Controller->EmailTest->messageId = false;
|
|
|
|
$this->Controller->EmailTest->layout = 'default';
|
|
|
|
$this->Controller->EmailTest->template = 'nested_element';
|
|
|
|
$this->Controller->EmailTest->sendAs = 'html';
|
|
|
|
$this->Controller->helpers = array('Html');
|
2008-08-05 17:02:22 +00:00
|
|
|
|
2010-12-10 03:34:20 +00:00
|
|
|
$this->Controller->EmailTest->send();
|
2011-04-17 17:54:38 +00:00
|
|
|
$result = DebugCompTransport::$lastEmail;
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertRegExp('/Test/', $result);
|
|
|
|
$this->assertRegExp('/http\:\/\/example\.com/', $result);
|
2011-04-17 01:51:51 +00:00
|
|
|
}
|
|
|
|
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
|
|
|
* testSendDebug method
|
2008-06-11 08:54:27 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testSendDebug() {
|
2011-04-17 17:54:38 +00:00
|
|
|
$this->Controller->EmailTest->to = 'postmaster@example.com';
|
2009-04-24 18:20:51 +00:00
|
|
|
$this->Controller->EmailTest->from = 'noreply@example.com';
|
2011-02-23 00:23:15 +00:00
|
|
|
$this->Controller->EmailTest->cc = 'cc@example.com';
|
|
|
|
$this->Controller->EmailTest->bcc = 'bcc@example.com';
|
2009-08-09 22:53:09 +00:00
|
|
|
$this->Controller->EmailTest->subject = 'Cake Debug Test';
|
2009-04-24 18:20:51 +00:00
|
|
|
$this->Controller->EmailTest->replyTo = 'noreply@example.com';
|
|
|
|
$this->Controller->EmailTest->template = null;
|
|
|
|
|
2011-04-17 17:54:38 +00:00
|
|
|
$this->Controller->EmailTest->delivery = 'DebugComp';
|
2009-04-24 18:20:51 +00:00
|
|
|
$this->assertTrue($this->Controller->EmailTest->send('This is the body of the message'));
|
2011-04-17 17:54:38 +00:00
|
|
|
$result = DebugCompTransport::$lastEmail;
|
2009-08-09 22:53:09 +00:00
|
|
|
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertRegExp('/To: postmaster@example.com\n/', $result);
|
|
|
|
$this->assertRegExp('/Subject: Cake Debug Test\n/', $result);
|
|
|
|
$this->assertRegExp('/Reply-To: noreply@example.com\n/', $result);
|
|
|
|
$this->assertRegExp('/From: noreply@example.com\n/', $result);
|
|
|
|
$this->assertRegExp('/Cc: cc@example.com\n/', $result);
|
|
|
|
$this->assertRegExp('/Bcc: bcc@example.com\n/', $result);
|
2011-11-22 16:21:00 +00:00
|
|
|
$this->assertRegExp('/Date: ' . preg_quote(self::$sentDate) . '\n/', $result);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertRegExp('/X-Mailer: CakePHP Email Component\n/', $result);
|
|
|
|
$this->assertRegExp('/Content-Type: text\/plain; charset=UTF-8\n/', $result);
|
|
|
|
$this->assertRegExp('/Content-Transfer-Encoding: 8bitMessage:\n/', $result);
|
|
|
|
$this->assertRegExp('/This is the body of the message/', $result);
|
2010-04-17 16:27:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* test send with delivery = debug and not using sessions.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testSendDebugWithNoSessions() {
|
2010-06-10 13:42:13 +00:00
|
|
|
$session = $this->Controller->Session;
|
2010-04-17 16:27:50 +00:00
|
|
|
unset($this->Controller->Session);
|
2011-04-17 17:54:38 +00:00
|
|
|
$this->Controller->EmailTest->to = 'postmaster@example.com';
|
2010-04-17 16:27:50 +00:00
|
|
|
$this->Controller->EmailTest->from = 'noreply@example.com';
|
|
|
|
$this->Controller->EmailTest->subject = 'Cake Debug Test';
|
|
|
|
$this->Controller->EmailTest->replyTo = 'noreply@example.com';
|
|
|
|
$this->Controller->EmailTest->template = null;
|
2011-04-17 01:51:51 +00:00
|
|
|
|
2011-04-17 17:54:38 +00:00
|
|
|
$this->Controller->EmailTest->delivery = 'DebugComp';
|
|
|
|
$this->Controller->EmailTest->send('This is the body of the message');
|
|
|
|
$result = DebugCompTransport::$lastEmail;
|
2010-04-17 16:27:50 +00:00
|
|
|
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertRegExp('/To: postmaster@example.com\n/', $result);
|
|
|
|
$this->assertRegExp('/Subject: Cake Debug Test\n/', $result);
|
|
|
|
$this->assertRegExp('/Reply-To: noreply@example.com\n/', $result);
|
|
|
|
$this->assertRegExp('/From: noreply@example.com\n/', $result);
|
2011-11-22 16:21:00 +00:00
|
|
|
$this->assertRegExp('/Date: ' . preg_quote(self::$sentDate) . '\n/', $result);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertRegExp('/X-Mailer: CakePHP Email Component\n/', $result);
|
|
|
|
$this->assertRegExp('/Content-Type: text\/plain; charset=UTF-8\n/', $result);
|
|
|
|
$this->assertRegExp('/Content-Transfer-Encoding: 8bitMessage:\n/', $result);
|
|
|
|
$this->assertRegExp('/This is the body of the message/', $result);
|
2010-04-17 16:27:50 +00:00
|
|
|
$this->Controller->Session = $session;
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-12-16 20:47:12 +00:00
|
|
|
/**
|
|
|
|
* testMessageRetrievalWithoutTemplate method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testMessageRetrievalWithoutTemplate() {
|
2009-12-16 20:47:12 +00:00
|
|
|
App::build(array(
|
2012-03-12 02:20:25 +00:00
|
|
|
'View' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS)
|
2009-12-16 20:47:12 +00:00
|
|
|
));
|
|
|
|
|
2011-04-17 17:54:38 +00:00
|
|
|
$this->Controller->EmailTest->to = 'postmaster@example.com';
|
2009-12-16 20:47:12 +00:00
|
|
|
$this->Controller->EmailTest->from = 'noreply@example.com';
|
|
|
|
$this->Controller->EmailTest->subject = 'Cake Debug Test';
|
|
|
|
$this->Controller->EmailTest->replyTo = 'noreply@example.com';
|
|
|
|
$this->Controller->EmailTest->layout = 'default';
|
|
|
|
$this->Controller->EmailTest->template = null;
|
|
|
|
|
2011-04-17 17:54:38 +00:00
|
|
|
$this->Controller->EmailTest->delivery = 'DebugComp';
|
2009-12-16 20:47:12 +00:00
|
|
|
|
2011-12-28 04:38:21 +00:00
|
|
|
$text = $html = "This is the body of the message\n";
|
2009-12-16 20:47:12 +00:00
|
|
|
|
|
|
|
$this->Controller->EmailTest->sendAs = 'both';
|
|
|
|
$this->assertTrue($this->Controller->EmailTest->send('This is the body of the message'));
|
2012-02-06 16:16:08 +00:00
|
|
|
$this->assertTextEquals($this->Controller->EmailTest->textMessage, $text);
|
|
|
|
$this->assertTextEquals($this->Controller->EmailTest->htmlMessage, $html);
|
2009-12-16 20:47:12 +00:00
|
|
|
|
|
|
|
$this->Controller->EmailTest->sendAs = 'text';
|
|
|
|
$this->assertTrue($this->Controller->EmailTest->send('This is the body of the message'));
|
2012-02-06 16:16:08 +00:00
|
|
|
$this->assertTextEquals($this->Controller->EmailTest->textMessage, $text);
|
2009-12-16 20:47:12 +00:00
|
|
|
$this->assertNull($this->Controller->EmailTest->htmlMessage);
|
|
|
|
|
|
|
|
$this->Controller->EmailTest->sendAs = 'html';
|
|
|
|
$this->assertTrue($this->Controller->EmailTest->send('This is the body of the message'));
|
|
|
|
$this->assertNull($this->Controller->EmailTest->textMessage);
|
2012-02-06 16:16:08 +00:00
|
|
|
$this->assertTextEquals($this->Controller->EmailTest->htmlMessage, $html);
|
2009-12-16 20:47:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* testMessageRetrievalWithTemplate method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testMessageRetrievalWithTemplate() {
|
2009-12-16 20:47:12 +00:00
|
|
|
App::build(array(
|
2012-03-12 02:20:25 +00:00
|
|
|
'View' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS)
|
2009-12-16 20:47:12 +00:00
|
|
|
));
|
|
|
|
|
|
|
|
$this->Controller->set('value', 22091985);
|
2010-01-21 22:07:42 +00:00
|
|
|
$this->Controller->set('title_for_layout', 'EmailTest');
|
2009-12-16 20:47:12 +00:00
|
|
|
|
2011-04-17 17:54:38 +00:00
|
|
|
$this->Controller->EmailTest->to = 'postmaster@example.com';
|
2009-12-16 20:47:12 +00:00
|
|
|
$this->Controller->EmailTest->from = 'noreply@example.com';
|
|
|
|
$this->Controller->EmailTest->subject = 'Cake Debug Test';
|
|
|
|
$this->Controller->EmailTest->replyTo = 'noreply@example.com';
|
|
|
|
$this->Controller->EmailTest->layout = 'default';
|
|
|
|
$this->Controller->EmailTest->template = 'custom';
|
|
|
|
|
2011-04-17 17:54:38 +00:00
|
|
|
$this->Controller->EmailTest->delivery = 'DebugComp';
|
2009-12-16 20:47:12 +00:00
|
|
|
|
|
|
|
$text = <<<TEXTBLOC
|
|
|
|
|
|
|
|
Here is your value: 22091985
|
|
|
|
This email was sent using the CakePHP Framework, http://cakephp.org.
|
|
|
|
TEXTBLOC;
|
|
|
|
|
|
|
|
$html = <<<HTMLBLOC
|
|
|
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
|
|
|
|
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<title>EmailTest</title>
|
|
|
|
</head>
|
|
|
|
|
|
|
|
<body>
|
|
|
|
<p>Here is your value: <b>22091985</b></p>
|
2011-06-19 22:43:11 +00:00
|
|
|
|
2009-12-16 20:47:12 +00:00
|
|
|
<p>This email was sent using the <a href="http://cakephp.org">CakePHP Framework</a></p>
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
HTMLBLOC;
|
|
|
|
|
|
|
|
$this->Controller->EmailTest->sendAs = 'both';
|
|
|
|
$this->assertTrue($this->Controller->EmailTest->send());
|
2012-02-06 16:16:08 +00:00
|
|
|
$this->assertTextEquals($this->Controller->EmailTest->textMessage, $text);
|
|
|
|
$this->assertTextEquals($this->Controller->EmailTest->htmlMessage, $html);
|
2009-12-16 20:47:12 +00:00
|
|
|
|
|
|
|
$this->Controller->EmailTest->sendAs = 'text';
|
|
|
|
$this->assertTrue($this->Controller->EmailTest->send());
|
2012-02-06 16:16:08 +00:00
|
|
|
$this->assertTextEquals($this->Controller->EmailTest->textMessage, $text);
|
2009-12-16 20:47:12 +00:00
|
|
|
$this->assertNull($this->Controller->EmailTest->htmlMessage);
|
|
|
|
|
|
|
|
$this->Controller->EmailTest->sendAs = 'html';
|
|
|
|
$this->assertTrue($this->Controller->EmailTest->send());
|
|
|
|
$this->assertNull($this->Controller->EmailTest->textMessage);
|
2012-02-06 16:16:08 +00:00
|
|
|
$this->assertTextEquals($this->Controller->EmailTest->htmlMessage, $html);
|
2009-12-16 20:47:12 +00:00
|
|
|
}
|
|
|
|
|
2011-06-19 22:43:11 +00:00
|
|
|
/**
|
|
|
|
* testMessageRetrievalWithHelper method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testMessageRetrievalWithHelper() {
|
|
|
|
App::build(array(
|
2012-03-12 02:20:25 +00:00
|
|
|
'View' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS)
|
2011-06-19 22:43:11 +00:00
|
|
|
));
|
|
|
|
|
|
|
|
$timestamp = time();
|
|
|
|
$this->Controller->set('time', $timestamp);
|
|
|
|
$this->Controller->set('title_for_layout', 'EmailTest');
|
|
|
|
$this->Controller->helpers = array('Time');
|
|
|
|
|
|
|
|
$this->Controller->EmailTest->to = 'postmaster@example.com';
|
|
|
|
$this->Controller->EmailTest->from = 'noreply@example.com';
|
|
|
|
$this->Controller->EmailTest->subject = 'Cake Debug Test';
|
|
|
|
$this->Controller->EmailTest->replyTo = 'noreply@example.com';
|
|
|
|
$this->Controller->EmailTest->layout = 'default';
|
|
|
|
$this->Controller->EmailTest->template = 'custom_helper';
|
|
|
|
$this->Controller->EmailTest->sendAs = 'text';
|
|
|
|
$this->Controller->EmailTest->delivery = 'DebugComp';
|
|
|
|
|
|
|
|
$this->assertTrue($this->Controller->EmailTest->send());
|
|
|
|
$this->assertTrue((bool)strpos($this->Controller->EmailTest->textMessage, 'Right now: ' . date('Y-m-d\TH:i:s\Z', $timestamp)));
|
|
|
|
}
|
|
|
|
|
2009-08-09 23:09:02 +00:00
|
|
|
/**
|
|
|
|
* testContentArray method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testSendContentArray() {
|
2011-04-17 17:54:38 +00:00
|
|
|
$this->Controller->EmailTest->to = 'postmaster@example.com';
|
2009-08-09 23:09:02 +00:00
|
|
|
$this->Controller->EmailTest->from = 'noreply@example.com';
|
|
|
|
$this->Controller->EmailTest->subject = 'Cake Debug Test';
|
|
|
|
$this->Controller->EmailTest->replyTo = 'noreply@example.com';
|
|
|
|
$this->Controller->EmailTest->template = null;
|
2011-04-17 17:54:38 +00:00
|
|
|
$this->Controller->EmailTest->delivery = 'DebugComp';
|
2009-08-09 23:09:02 +00:00
|
|
|
|
|
|
|
$content = array('First line', 'Second line', 'Third line');
|
|
|
|
$this->assertTrue($this->Controller->EmailTest->send($content));
|
2011-04-17 17:54:38 +00:00
|
|
|
$result = DebugCompTransport::$lastEmail;
|
2009-08-09 23:09:02 +00:00
|
|
|
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertRegExp('/To: postmaster@example.com\n/', $result);
|
|
|
|
$this->assertRegExp('/Subject: Cake Debug Test\n/', $result);
|
|
|
|
$this->assertRegExp('/Reply-To: noreply@example.com\n/', $result);
|
|
|
|
$this->assertRegExp('/From: noreply@example.com\n/', $result);
|
|
|
|
$this->assertRegExp('/X-Mailer: CakePHP Email Component\n/', $result);
|
|
|
|
$this->assertRegExp('/Content-Type: text\/plain; charset=UTF-8\n/', $result);
|
|
|
|
$this->assertRegExp('/Content-Transfer-Encoding: 8bitMessage:\n/', $result);
|
|
|
|
$this->assertRegExp('/First line\n/', $result);
|
|
|
|
$this->assertRegExp('/Second line\n/', $result);
|
|
|
|
$this->assertRegExp('/Third line\n/', $result);
|
2010-11-23 03:08:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* test setting a custom date.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testDateProperty() {
|
2011-04-17 17:54:38 +00:00
|
|
|
$this->Controller->EmailTest->to = 'postmaster@example.com';
|
2010-11-23 03:08:46 +00:00
|
|
|
$this->Controller->EmailTest->from = 'noreply@example.com';
|
|
|
|
$this->Controller->EmailTest->subject = 'Cake Debug Test';
|
2011-11-22 16:21:00 +00:00
|
|
|
$this->Controller->EmailTest->date = self::$sentDate = 'Today!';
|
2010-11-23 03:08:46 +00:00
|
|
|
$this->Controller->EmailTest->template = null;
|
2011-04-17 17:54:38 +00:00
|
|
|
$this->Controller->EmailTest->delivery = 'DebugComp';
|
2009-08-09 23:09:02 +00:00
|
|
|
|
2010-11-23 03:08:46 +00:00
|
|
|
$this->assertTrue($this->Controller->EmailTest->send('test message'));
|
2011-04-17 17:54:38 +00:00
|
|
|
$result = DebugCompTransport::$lastEmail;
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertRegExp('/Date: Today!\n/', $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
|
|
|
* testContentStripping method
|
2008-06-11 08:54:27 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testContentStripping() {
|
2011-10-22 13:28:47 +00:00
|
|
|
$content = "Previous content\n--alt-\nContent-TypeContent-Type:: text/html; charsetcharset==utf-8\nContent-Transfer-Encoding: 8bit";
|
2008-05-30 11:40:08 +00:00
|
|
|
$content .= "\n\n<p>My own html content</p>";
|
|
|
|
|
2009-07-02 02:58:43 +00:00
|
|
|
$result = $this->Controller->EmailTest->strip($content, true);
|
2011-10-22 13:28:47 +00:00
|
|
|
$expected = "Previous content\n--alt-\n text/html; utf-8\n 8bit\n\n<p>My own html content</p>";
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2009-07-02 02:58:43 +00:00
|
|
|
|
|
|
|
$content = '<p>Some HTML content with an <a href="mailto:test@example.com">email link</a>';
|
|
|
|
$result = $this->Controller->EmailTest->strip($content, true);
|
|
|
|
$expected = $content;
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2009-07-02 02:58:43 +00:00
|
|
|
|
|
|
|
$content = '<p>Some HTML content with an ';
|
|
|
|
$content .= '<a href="mailto:test@example.com,test2@example.com">email link</a>';
|
|
|
|
$result = $this->Controller->EmailTest->strip($content, true);
|
|
|
|
$expected = $content;
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2010-07-19 00:48:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* test that the _encode() will set mb_internal_encoding.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2012-03-12 02:20:25 +00:00
|
|
|
public function testEncodeSettingInternalCharset() {
|
2011-05-31 00:49:46 +00:00
|
|
|
$this->skipIf(!function_exists('mb_internal_encoding'), 'Missing mb_* functions, cannot run test.');
|
|
|
|
|
2010-09-20 03:30:02 +00:00
|
|
|
$restore = mb_internal_encoding();
|
2010-07-19 00:48:15 +00:00
|
|
|
mb_internal_encoding('ISO-8859-1');
|
|
|
|
|
|
|
|
$this->Controller->charset = 'UTF-8';
|
2011-04-17 17:54:38 +00:00
|
|
|
$this->Controller->EmailTest->to = 'postmaster@example.com';
|
2010-07-19 00:48:15 +00:00
|
|
|
$this->Controller->EmailTest->from = 'noreply@example.com';
|
|
|
|
$this->Controller->EmailTest->subject = 'هذه رسالة بعنوان طويل مرسل للمستلم';
|
|
|
|
$this->Controller->EmailTest->replyTo = 'noreply@example.com';
|
|
|
|
$this->Controller->EmailTest->template = null;
|
2011-04-17 17:54:38 +00:00
|
|
|
$this->Controller->EmailTest->delivery = 'DebugComp';
|
2010-07-19 00:48:15 +00:00
|
|
|
|
|
|
|
$this->Controller->EmailTest->sendAs = 'text';
|
|
|
|
$this->assertTrue($this->Controller->EmailTest->send('This is the body of the message'));
|
|
|
|
|
|
|
|
$subject = '=?UTF-8?B?2YfYsNmHINix2LPYp9mE2Kkg2KjYudmG2YjYp9mGINi32YjZitmEINmF2LE=?=' . "\r\n" . ' =?UTF-8?B?2LPZhCDZhNmE2YXYs9iq2YTZhQ==?=';
|
|
|
|
|
2011-04-17 17:54:38 +00:00
|
|
|
preg_match('/Subject: (.*)Header:/s', DebugCompTransport::$lastEmail, $matches);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals(trim($matches[1]), $subject);
|
2009-07-02 02:58:43 +00:00
|
|
|
|
2010-07-19 00:48:15 +00:00
|
|
|
$result = mb_internal_encoding();
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('ISO-8859-1', $result);
|
2010-09-20 03:30:02 +00:00
|
|
|
|
|
|
|
mb_internal_encoding($restore);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-03-18 17:55:58 +00:00
|
|
|
/**
|
|
|
|
* testMultibyte method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testMultibyte() {
|
2010-07-19 00:48:15 +00:00
|
|
|
$this->Controller->charset = 'UTF-8';
|
2011-04-17 17:54:38 +00:00
|
|
|
$this->Controller->EmailTest->to = 'postmaster@example.com';
|
2009-04-24 18:20:51 +00:00
|
|
|
$this->Controller->EmailTest->from = 'noreply@example.com';
|
|
|
|
$this->Controller->EmailTest->subject = 'هذه رسالة بعنوان طويل مرسل للمستلم';
|
|
|
|
$this->Controller->EmailTest->replyTo = 'noreply@example.com';
|
|
|
|
$this->Controller->EmailTest->template = null;
|
2011-04-17 17:54:38 +00:00
|
|
|
$this->Controller->EmailTest->delivery = 'DebugComp';
|
2008-11-11 19:52:41 +00:00
|
|
|
|
|
|
|
$subject = '=?UTF-8?B?2YfYsNmHINix2LPYp9mE2Kkg2KjYudmG2YjYp9mGINi32YjZitmEINmF2LE=?=' . "\r\n" . ' =?UTF-8?B?2LPZhCDZhNmE2YXYs9iq2YTZhQ==?=';
|
|
|
|
|
2009-04-24 18:20:51 +00:00
|
|
|
$this->Controller->EmailTest->sendAs = 'text';
|
|
|
|
$this->assertTrue($this->Controller->EmailTest->send('This is the body of the message'));
|
2011-04-17 17:54:38 +00:00
|
|
|
preg_match('/Subject: (.*)Header:/s', DebugCompTransport::$lastEmail, $matches);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals(trim($matches[1]), $subject);
|
2008-11-11 19:52:41 +00:00
|
|
|
|
2009-04-24 18:20:51 +00:00
|
|
|
$this->Controller->EmailTest->sendAs = 'html';
|
|
|
|
$this->assertTrue($this->Controller->EmailTest->send('This is the body of the message'));
|
2011-04-17 17:54:38 +00:00
|
|
|
preg_match('/Subject: (.*)Header:/s', DebugCompTransport::$lastEmail, $matches);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals(trim($matches[1]), $subject);
|
2008-11-11 19:52:41 +00:00
|
|
|
|
2009-04-24 18:20:51 +00:00
|
|
|
$this->Controller->EmailTest->sendAs = 'both';
|
|
|
|
$this->assertTrue($this->Controller->EmailTest->send('This is the body of the message'));
|
2011-04-17 17:54:38 +00:00
|
|
|
preg_match('/Subject: (.*)Header:/s', DebugCompTransport::$lastEmail, $matches);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals(trim($matches[1]), $subject);
|
2008-10-01 18:36:38 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-07-21 21:54:05 +00:00
|
|
|
/**
|
|
|
|
* undocumented function
|
|
|
|
*
|
|
|
|
* @return void
|
2010-04-02 19:02:23 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testSendWithAttachments() {
|
2011-04-17 17:54:38 +00:00
|
|
|
$this->Controller->EmailTest->to = 'postmaster@example.com';
|
2010-04-02 19:02:23 +00:00
|
|
|
$this->Controller->EmailTest->from = 'noreply@example.com';
|
|
|
|
$this->Controller->EmailTest->subject = 'Attachment Test';
|
|
|
|
$this->Controller->EmailTest->replyTo = 'noreply@example.com';
|
|
|
|
$this->Controller->EmailTest->template = null;
|
2011-04-17 17:54:38 +00:00
|
|
|
$this->Controller->EmailTest->delivery = 'DebugComp';
|
2010-04-02 19:02:23 +00:00
|
|
|
$this->Controller->EmailTest->attachments = array(
|
|
|
|
__FILE__,
|
|
|
|
'some-name.php' => __FILE__
|
|
|
|
);
|
|
|
|
$body = '<p>This is the body of the message</p>';
|
|
|
|
|
|
|
|
$this->Controller->EmailTest->sendAs = 'text';
|
|
|
|
$this->assertTrue($this->Controller->EmailTest->send($body));
|
2011-04-17 17:54:38 +00:00
|
|
|
$msg = DebugCompTransport::$lastEmail;
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertRegExp('/' . preg_quote('Content-Disposition: attachment; filename="EmailComponentTest.php"') . '/', $msg);
|
|
|
|
$this->assertRegExp('/' . preg_quote('Content-Disposition: attachment; filename="some-name.php"') . '/', $msg);
|
2010-04-02 19:02:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* testSendAsIsNotIgnoredIfAttachmentsPresent method
|
|
|
|
*
|
|
|
|
* @return void
|
2009-07-21 21:54:05 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testSendAsIsNotIgnoredIfAttachmentsPresent() {
|
2011-04-17 17:54:38 +00:00
|
|
|
$this->Controller->EmailTest->to = 'postmaster@example.com';
|
2009-07-21 21:54:05 +00:00
|
|
|
$this->Controller->EmailTest->from = 'noreply@example.com';
|
|
|
|
$this->Controller->EmailTest->subject = 'Attachment Test';
|
|
|
|
$this->Controller->EmailTest->replyTo = 'noreply@example.com';
|
|
|
|
$this->Controller->EmailTest->template = null;
|
2011-04-17 17:54:38 +00:00
|
|
|
$this->Controller->EmailTest->delivery = 'DebugComp';
|
2009-07-21 21:54:05 +00:00
|
|
|
$this->Controller->EmailTest->attachments = array(__FILE__);
|
|
|
|
$body = '<p>This is the body of the message</p>';
|
|
|
|
|
|
|
|
$this->Controller->EmailTest->sendAs = 'html';
|
|
|
|
$this->assertTrue($this->Controller->EmailTest->send($body));
|
2011-04-17 17:54:38 +00:00
|
|
|
$msg = DebugCompTransport::$lastEmail;
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertNotRegExp('/text\/plain/', $msg);
|
|
|
|
$this->assertRegExp('/text\/html/', $msg);
|
2009-07-21 21:54:05 +00:00
|
|
|
|
|
|
|
$this->Controller->EmailTest->sendAs = 'text';
|
|
|
|
$this->assertTrue($this->Controller->EmailTest->send($body));
|
2011-04-17 17:54:38 +00:00
|
|
|
$msg = DebugCompTransport::$lastEmail;
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertRegExp('/text\/plain/', $msg);
|
|
|
|
$this->assertNotRegExp('/text\/html/', $msg);
|
2009-07-21 21:54:05 +00:00
|
|
|
|
|
|
|
$this->Controller->EmailTest->sendAs = 'both';
|
|
|
|
$this->assertTrue($this->Controller->EmailTest->send($body));
|
2011-04-17 17:54:38 +00:00
|
|
|
$msg = DebugCompTransport::$lastEmail;
|
2009-07-22 16:04:53 +00:00
|
|
|
|
2011-12-28 04:38:21 +00:00
|
|
|
$this->assertRegExp('/text\/plain/', $msg);
|
|
|
|
$this->assertRegExp('/text\/html/', $msg);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertRegExp('/multipart\/alternative/', $msg);
|
2009-07-21 21:54:05 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-07-22 16:04:53 +00:00
|
|
|
/**
|
2010-04-02 19:02:23 +00:00
|
|
|
* testNoDoubleNewlinesInHeaders function
|
2009-07-22 16:04:53 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testNoDoubleNewlinesInHeaders() {
|
2011-04-17 17:54:38 +00:00
|
|
|
$this->Controller->EmailTest->to = 'postmaster@example.com';
|
2009-07-22 16:04:53 +00:00
|
|
|
$this->Controller->EmailTest->from = 'noreply@example.com';
|
|
|
|
$this->Controller->EmailTest->subject = 'Attachment Test';
|
|
|
|
$this->Controller->EmailTest->replyTo = 'noreply@example.com';
|
|
|
|
$this->Controller->EmailTest->template = null;
|
2011-04-17 17:54:38 +00:00
|
|
|
$this->Controller->EmailTest->delivery = 'DebugComp';
|
2009-07-22 16:04:53 +00:00
|
|
|
$body = '<p>This is the body of the message</p>';
|
|
|
|
|
|
|
|
$this->Controller->EmailTest->sendAs = 'both';
|
|
|
|
$this->assertTrue($this->Controller->EmailTest->send($body));
|
2011-04-17 17:54:38 +00:00
|
|
|
$msg = DebugCompTransport::$lastEmail;
|
2009-07-22 16:04:53 +00:00
|
|
|
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertNotRegExp('/\n\nContent-Transfer-Encoding/', $msg);
|
|
|
|
$this->assertRegExp('/\nContent-Transfer-Encoding/', $msg);
|
2009-07-22 16:04:53 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-04-25 00:01:57 +00:00
|
|
|
/**
|
|
|
|
* testReset method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testReset() {
|
2011-04-21 04:09:33 +00:00
|
|
|
$this->Controller->EmailTest->template = 'default';
|
2009-04-25 00:01:57 +00:00
|
|
|
$this->Controller->EmailTest->to = 'test.recipient@example.com';
|
|
|
|
$this->Controller->EmailTest->from = 'test.sender@example.com';
|
|
|
|
$this->Controller->EmailTest->replyTo = 'test.replyto@example.com';
|
|
|
|
$this->Controller->EmailTest->return = 'test.return@example.com';
|
|
|
|
$this->Controller->EmailTest->cc = array('cc1@example.com', 'cc2@example.com');
|
|
|
|
$this->Controller->EmailTest->bcc = array('bcc1@example.com', 'bcc2@example.com');
|
2010-11-23 03:08:46 +00:00
|
|
|
$this->Controller->EmailTest->date = 'Today!';
|
2009-04-25 00:01:57 +00:00
|
|
|
$this->Controller->EmailTest->subject = 'Test subject';
|
|
|
|
$this->Controller->EmailTest->additionalParams = 'X-additional-header';
|
2011-04-17 01:51:51 +00:00
|
|
|
$this->Controller->EmailTest->delivery = 'smtp';
|
|
|
|
$this->Controller->EmailTest->smtpOptions['host'] = 'blah';
|
|
|
|
$this->Controller->EmailTest->smtpOptions['timeout'] = 0.2;
|
2009-07-10 00:07:51 +00:00
|
|
|
$this->Controller->EmailTest->attachments = array('attachment1', 'attachment2');
|
2009-12-16 20:47:12 +00:00
|
|
|
$this->Controller->EmailTest->textMessage = 'This is the body of the message';
|
|
|
|
$this->Controller->EmailTest->htmlMessage = 'This is the body of the message';
|
2010-01-24 22:29:53 +00:00
|
|
|
$this->Controller->EmailTest->messageId = false;
|
2011-04-17 01:51:51 +00:00
|
|
|
|
2010-12-16 03:08:24 +00:00
|
|
|
try {
|
|
|
|
$this->Controller->EmailTest->send('Should not work');
|
|
|
|
$this->fail('No exception');
|
|
|
|
} catch (SocketException $e) {
|
|
|
|
$this->assertTrue(true, 'SocketException raised');
|
|
|
|
}
|
2011-04-17 01:51:51 +00:00
|
|
|
|
2009-04-25 00:01:57 +00:00
|
|
|
$this->Controller->EmailTest->reset();
|
|
|
|
|
|
|
|
$this->assertNull($this->Controller->EmailTest->template);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertSame($this->Controller->EmailTest->to, array());
|
2009-04-25 00:01:57 +00:00
|
|
|
$this->assertNull($this->Controller->EmailTest->from);
|
|
|
|
$this->assertNull($this->Controller->EmailTest->replyTo);
|
|
|
|
$this->assertNull($this->Controller->EmailTest->return);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertSame($this->Controller->EmailTest->cc, array());
|
|
|
|
$this->assertSame($this->Controller->EmailTest->bcc, array());
|
2010-11-23 03:08:46 +00:00
|
|
|
$this->assertNull($this->Controller->EmailTest->date);
|
2009-04-25 00:01:57 +00:00
|
|
|
$this->assertNull($this->Controller->EmailTest->subject);
|
|
|
|
$this->assertNull($this->Controller->EmailTest->additionalParams);
|
2011-04-17 01:51:51 +00:00
|
|
|
$this->assertNull($this->Controller->EmailTest->smtpError);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertSame($this->Controller->EmailTest->attachments, array());
|
2009-12-16 20:47:12 +00:00
|
|
|
$this->assertNull($this->Controller->EmailTest->textMessage);
|
2010-01-24 22:29:53 +00:00
|
|
|
$this->assertTrue($this->Controller->EmailTest->messageId);
|
2012-02-02 01:20:14 +00:00
|
|
|
$this->assertEquals('mail', $this->Controller->EmailTest->delivery);
|
2009-04-25 00:01:57 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testPluginCustomViewClass() {
|
2009-08-10 01:29:29 +00:00
|
|
|
App::build(array(
|
2012-02-18 12:31:29 +00:00
|
|
|
'Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS),
|
2012-03-12 02:20:25 +00:00
|
|
|
'View' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS)
|
2009-08-10 01:29:29 +00:00
|
|
|
));
|
|
|
|
|
|
|
|
$this->Controller->view = 'TestPlugin.Email';
|
|
|
|
|
2011-04-17 17:54:38 +00:00
|
|
|
$this->Controller->EmailTest->to = 'postmaster@example.com';
|
2009-08-10 01:29:29 +00:00
|
|
|
$this->Controller->EmailTest->from = 'noreply@example.com';
|
|
|
|
$this->Controller->EmailTest->subject = 'CustomViewClass test';
|
2011-04-17 17:54:38 +00:00
|
|
|
$this->Controller->EmailTest->delivery = 'DebugComp';
|
2009-08-10 01:29:29 +00:00
|
|
|
$body = 'Body of message';
|
|
|
|
|
|
|
|
$this->assertTrue($this->Controller->EmailTest->send($body));
|
2011-04-17 17:54:38 +00:00
|
|
|
$result = DebugCompTransport::$lastEmail;
|
2011-04-17 01:51:51 +00:00
|
|
|
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertRegExp('/Body of message/', $result);
|
2009-04-25 00:01:57 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-03-18 17:55:58 +00:00
|
|
|
/**
|
2009-08-09 22:39:05 +00:00
|
|
|
* testStartup method
|
2009-03-18 17:55:58 +00:00
|
|
|
*
|
2009-08-09 22:39:05 +00:00
|
|
|
* @return void
|
2009-03-18 17:55:58 +00:00
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testStartup() {
|
2009-08-09 22:39:05 +00:00
|
|
|
$this->assertNull($this->Controller->EmailTest->startup($this->Controller));
|
2008-07-24 13:54:39 +00:00
|
|
|
}
|
2009-08-09 22:39:05 +00:00
|
|
|
|
2010-01-24 22:29:53 +00:00
|
|
|
/**
|
|
|
|
* testMessageId method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testMessageId() {
|
2011-04-17 17:54:38 +00:00
|
|
|
$this->Controller->EmailTest->to = 'postmaster@example.com';
|
2010-01-24 22:29:53 +00:00
|
|
|
$this->Controller->EmailTest->from = 'noreply@example.com';
|
|
|
|
$this->Controller->EmailTest->subject = 'Cake Debug Test';
|
|
|
|
$this->Controller->EmailTest->replyTo = 'noreply@example.com';
|
|
|
|
$this->Controller->EmailTest->template = null;
|
|
|
|
|
2011-04-17 17:54:38 +00:00
|
|
|
$this->Controller->EmailTest->delivery = 'DebugComp';
|
2010-01-24 22:29:53 +00:00
|
|
|
$this->assertTrue($this->Controller->EmailTest->send('This is the body of the message'));
|
2011-04-17 17:54:38 +00:00
|
|
|
$result = DebugCompTransport::$lastEmail;
|
2011-04-17 01:51:51 +00:00
|
|
|
|
2012-04-20 02:17:19 +00:00
|
|
|
$host = env('HTTP_HOST') ? env('HTTP_HOST') : php_uname('n');
|
|
|
|
$this->assertRegExp('/Message-ID: \<[a-f0-9]{8}[a-f0-9]{4}[a-f0-9]{4}[a-f0-9]{4}[a-f0-9]{12}@' . $host . '\>\n/', $result);
|
2010-01-24 22:29:53 +00:00
|
|
|
|
2011-04-17 17:54:38 +00:00
|
|
|
$this->Controller->EmailTest->messageId = '<22091985.998877@example.com>';
|
2010-01-24 22:29:53 +00:00
|
|
|
|
|
|
|
$this->assertTrue($this->Controller->EmailTest->send('This is the body of the message'));
|
2011-04-17 17:54:38 +00:00
|
|
|
$result = DebugCompTransport::$lastEmail;
|
2011-04-17 01:51:51 +00:00
|
|
|
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertRegExp('/Message-ID: <22091985.998877@example.com>\n/', $result);
|
2010-01-24 22:29:53 +00:00
|
|
|
|
|
|
|
$this->Controller->EmailTest->messageId = false;
|
|
|
|
|
|
|
|
$this->assertTrue($this->Controller->EmailTest->send('This is the body of the message'));
|
2011-04-17 17:54:38 +00:00
|
|
|
$result = DebugCompTransport::$lastEmail;
|
2011-04-17 01:51:51 +00:00
|
|
|
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertNotRegExp('/Message-ID:/', $result);
|
2008-07-24 13:54:39 +00:00
|
|
|
}
|
2010-01-24 22:29:53 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|