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
|
|
|
*
|
|
|
|
* PHP versions 4 and 5
|
|
|
|
*
|
2010-05-19 01:15:13 +00:00
|
|
|
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
|
2010-01-26 19:18:20 +00:00
|
|
|
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
|
|
|
* Licensed under The Open Group Test Suite License
|
|
|
|
* Redistributions of files must retain the above copyright notice.
|
|
|
|
*
|
2010-01-26 19:18:20 +00:00
|
|
|
* @copyright Copyright 2005-2010, 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
|
2008-10-30 17:30:26 +00:00
|
|
|
* @package cake
|
|
|
|
* @subpackage cake.cake.tests.cases.libs.controller.components
|
|
|
|
* @since CakePHP(tm) v 1.2.0.5347
|
|
|
|
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2008-07-21 02:40:58 +00:00
|
|
|
App::import('Component', 'Email');
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-04-24 18:20:51 +00:00
|
|
|
/**
|
|
|
|
* EmailTestComponent class
|
|
|
|
*
|
|
|
|
* @package cake
|
|
|
|
* @subpackage cake.tests.cases.libs.controller.components
|
|
|
|
*/
|
|
|
|
class EmailTestComponent extends EmailComponent {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-04-24 18:20:51 +00:00
|
|
|
/**
|
|
|
|
* smtpSend method override for testing
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
function smtpSend($data, $code = '250') {
|
2009-03-22 04:19:20 +00:00
|
|
|
return parent::_smtpSend($data, $code);
|
2009-04-24 18:20:51 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-04-24 18:20:51 +00:00
|
|
|
/**
|
|
|
|
* Convenience setter method for testing.
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function setConnectionSocket(&$socket) {
|
|
|
|
$this->__smtpConnection = $socket;
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-04-24 18:20:51 +00:00
|
|
|
/**
|
|
|
|
* Convenience getter method for testing.
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
function getConnectionSocket() {
|
|
|
|
return $this->__smtpConnection;
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-04-25 00:01:57 +00:00
|
|
|
/**
|
|
|
|
* Convenience setter for testing.
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function setHeaders($headers) {
|
|
|
|
$this->__header += $headers;
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-04-25 00:01:57 +00:00
|
|
|
/**
|
|
|
|
* Convenience getter for testing.
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
function getHeaders() {
|
2010-06-10 13:42:13 +00:00
|
|
|
if (empty($this->_header)) {
|
|
|
|
return array();
|
|
|
|
}
|
2009-04-25 00:01:57 +00:00
|
|
|
return $this->__header;
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-04-25 00:01:57 +00:00
|
|
|
/**
|
|
|
|
* Convenience setter for testing.
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function setBoundary() {
|
|
|
|
$this->__createBoundary();
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-04-25 00:01:57 +00:00
|
|
|
/**
|
|
|
|
* Convenience getter for testing.
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
function getBoundary() {
|
2010-06-10 13:42:13 +00:00
|
|
|
if (empty($this->__boundary)) {
|
|
|
|
return null;
|
|
|
|
}
|
2009-04-25 00:01:57 +00:00
|
|
|
return $this->__boundary;
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-04-25 00:01:57 +00:00
|
|
|
/**
|
|
|
|
* Convenience getter for testing.
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
function getMessage() {
|
2010-06-10 13:42:13 +00:00
|
|
|
if (empty($this->__message)) {
|
|
|
|
return array();
|
|
|
|
}
|
2009-04-25 00:01:57 +00:00
|
|
|
return $this->__message;
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-07-02 02:58:43 +00:00
|
|
|
/**
|
|
|
|
* Convenience method for testing.
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
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
|
|
|
}
|
2009-04-24 18:20:51 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* EmailTestController class
|
2008-06-11 08:54:27 +00:00
|
|
|
*
|
2008-10-30 17:30:26 +00:00
|
|
|
* @package cake
|
|
|
|
* @subpackage cake.tests.cases.libs.controller.components
|
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'
|
|
|
|
* @access public
|
|
|
|
*/
|
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
|
|
|
|
* @access public
|
|
|
|
*/
|
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
|
|
|
|
* @access public
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $components = array('Session', 'EmailTest');
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-03-18 17:55:58 +00:00
|
|
|
/**
|
|
|
|
* pageTitle property
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
* @access public
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $pageTitle = 'EmailTest';
|
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
|
|
|
*
|
2008-10-30 17:30:26 +00:00
|
|
|
* @package cake
|
|
|
|
* @subpackage cake.tests.cases.libs.controller.components
|
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
|
|
|
|
* @access public
|
|
|
|
*/
|
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'
|
|
|
|
* @access public
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $name = 'Email';
|
2009-07-24 19:18:37 +00:00
|
|
|
|
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
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function setUp() {
|
2009-03-21 23:55:39 +00:00
|
|
|
$this->_appEncoding = Configure::read('App.encoding');
|
|
|
|
Configure::write('App.encoding', 'UTF-8');
|
|
|
|
|
2010-06-10 13:42:13 +00:00
|
|
|
$this->Controller = new EmailTestController();
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-06-10 13:42:13 +00:00
|
|
|
$this->Controller->Component->init($this->Controller);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2009-04-24 18:20:51 +00:00
|
|
|
$this->Controller->EmailTest->initialize($this->Controller, array());
|
2008-05-30 11:40:08 +00:00
|
|
|
ClassRegistry::addObject('view', new View($this->Controller));
|
2009-03-21 23:55:39 +00:00
|
|
|
|
2009-06-11 16:13:16 +00:00
|
|
|
App::build(array(
|
|
|
|
'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS)
|
|
|
|
));
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-03-21 23:55:39 +00:00
|
|
|
/**
|
|
|
|
* tearDown method
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function tearDown() {
|
|
|
|
Configure::write('App.encoding', $this->_appEncoding);
|
2009-06-11 16:13:16 +00:00
|
|
|
App::build();
|
2009-10-21 11:00:51 +00:00
|
|
|
$this->Controller->Session->delete('Message');
|
2009-03-21 23:55:39 +00:00
|
|
|
ClassRegistry::flush();
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-08-09 22:39:05 +00:00
|
|
|
/**
|
|
|
|
* osFix method
|
|
|
|
*
|
|
|
|
* @param string $string
|
|
|
|
* @access private
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
function __osFix($string) {
|
|
|
|
return str_replace(array("\r\n", "\r"), "\n", $string);
|
|
|
|
}
|
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testBadSmtpSend method
|
2008-06-11 08:54:27 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testBadSmtpSend() {
|
2009-04-24 18:20:51 +00:00
|
|
|
$this->Controller->EmailTest->smtpOptions['host'] = 'blah';
|
|
|
|
$this->Controller->EmailTest->delivery = 'smtp';
|
|
|
|
$this->assertFalse($this->Controller->EmailTest->send('Should not work'));
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testSmtpSend method
|
2008-06-11 08:54:27 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testSmtpSend() {
|
2009-03-21 23:55:39 +00:00
|
|
|
if (!$this->skipIf(!@fsockopen('localhost', 25), '%s No SMTP server running on localhost')) {
|
2008-11-11 19:52:41 +00:00
|
|
|
return;
|
|
|
|
}
|
2009-08-10 02:20:22 +00:00
|
|
|
|
2009-04-24 18:20:51 +00:00
|
|
|
$this->Controller->EmailTest->to = 'postmaster@localhost';
|
|
|
|
$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;
|
|
|
|
|
|
|
|
$this->Controller->EmailTest->delivery = 'smtp';
|
|
|
|
$this->assertTrue($this->Controller->EmailTest->send('This is the body of the message'));
|
|
|
|
|
|
|
|
$this->Controller->EmailTest->_debug = true;
|
|
|
|
$this->Controller->EmailTest->sendAs = 'text';
|
2008-11-11 19:52:41 +00:00
|
|
|
$expect = <<<TEMPDOC
|
2008-05-30 11:40:08 +00:00
|
|
|
<pre>Host: localhost
|
|
|
|
Port: 25
|
|
|
|
Timeout: 30
|
|
|
|
To: postmaster@localhost
|
|
|
|
From: noreply@example.com
|
|
|
|
Subject: Cake SMTP test
|
|
|
|
Header:
|
|
|
|
|
|
|
|
To: postmaster@localhost
|
|
|
|
From: noreply@example.com
|
|
|
|
Reply-To: noreply@example.com
|
2008-10-01 18:36:38 +00:00
|
|
|
Subject: Cake SMTP test
|
2008-05-30 11:40:08 +00:00
|
|
|
X-Mailer: CakePHP Email Component
|
|
|
|
Content-Type: text/plain; charset=UTF-8
|
|
|
|
Content-Transfer-Encoding: 7bitParameters:
|
|
|
|
|
|
|
|
Message:
|
|
|
|
|
|
|
|
This is the body of the message
|
|
|
|
|
2010-02-04 02:35:33 +00:00
|
|
|
</pre>
|
|
|
|
TEMPDOC;
|
|
|
|
$this->assertTrue($this->Controller->EmailTest->send('This is the body of the message'));
|
|
|
|
$this->assertEqual($this->Controller->Session->read('Message.email.message'), $this->__osFix($expect));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* testSmtpSendMultipleTo method
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testSmtpSendMultipleTo() {
|
2010-02-07 21:45:36 +00:00
|
|
|
if (!$this->skipIf(!@fsockopen('localhost', 25), '%s No SMTP server running on localhost')) {
|
2010-02-04 02:35:33 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
$this->Controller->EmailTest->reset();
|
|
|
|
$this->Controller->EmailTest->to = array('postmaster@localhost', 'root@localhost');
|
|
|
|
$this->Controller->EmailTest->from = 'noreply@example.com';
|
|
|
|
$this->Controller->EmailTest->subject = 'Cake SMTP multiple To test';
|
|
|
|
$this->Controller->EmailTest->replyTo = 'noreply@example.com';
|
|
|
|
$this->Controller->EmailTest->template = null;
|
|
|
|
|
|
|
|
$this->Controller->EmailTest->delivery = 'smtp';
|
|
|
|
$this->assertTrue($this->Controller->EmailTest->send('This is the body of the message'));
|
|
|
|
|
|
|
|
$this->Controller->EmailTest->_debug = true;
|
|
|
|
$this->Controller->EmailTest->sendAs = 'text';
|
|
|
|
$expect = <<<TEMPDOC
|
|
|
|
<pre>Host: localhost
|
|
|
|
Port: 25
|
|
|
|
Timeout: 30
|
|
|
|
To: postmaster@localhost, root@localhost
|
|
|
|
From: noreply@example.com
|
|
|
|
Subject: Cake SMTP multiple To test
|
|
|
|
Header:
|
|
|
|
|
|
|
|
To: postmaster@localhost, root@localhost
|
|
|
|
From: noreply@example.com
|
|
|
|
Reply-To: noreply@example.com
|
|
|
|
Subject: Cake SMTP multiple To test
|
|
|
|
X-Mailer: CakePHP Email Component
|
|
|
|
Content-Type: text/plain; charset=UTF-8
|
|
|
|
Content-Transfer-Encoding: 7bitParameters:
|
|
|
|
|
|
|
|
Message:
|
|
|
|
|
|
|
|
This is the body of the message
|
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
</pre>
|
|
|
|
TEMPDOC;
|
2009-04-24 18:20:51 +00:00
|
|
|
$this->assertTrue($this->Controller->EmailTest->send('This is the body of the message'));
|
2008-11-11 19:52:41 +00:00
|
|
|
$this->assertEqual($this->Controller->Session->read('Message.email.message'), $this->__osFix($expect));
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testAuthenticatedSmtpSend method
|
2008-06-11 08:54:27 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testAuthenticatedSmtpSend() {
|
2009-03-21 23:55:39 +00:00
|
|
|
$this->skipIf(!@fsockopen('localhost', 25), '%s No SMTP server running on localhost');
|
2008-11-11 19:52:41 +00:00
|
|
|
|
2009-04-24 18:20:51 +00:00
|
|
|
$this->Controller->EmailTest->to = 'postmaster@localhost';
|
|
|
|
$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;
|
|
|
|
$this->Controller->EmailTest->smtpOptions['username'] = 'test';
|
|
|
|
$this->Controller->EmailTest->smtpOptions['password'] = 'testing';
|
|
|
|
|
|
|
|
$this->Controller->EmailTest->delivery = 'smtp';
|
|
|
|
$result = $this->Controller->EmailTest->send('This is the body of the message');
|
|
|
|
$code = substr($this->Controller->EmailTest->smtpError, 0, 3);
|
2009-03-21 23:55:39 +00:00
|
|
|
$this->skipIf(!$code, '%s Authentication not enabled on server');
|
2009-04-24 18:20:51 +00:00
|
|
|
|
|
|
|
$this->assertFalse($result);
|
|
|
|
$this->assertEqual($code, '535');
|
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
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testSendFormats() {
|
2009-04-24 18:20:51 +00:00
|
|
|
$this->Controller->EmailTest->to = 'postmaster@localhost';
|
|
|
|
$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;
|
|
|
|
$this->Controller->EmailTest->delivery = 'debug';
|
2010-01-24 22:29:53 +00:00
|
|
|
$this->Controller->EmailTest->messageId = false;
|
2008-11-11 19:52:41 +00:00
|
|
|
|
|
|
|
$message = <<<MSGBLOC
|
2008-05-30 11:40:08 +00:00
|
|
|
<pre>To: postmaster@localhost
|
|
|
|
From: noreply@example.com
|
|
|
|
Subject: Cake SMTP test
|
|
|
|
Header:
|
|
|
|
|
|
|
|
From: noreply@example.com
|
|
|
|
Reply-To: noreply@example.com
|
|
|
|
X-Mailer: CakePHP Email Component
|
2008-07-24 13:54:39 +00:00
|
|
|
Content-Type: {CONTENTTYPE}
|
2008-05-30 11:40:08 +00:00
|
|
|
Content-Transfer-Encoding: 7bitParameters:
|
|
|
|
|
|
|
|
Message:
|
|
|
|
|
|
|
|
This is the body of the message
|
|
|
|
|
|
|
|
</pre>
|
2008-07-24 13:54:39 +00:00
|
|
|
MSGBLOC;
|
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'));
|
2008-11-11 19:52:41 +00:00
|
|
|
$this->assertEqual($this->Controller->Session->read('Message.email.message'), $this->__osFix($expect));
|
|
|
|
|
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'));
|
2008-11-11 19:52:41 +00:00
|
|
|
$this->assertEqual($this->Controller->Session->read('Message.email.message'), $this->__osFix($expect));
|
|
|
|
|
|
|
|
// TODO: better test for format of message sent?
|
2009-04-24 18:20:51 +00:00
|
|
|
$this->Controller->EmailTest->sendAs = 'both';
|
2009-07-22 16:04:53 +00:00
|
|
|
$expect = str_replace('{CONTENTTYPE}', 'multipart/alternative; boundary="alt-"', $message);
|
|
|
|
|
2009-04-24 18:20:51 +00:00
|
|
|
$this->assertTrue($this->Controller->EmailTest->send('This is the body of the message'));
|
2008-11-11 19:52:41 +00:00
|
|
|
$this->assertEqual($this->Controller->Session->read('Message.email.message'), $this->__osFix($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
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testTemplates() {
|
2009-04-24 18:20:51 +00:00
|
|
|
$this->Controller->EmailTest->to = 'postmaster@localhost';
|
|
|
|
$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
|
|
|
|
2009-04-24 18:20:51 +00:00
|
|
|
$this->Controller->EmailTest->delivery = 'debug';
|
2010-01-24 22:29:53 +00:00
|
|
|
$this->Controller->EmailTest->messageId = false;
|
2008-07-24 13:54:39 +00:00
|
|
|
|
2008-11-11 19:52:41 +00:00
|
|
|
$header = <<<HEADBLOC
|
2008-07-24 13:54:39 +00:00
|
|
|
To: postmaster@localhost
|
|
|
|
From: noreply@example.com
|
|
|
|
Subject: Cake SMTP test
|
|
|
|
Header:
|
|
|
|
|
|
|
|
From: noreply@example.com
|
|
|
|
Reply-To: noreply@example.com
|
|
|
|
X-Mailer: CakePHP Email Component
|
|
|
|
Content-Type: {CONTENTTYPE}
|
|
|
|
Content-Transfer-Encoding: 7bitParameters:
|
|
|
|
|
|
|
|
Message:
|
|
|
|
|
|
|
|
|
|
|
|
HEADBLOC;
|
|
|
|
|
2009-04-24 18:20:51 +00:00
|
|
|
$this->Controller->EmailTest->layout = 'default';
|
|
|
|
$this->Controller->EmailTest->template = 'default';
|
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'));
|
2008-11-11 19:52:41 +00:00
|
|
|
$this->assertEqual($this->Controller->Session->read('Message.email.message'), $this->__osFix($expect));
|
|
|
|
|
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'));
|
2008-11-11 19:52:41 +00:00
|
|
|
$this->assertEqual($this->Controller->Session->read('Message.email.message'), $this->__osFix($expect));
|
|
|
|
|
2009-04-24 18:20:51 +00:00
|
|
|
$this->Controller->EmailTest->sendAs = 'both';
|
2009-07-22 16:04:53 +00:00
|
|
|
$expect = str_replace('{CONTENTTYPE}', 'multipart/alternative; boundary="alt-"', $header);
|
2008-11-11 19:52:41 +00:00
|
|
|
$expect .= '--alt-' . "\n" . 'Content-Type: text/plain; charset=UTF-8' . "\n" . 'Content-Transfer-Encoding: 7bit' . "\n\n" . $text . "\n\n";
|
|
|
|
$expect .= '--alt-' . "\n" . 'Content-Type: text/html; charset=UTF-8' . "\n" . 'Content-Transfer-Encoding: 7bit' . "\n\n" . $html . "\n\n";
|
|
|
|
$expect = '<pre>' . $expect . '--alt---' . "\n\n" . '</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'));
|
2008-11-11 19:52:41 +00:00
|
|
|
$this->assertEqual($this->Controller->Session->read('Message.email.message'), $this->__osFix($expect));
|
|
|
|
|
|
|
|
$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'));
|
2008-11-11 19:52:41 +00:00
|
|
|
$this->assertEqual($this->Controller->Session->read('Message.email.message'), $this->__osFix($expect));
|
2008-08-05 17:02:22 +00:00
|
|
|
|
2008-11-11 19:52:41 +00:00
|
|
|
return;
|
2008-08-05 17:02:22 +00:00
|
|
|
|
2008-11-11 19:52:41 +00:00
|
|
|
$text = <<<TEXTBLOC
|
2008-08-05 17:02:22 +00:00
|
|
|
|
|
|
|
This element has some text that is just too wide to comply with email
|
|
|
|
standards.
|
|
|
|
This is the body of the message
|
|
|
|
|
|
|
|
This email was sent using the CakePHP Framework, http://cakephp.org.
|
|
|
|
TEXTBLOC;
|
|
|
|
|
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', 'wide', 'default'));
|
2008-11-11 19:52:41 +00:00
|
|
|
$this->assertEqual($this->Controller->Session->read('Message.email.message'), $this->__osFix($expect));
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-04-24 18:20:51 +00:00
|
|
|
/**
|
|
|
|
* testSmtpSendSocket method
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testSmtpSendSocket() {
|
|
|
|
$this->skipIf(!@fsockopen('localhost', 25), '%s No SMTP server running on localhost');
|
|
|
|
|
2010-06-10 13:42:13 +00:00
|
|
|
$socket = new CakeSocket(array_merge(array('protocol'=>'smtp'), $this->Controller->EmailTest->smtpOptions));
|
2009-04-24 18:20:51 +00:00
|
|
|
$this->Controller->EmailTest->setConnectionSocket($socket);
|
|
|
|
|
|
|
|
$this->assertTrue($this->Controller->EmailTest->getConnectionSocket());
|
|
|
|
|
|
|
|
$response = $this->Controller->EmailTest->smtpSend('HELO', '250');
|
|
|
|
$this->assertPattern('/501 Syntax: HELO hostname/', $this->Controller->EmailTest->smtpError);
|
|
|
|
|
2009-09-06 23:49:50 +00:00
|
|
|
$this->Controller->EmailTest->reset();
|
2009-04-24 18:20:51 +00:00
|
|
|
$response = $this->Controller->EmailTest->smtpSend('HELO somehostname', '250');
|
|
|
|
$this->assertNoPattern('/501 Syntax: HELO hostname/', $this->Controller->EmailTest->smtpError);
|
|
|
|
}
|
2009-07-24 19:18:37 +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
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testSendDebug() {
|
2009-04-24 18:20:51 +00:00
|
|
|
$this->Controller->EmailTest->to = 'postmaster@localhost';
|
|
|
|
$this->Controller->EmailTest->from = 'noreply@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;
|
|
|
|
|
|
|
|
$this->Controller->EmailTest->delivery = 'debug';
|
|
|
|
$this->assertTrue($this->Controller->EmailTest->send('This is the body of the message'));
|
2009-08-09 22:53:09 +00:00
|
|
|
$result = $this->Controller->Session->read('Message.email.message');
|
|
|
|
|
2009-08-10 00:34:23 +00:00
|
|
|
$this->assertPattern('/To: postmaster@localhost\n/', $result);
|
|
|
|
$this->assertPattern('/Subject: Cake Debug Test\n/', $result);
|
|
|
|
$this->assertPattern('/Reply-To: noreply@example.com\n/', $result);
|
|
|
|
$this->assertPattern('/From: noreply@example.com\n/', $result);
|
|
|
|
$this->assertPattern('/X-Mailer: CakePHP Email Component\n/', $result);
|
|
|
|
$this->assertPattern('/Content-Type: text\/plain; charset=UTF-8\n/', $result);
|
|
|
|
$this->assertPattern('/Content-Transfer-Encoding: 7bitParameters:\n/', $result);
|
2009-08-09 22:53:09 +00:00
|
|
|
$this->assertPattern('/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
|
|
|
|
*/
|
|
|
|
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);
|
|
|
|
$this->Controller->EmailTest->to = 'postmaster@localhost';
|
|
|
|
$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;
|
2009-08-09 22:53:09 +00:00
|
|
|
|
2010-04-17 16:27:50 +00:00
|
|
|
$this->Controller->EmailTest->delivery = 'debug';
|
|
|
|
$result = $this->Controller->EmailTest->send('This is the body of the message');
|
|
|
|
|
|
|
|
$this->assertPattern('/To: postmaster@localhost\n/', $result);
|
|
|
|
$this->assertPattern('/Subject: Cake Debug Test\n/', $result);
|
|
|
|
$this->assertPattern('/Reply-To: noreply@example.com\n/', $result);
|
|
|
|
$this->assertPattern('/From: noreply@example.com\n/', $result);
|
|
|
|
$this->assertPattern('/X-Mailer: CakePHP Email Component\n/', $result);
|
|
|
|
$this->assertPattern('/Content-Type: text\/plain; charset=UTF-8\n/', $result);
|
|
|
|
$this->assertPattern('/Content-Transfer-Encoding: 7bitParameters:\n/', $result);
|
|
|
|
$this->assertPattern('/This is the body of the message/', $result);
|
|
|
|
$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
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testMessageRetrievalWithoutTemplate() {
|
|
|
|
App::build(array(
|
|
|
|
'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS)
|
|
|
|
));
|
|
|
|
|
|
|
|
$this->Controller->EmailTest->to = 'postmaster@localhost';
|
|
|
|
$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;
|
|
|
|
|
|
|
|
$this->Controller->EmailTest->delivery = 'debug';
|
|
|
|
|
|
|
|
$text = $html = 'This is the body of the message';
|
|
|
|
|
|
|
|
$this->Controller->EmailTest->sendAs = 'both';
|
|
|
|
$this->assertTrue($this->Controller->EmailTest->send('This is the body of the message'));
|
|
|
|
$this->assertEqual($this->Controller->EmailTest->textMessage, $this->__osFix($text));
|
|
|
|
$this->assertEqual($this->Controller->EmailTest->htmlMessage, $this->__osFix($html));
|
|
|
|
|
|
|
|
$this->Controller->EmailTest->sendAs = 'text';
|
|
|
|
$this->assertTrue($this->Controller->EmailTest->send('This is the body of the message'));
|
|
|
|
$this->assertEqual($this->Controller->EmailTest->textMessage, $this->__osFix($text));
|
|
|
|
$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);
|
|
|
|
$this->assertEqual($this->Controller->EmailTest->htmlMessage, $this->__osFix($html));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* testMessageRetrievalWithTemplate method
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testMessageRetrievalWithTemplate() {
|
|
|
|
App::build(array(
|
|
|
|
'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS)
|
|
|
|
));
|
|
|
|
|
|
|
|
$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
|
|
|
|
|
|
|
$this->Controller->EmailTest->to = 'postmaster@localhost';
|
|
|
|
$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';
|
|
|
|
|
|
|
|
$this->Controller->EmailTest->delivery = 'debug';
|
|
|
|
|
|
|
|
$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>
|
|
|
|
<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());
|
|
|
|
$this->assertEqual($this->Controller->EmailTest->textMessage, $this->__osFix($text));
|
|
|
|
$this->assertEqual($this->Controller->EmailTest->htmlMessage, $this->__osFix($html));
|
|
|
|
|
|
|
|
$this->Controller->EmailTest->sendAs = 'text';
|
|
|
|
$this->assertTrue($this->Controller->EmailTest->send());
|
|
|
|
$this->assertEqual($this->Controller->EmailTest->textMessage, $this->__osFix($text));
|
|
|
|
$this->assertNull($this->Controller->EmailTest->htmlMessage);
|
|
|
|
|
|
|
|
$this->Controller->EmailTest->sendAs = 'html';
|
|
|
|
$this->assertTrue($this->Controller->EmailTest->send());
|
|
|
|
$this->assertNull($this->Controller->EmailTest->textMessage);
|
|
|
|
$this->assertEqual($this->Controller->EmailTest->htmlMessage, $this->__osFix($html));
|
|
|
|
}
|
|
|
|
|
2009-08-09 23:09:02 +00:00
|
|
|
/**
|
|
|
|
* testContentArray method
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testSendContentArray() {
|
|
|
|
$this->Controller->EmailTest->to = 'postmaster@localhost';
|
|
|
|
$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;
|
|
|
|
$this->Controller->EmailTest->delivery = 'debug';
|
|
|
|
|
|
|
|
$content = array('First line', 'Second line', 'Third line');
|
|
|
|
$this->assertTrue($this->Controller->EmailTest->send($content));
|
|
|
|
$result = $this->Controller->Session->read('Message.email.message');
|
|
|
|
|
2009-08-10 00:34:23 +00:00
|
|
|
$this->assertPattern('/To: postmaster@localhost\n/', $result);
|
|
|
|
$this->assertPattern('/Subject: Cake Debug Test\n/', $result);
|
|
|
|
$this->assertPattern('/Reply-To: noreply@example.com\n/', $result);
|
|
|
|
$this->assertPattern('/From: noreply@example.com\n/', $result);
|
|
|
|
$this->assertPattern('/X-Mailer: CakePHP Email Component\n/', $result);
|
|
|
|
$this->assertPattern('/Content-Type: text\/plain; charset=UTF-8\n/', $result);
|
|
|
|
$this->assertPattern('/Content-Transfer-Encoding: 7bitParameters:\n/', $result);
|
2009-08-09 23:09:02 +00:00
|
|
|
$this->assertPattern('/First line\n/', $result);
|
|
|
|
$this->assertPattern('/Second line\n/', $result);
|
|
|
|
$this->assertPattern('/Third line\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
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function testContentStripping() {
|
|
|
|
$content = "Previous content\n--alt-\nContent-TypeContent-Type:: text/html; charsetcharset==utf-8\nContent-Transfer-Encoding: 7bit";
|
|
|
|
$content .= "\n\n<p>My own html content</p>";
|
|
|
|
|
2009-07-02 02:58:43 +00:00
|
|
|
$result = $this->Controller->EmailTest->strip($content, true);
|
2008-05-30 11:40:08 +00:00
|
|
|
$expected = "Previous content\n--alt-\n text/html; utf-8\n 7bit\n\n<p>My own html content</p>";
|
|
|
|
$this->assertEqual($result, $expected);
|
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;
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
$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;
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
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
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-10-01 18:36:38 +00:00
|
|
|
function testMultibyte() {
|
2009-04-24 18:20:51 +00:00
|
|
|
$this->Controller->EmailTest->to = 'postmaster@localhost';
|
|
|
|
$this->Controller->EmailTest->from = 'noreply@example.com';
|
|
|
|
$this->Controller->EmailTest->subject = 'هذه رسالة بعنوان طويل مرسل للمستلم';
|
|
|
|
$this->Controller->EmailTest->replyTo = 'noreply@example.com';
|
|
|
|
$this->Controller->EmailTest->template = null;
|
|
|
|
$this->Controller->EmailTest->delivery = 'debug';
|
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'));
|
2008-11-11 19:52:41 +00:00
|
|
|
preg_match('/Subject: (.*)Header:/s', $this->Controller->Session->read('Message.email.message'), $matches);
|
|
|
|
$this->assertEqual(trim($matches[1]), $subject);
|
|
|
|
|
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'));
|
2008-11-11 19:52:41 +00:00
|
|
|
preg_match('/Subject: (.*)Header:/s', $this->Controller->Session->read('Message.email.message'), $matches);
|
|
|
|
$this->assertEqual(trim($matches[1]), $subject);
|
|
|
|
|
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'));
|
2008-11-11 19:52:41 +00:00
|
|
|
preg_match('/Subject: (.*)Header:/s', $this->Controller->Session->read('Message.email.message'), $matches);
|
|
|
|
$this->assertEqual(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() {
|
2010-04-02 19:02:23 +00:00
|
|
|
$this->Controller->EmailTest->to = 'postmaster@localhost';
|
|
|
|
$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;
|
|
|
|
$this->Controller->EmailTest->delivery = 'debug';
|
|
|
|
$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));
|
|
|
|
$msg = $this->Controller->Session->read('Message.email.message');
|
|
|
|
$this->assertPattern('/' . preg_quote('Content-Disposition: attachment; filename="email.test.php"') . '/', $msg);
|
|
|
|
$this->assertPattern('/' . preg_quote('Content-Disposition: attachment; filename="some-name.php"') . '/', $msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* testSendAsIsNotIgnoredIfAttachmentsPresent method
|
|
|
|
*
|
|
|
|
* @return void
|
2009-07-21 21:54:05 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function testSendAsIsNotIgnoredIfAttachmentsPresent() {
|
2009-07-21 21:54:05 +00:00
|
|
|
$this->Controller->EmailTest->to = 'postmaster@localhost';
|
|
|
|
$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;
|
|
|
|
$this->Controller->EmailTest->delivery = 'debug';
|
|
|
|
$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));
|
|
|
|
$msg = $this->Controller->Session->read('Message.email.message');
|
|
|
|
$this->assertNoPattern('/text\/plain/', $msg);
|
|
|
|
$this->assertPattern('/text\/html/', $msg);
|
|
|
|
|
|
|
|
$this->Controller->EmailTest->sendAs = 'text';
|
|
|
|
$this->assertTrue($this->Controller->EmailTest->send($body));
|
|
|
|
$msg = $this->Controller->Session->read('Message.email.message');
|
|
|
|
$this->assertPattern('/text\/plain/', $msg);
|
|
|
|
$this->assertNoPattern('/text\/html/', $msg);
|
|
|
|
|
|
|
|
$this->Controller->EmailTest->sendAs = 'both';
|
|
|
|
$this->assertTrue($this->Controller->EmailTest->send($body));
|
|
|
|
$msg = $this->Controller->Session->read('Message.email.message');
|
2009-07-22 16:04:53 +00:00
|
|
|
|
2009-07-21 21:54:05 +00:00
|
|
|
$this->assertNoPattern('/text\/plain/', $msg);
|
|
|
|
$this->assertNoPattern('/text\/html/', $msg);
|
|
|
|
$this->assertPattern('/multipart\/alternative/', $msg);
|
|
|
|
}
|
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() {
|
2009-07-22 16:04:53 +00:00
|
|
|
$this->Controller->EmailTest->to = 'postmaster@localhost';
|
|
|
|
$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;
|
|
|
|
$this->Controller->EmailTest->delivery = 'debug';
|
|
|
|
$body = '<p>This is the body of the message</p>';
|
|
|
|
|
|
|
|
$this->Controller->EmailTest->sendAs = 'both';
|
|
|
|
$this->assertTrue($this->Controller->EmailTest->send($body));
|
|
|
|
$msg = $this->Controller->Session->read('Message.email.message');
|
|
|
|
|
|
|
|
$this->assertNoPattern('/\n\nContent-Transfer-Encoding/', $msg);
|
|
|
|
$this->assertPattern('/\nContent-Transfer-Encoding/', $msg);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-04-25 00:01:57 +00:00
|
|
|
/**
|
|
|
|
* testReset method
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testReset() {
|
|
|
|
$this->Controller->EmailTest->template = 'test_template';
|
|
|
|
$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');
|
|
|
|
$this->Controller->EmailTest->subject = 'Test subject';
|
|
|
|
$this->Controller->EmailTest->additionalParams = 'X-additional-header';
|
|
|
|
$this->Controller->EmailTest->delivery = 'smtp';
|
|
|
|
$this->Controller->EmailTest->smtpOptions['host'] = 'blah';
|
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;
|
2009-04-25 00:01:57 +00:00
|
|
|
|
|
|
|
$this->assertFalse($this->Controller->EmailTest->send('Should not work'));
|
|
|
|
|
|
|
|
$this->Controller->EmailTest->reset();
|
|
|
|
|
|
|
|
$this->assertNull($this->Controller->EmailTest->template);
|
2010-02-04 02:35:33 +00:00
|
|
|
$this->assertIdentical($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);
|
|
|
|
$this->assertIdentical($this->Controller->EmailTest->cc, array());
|
|
|
|
$this->assertIdentical($this->Controller->EmailTest->bcc, array());
|
|
|
|
$this->assertNull($this->Controller->EmailTest->subject);
|
|
|
|
$this->assertNull($this->Controller->EmailTest->additionalParams);
|
|
|
|
$this->assertIdentical($this->Controller->EmailTest->getHeaders(), array());
|
|
|
|
$this->assertNull($this->Controller->EmailTest->getBoundary());
|
|
|
|
$this->assertIdentical($this->Controller->EmailTest->getMessage(), array());
|
|
|
|
$this->assertNull($this->Controller->EmailTest->smtpError);
|
2009-07-10 00:07:51 +00:00
|
|
|
$this->assertIdentical($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);
|
2009-04-25 00:01:57 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-08-10 02:20:22 +00:00
|
|
|
function testPluginCustomViewClass() {
|
2009-08-10 01:29:29 +00:00
|
|
|
App::build(array(
|
|
|
|
'plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS),
|
|
|
|
'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS)
|
|
|
|
));
|
|
|
|
|
|
|
|
$this->Controller->view = 'TestPlugin.Email';
|
|
|
|
|
|
|
|
$this->Controller->EmailTest->to = 'postmaster@localhost';
|
|
|
|
$this->Controller->EmailTest->from = 'noreply@example.com';
|
|
|
|
$this->Controller->EmailTest->subject = 'CustomViewClass test';
|
|
|
|
$this->Controller->EmailTest->delivery = 'debug';
|
|
|
|
$body = 'Body of message';
|
|
|
|
|
|
|
|
$this->assertTrue($this->Controller->EmailTest->send($body));
|
|
|
|
$result = $this->Controller->Session->read('Message.email.message');
|
|
|
|
|
|
|
|
$this->assertPattern('/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
|
|
|
* @access public
|
|
|
|
* @return void
|
2009-03-18 17:55:58 +00:00
|
|
|
*/
|
2009-08-09 22:39:05 +00:00
|
|
|
function testStartup() {
|
|
|
|
$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
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testMessageId() {
|
|
|
|
$this->Controller->EmailTest->to = 'postmaster@localhost';
|
|
|
|
$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;
|
|
|
|
|
|
|
|
$this->Controller->EmailTest->delivery = 'debug';
|
|
|
|
$this->assertTrue($this->Controller->EmailTest->send('This is the body of the message'));
|
|
|
|
$result = $this->Controller->Session->read('Message.email.message');
|
|
|
|
|
|
|
|
$this->assertPattern('/Message-ID: \<[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}@' . env('HTTP_HOST') . '\>\n/', $result);
|
|
|
|
|
|
|
|
$this->Controller->EmailTest->messageId = '<22091985.998877@localhost>';
|
|
|
|
|
|
|
|
$this->assertTrue($this->Controller->EmailTest->send('This is the body of the message'));
|
|
|
|
$result = $this->Controller->Session->read('Message.email.message');
|
|
|
|
|
|
|
|
$this->assertPattern('/Message-ID: <22091985.998877@localhost>\n/', $result);
|
|
|
|
|
|
|
|
$this->Controller->EmailTest->messageId = false;
|
|
|
|
|
|
|
|
$this->assertTrue($this->Controller->EmailTest->send('This is the body of the message'));
|
|
|
|
$result = $this->Controller->Session->read('Message.email.message');
|
|
|
|
|
|
|
|
$this->assertNoPattern('/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
|
|
|
}
|