2011-04-03 22:42:05 -04:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* SmtpTransportTest file
|
|
|
|
*
|
2012-04-26 19:49:18 -07:00
|
|
|
* CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
|
2013-02-08 20:59:49 +09:00
|
|
|
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2011-04-03 22:42:05 -04:00
|
|
|
*
|
|
|
|
* Licensed under The MIT License
|
2013-02-08 21:22:51 +09:00
|
|
|
* For full copyright and license information, please see the LICENSE.txt
|
2011-04-03 22:42:05 -04:00
|
|
|
* Redistributions of files must retain the above copyright notice
|
|
|
|
*
|
2013-02-08 20:59:49 +09:00
|
|
|
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2012-04-26 19:49:18 -07:00
|
|
|
* @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
|
2011-07-26 01:46:14 -04:30
|
|
|
* @package Cake.Test.Case.Network.Email
|
2011-04-03 22:42:05 -04:00
|
|
|
* @since CakePHP(tm) v 2.0.0
|
2013-05-31 00:11:14 +02:00
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
2011-04-03 22:42:05 -04:00
|
|
|
*/
|
2013-05-31 00:11:14 +02:00
|
|
|
|
2011-04-26 22:19:17 -04:00
|
|
|
App::uses('CakeEmail', 'Network/Email');
|
2011-04-13 00:20:35 -04:00
|
|
|
App::uses('AbstractTransport', 'Network/Email');
|
2011-04-12 23:29:34 -04:00
|
|
|
App::uses('SmtpTransport', 'Network/Email');
|
2011-04-03 22:42:05 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Help to test SmtpTransport
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
class SmtpTestTransport extends SmtpTransport {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper to change the socket
|
|
|
|
*
|
|
|
|
* @param object $socket
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function setSocket(CakeSocket $socket) {
|
|
|
|
$this->_socket = $socket;
|
|
|
|
}
|
|
|
|
|
2011-04-04 00:00:01 -04:00
|
|
|
/**
|
|
|
|
* Helper to change the CakeEmail
|
|
|
|
*
|
|
|
|
* @param object $cakeEmail
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function setCakeEmail($cakeEmail) {
|
|
|
|
$this->_cakeEmail = $cakeEmail;
|
|
|
|
}
|
|
|
|
|
2011-04-03 22:42:05 -04:00
|
|
|
/**
|
|
|
|
* Disabled the socket change
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
protected function _generateSocket() {
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Magic function to call protected methods
|
|
|
|
*
|
|
|
|
* @param string $method
|
|
|
|
* @param string $args
|
|
|
|
* @return mixed
|
2011-08-26 02:31:18 +02:00
|
|
|
*/
|
2011-04-03 22:42:05 -04:00
|
|
|
public function __call($method, $args) {
|
|
|
|
$method = '_' . $method;
|
2014-03-13 16:28:54 +01:00
|
|
|
return call_user_func_array(array($this, $method), $args);
|
2011-04-03 22:42:05 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test case
|
|
|
|
*
|
|
|
|
*/
|
2011-08-26 02:31:18 +02:00
|
|
|
class SmtpTransportTest extends CakeTestCase {
|
2011-04-03 22:42:05 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Setup
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function setUp() {
|
2013-07-29 01:22:52 +02:00
|
|
|
parent::setUp();
|
2014-03-01 19:01:36 +01:00
|
|
|
$this->socket = $this->getMock('CakeSocket', array('read', 'write', 'connect', 'enableCrypto'));
|
2011-04-03 22:42:05 -04:00
|
|
|
|
|
|
|
$this->SmtpTransport = new SmtpTestTransport();
|
|
|
|
$this->SmtpTransport->setSocket($this->socket);
|
2011-10-21 15:02:53 +02:00
|
|
|
$this->SmtpTransport->config(array('client' => 'localhost'));
|
2011-04-03 22:42:05 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* testConnectEhlo method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testConnectEhlo() {
|
|
|
|
$this->socket->expects($this->any())->method('connect')->will($this->returnValue(true));
|
|
|
|
$this->socket->expects($this->at(0))->method('read')->will($this->returnValue(false));
|
|
|
|
$this->socket->expects($this->at(1))->method('read')->will($this->returnValue("220 Welcome message\r\n"));
|
|
|
|
$this->socket->expects($this->at(2))->method('write')->with("EHLO localhost\r\n");
|
|
|
|
$this->socket->expects($this->at(3))->method('read')->will($this->returnValue(false));
|
|
|
|
$this->socket->expects($this->at(4))->method('read')->will($this->returnValue("250 Accepted\r\n"));
|
|
|
|
$this->SmtpTransport->connect();
|
|
|
|
}
|
|
|
|
|
2012-07-21 20:28:38 +01:00
|
|
|
/**
|
|
|
|
* testConnectEhloTls method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testConnectEhloTls() {
|
|
|
|
$this->SmtpTransport->config(array('tls' => true));
|
|
|
|
$this->socket->expects($this->any())->method('connect')->will($this->returnValue(true));
|
|
|
|
$this->socket->expects($this->at(0))->method('read')->will($this->returnValue(false));
|
|
|
|
$this->socket->expects($this->at(1))->method('read')->will($this->returnValue("220 Welcome message\r\n"));
|
|
|
|
$this->socket->expects($this->at(2))->method('write')->with("EHLO localhost\r\n");
|
|
|
|
$this->socket->expects($this->at(3))->method('read')->will($this->returnValue(false));
|
|
|
|
$this->socket->expects($this->at(4))->method('read')->will($this->returnValue("250 Accepted\r\n"));
|
|
|
|
$this->socket->expects($this->at(5))->method('write')->with("STARTTLS\r\n");
|
|
|
|
$this->socket->expects($this->at(6))->method('read')->will($this->returnValue(false));
|
|
|
|
$this->socket->expects($this->at(7))->method('read')->will($this->returnValue("220 Server ready\r\n"));
|
2014-03-01 19:01:36 +01:00
|
|
|
$this->socket->expects($this->at(8))->method('enableCrypto')->with('tls')->will($this->returnValue(true));
|
2012-07-21 20:28:38 +01:00
|
|
|
$this->socket->expects($this->at(9))->method('write')->with("EHLO localhost\r\n");
|
|
|
|
$this->socket->expects($this->at(10))->method('read')->will($this->returnValue(false));
|
|
|
|
$this->socket->expects($this->at(11))->method('read')->will($this->returnValue("250 Accepted\r\n"));
|
|
|
|
$this->SmtpTransport->connect();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* testConnectEhloTlsOnNonTlsServer method
|
|
|
|
*
|
2012-07-24 14:09:48 +01:00
|
|
|
* @expectedException SocketException
|
2012-07-21 20:28:38 +01:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testConnectEhloTlsOnNonTlsServer() {
|
|
|
|
$this->SmtpTransport->config(array('tls' => true));
|
|
|
|
$this->socket->expects($this->any())->method('connect')->will($this->returnValue(true));
|
|
|
|
$this->socket->expects($this->at(0))->method('read')->will($this->returnValue(false));
|
|
|
|
$this->socket->expects($this->at(1))->method('read')->will($this->returnValue("220 Welcome message\r\n"));
|
|
|
|
$this->socket->expects($this->at(2))->method('write')->with("EHLO localhost\r\n");
|
|
|
|
$this->socket->expects($this->at(3))->method('read')->will($this->returnValue(false));
|
|
|
|
$this->socket->expects($this->at(4))->method('read')->will($this->returnValue("250 Accepted\r\n"));
|
|
|
|
$this->socket->expects($this->at(5))->method('write')->with("STARTTLS\r\n");
|
|
|
|
$this->socket->expects($this->at(6))->method('read')->will($this->returnValue(false));
|
|
|
|
$this->socket->expects($this->at(7))->method('read')->will($this->returnValue("500 5.3.3 Unrecognized command\r\n"));
|
|
|
|
$this->SmtpTransport->connect();
|
|
|
|
}
|
2012-08-09 20:51:29 -04:00
|
|
|
|
2012-07-21 20:28:38 +01:00
|
|
|
/**
|
|
|
|
* testConnectEhloNoTlsOnRequiredTlsServer method
|
|
|
|
*
|
2012-07-24 14:09:48 +01:00
|
|
|
* @expectedException SocketException
|
2012-07-21 20:28:38 +01:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testConnectEhloNoTlsOnRequiredTlsServer() {
|
|
|
|
$this->SmtpTransport->config(array('tls' => false, 'username' => 'user', 'password' => 'pass'));
|
|
|
|
$this->socket->expects($this->any())->method('connect')->will($this->returnValue(true));
|
|
|
|
$this->socket->expects($this->at(0))->method('read')->will($this->returnValue(false));
|
|
|
|
$this->socket->expects($this->at(1))->method('read')->will($this->returnValue("220 Welcome message\r\n"));
|
|
|
|
$this->socket->expects($this->at(2))->method('write')->with("EHLO localhost\r\n");
|
|
|
|
$this->socket->expects($this->at(3))->method('read')->will($this->returnValue(false));
|
|
|
|
$this->socket->expects($this->at(4))->method('read')->will($this->returnValue("250 Accepted\r\n"));
|
2014-03-01 19:01:36 +01:00
|
|
|
$this->socket->expects($this->at(5))->method('write')->with("AUTH LOGIN\r\n");
|
2012-07-21 20:28:38 +01:00
|
|
|
$this->socket->expects($this->at(6))->method('read')->will($this->returnValue(false));
|
|
|
|
$this->socket->expects($this->at(7))->method('read')->will($this->returnValue("504 5.7.4 Unrecognized authentication type\r\n"));
|
|
|
|
$this->SmtpTransport->connect();
|
|
|
|
$this->SmtpTransport->auth();
|
|
|
|
}
|
2012-08-09 20:51:29 -04:00
|
|
|
|
2011-04-03 22:42:05 -04:00
|
|
|
/**
|
|
|
|
* testConnectHelo method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testConnectHelo() {
|
|
|
|
$this->socket->expects($this->any())->method('connect')->will($this->returnValue(true));
|
|
|
|
$this->socket->expects($this->at(0))->method('read')->will($this->returnValue(false));
|
|
|
|
$this->socket->expects($this->at(1))->method('read')->will($this->returnValue("220 Welcome message\r\n"));
|
|
|
|
$this->socket->expects($this->at(2))->method('write')->with("EHLO localhost\r\n");
|
|
|
|
$this->socket->expects($this->at(3))->method('read')->will($this->returnValue(false));
|
|
|
|
$this->socket->expects($this->at(4))->method('read')->will($this->returnValue("200 Not Accepted\r\n"));
|
|
|
|
$this->socket->expects($this->at(5))->method('write')->with("HELO localhost\r\n");
|
|
|
|
$this->socket->expects($this->at(6))->method('read')->will($this->returnValue(false));
|
|
|
|
$this->socket->expects($this->at(7))->method('read')->will($this->returnValue("250 Accepted\r\n"));
|
|
|
|
$this->SmtpTransport->connect();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* testConnectFail method
|
|
|
|
*
|
2011-11-03 21:16:29 -04:00
|
|
|
* @expectedException SocketException
|
2011-04-03 22:42:05 -04:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-08-26 02:31:18 +02:00
|
|
|
public function testConnectFail() {
|
2011-04-03 22:42:05 -04:00
|
|
|
$this->socket->expects($this->any())->method('connect')->will($this->returnValue(true));
|
|
|
|
$this->socket->expects($this->at(0))->method('read')->will($this->returnValue(false));
|
|
|
|
$this->socket->expects($this->at(1))->method('read')->will($this->returnValue("220 Welcome message\r\n"));
|
|
|
|
$this->socket->expects($this->at(2))->method('write')->with("EHLO localhost\r\n");
|
|
|
|
$this->socket->expects($this->at(3))->method('read')->will($this->returnValue(false));
|
|
|
|
$this->socket->expects($this->at(4))->method('read')->will($this->returnValue("200 Not Accepted\r\n"));
|
|
|
|
$this->socket->expects($this->at(5))->method('write')->with("HELO localhost\r\n");
|
|
|
|
$this->socket->expects($this->at(6))->method('read')->will($this->returnValue(false));
|
|
|
|
$this->socket->expects($this->at(7))->method('read')->will($this->returnValue("200 Not Accepted\r\n"));
|
|
|
|
$this->SmtpTransport->connect();
|
|
|
|
}
|
|
|
|
|
2011-04-03 23:29:08 -04:00
|
|
|
/**
|
|
|
|
* testAuth method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testAuth() {
|
|
|
|
$this->socket->expects($this->at(0))->method('write')->with("AUTH LOGIN\r\n");
|
|
|
|
$this->socket->expects($this->at(1))->method('read')->will($this->returnValue(false));
|
|
|
|
$this->socket->expects($this->at(2))->method('read')->will($this->returnValue("334 Login\r\n"));
|
|
|
|
$this->socket->expects($this->at(3))->method('write')->with("bWFyaw==\r\n");
|
|
|
|
$this->socket->expects($this->at(4))->method('read')->will($this->returnValue(false));
|
|
|
|
$this->socket->expects($this->at(5))->method('read')->will($this->returnValue("334 Pass\r\n"));
|
|
|
|
$this->socket->expects($this->at(6))->method('write')->with("c3Rvcnk=\r\n");
|
|
|
|
$this->socket->expects($this->at(7))->method('read')->will($this->returnValue(false));
|
|
|
|
$this->socket->expects($this->at(8))->method('read')->will($this->returnValue("235 OK\r\n"));
|
2011-04-15 22:09:56 -04:00
|
|
|
$this->SmtpTransport->config(array('username' => 'mark', 'password' => 'story'));
|
2011-04-03 23:29:08 -04:00
|
|
|
$this->SmtpTransport->auth();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* testAuthNoAuth method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testAuthNoAuth() {
|
2014-03-02 17:56:35 +01:00
|
|
|
$this->socket->expects($this->any())->method('write')->with($this->logicalNot($this->stringContains('AUTH LOGIN')));
|
2014-03-01 19:01:36 +01:00
|
|
|
|
2011-04-15 22:09:56 -04:00
|
|
|
$this->SmtpTransport->config(array('username' => null, 'password' => null));
|
2011-04-03 23:29:08 -04:00
|
|
|
$this->SmtpTransport->auth();
|
|
|
|
}
|
|
|
|
|
2011-04-04 00:00:01 -04:00
|
|
|
/**
|
|
|
|
* testRcpt method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testRcpt() {
|
|
|
|
$email = new CakeEmail();
|
|
|
|
$email->from('noreply@cakephp.org', 'CakePHP Test');
|
|
|
|
$email->to('cake@cakephp.org', 'CakePHP');
|
|
|
|
$email->bcc('phpnut@cakephp.org');
|
|
|
|
$email->cc(array('mark@cakephp.org' => 'Mark Story', 'juan@cakephp.org' => 'Juan Basso'));
|
|
|
|
|
|
|
|
$this->socket->expects($this->at(0))->method('write')->with("MAIL FROM:<noreply@cakephp.org>\r\n");
|
|
|
|
$this->socket->expects($this->at(1))->method('read')->will($this->returnValue(false));
|
|
|
|
$this->socket->expects($this->at(2))->method('read')->will($this->returnValue("250 OK\r\n"));
|
|
|
|
$this->socket->expects($this->at(3))->method('write')->with("RCPT TO:<cake@cakephp.org>\r\n");
|
|
|
|
$this->socket->expects($this->at(4))->method('read')->will($this->returnValue(false));
|
|
|
|
$this->socket->expects($this->at(5))->method('read')->will($this->returnValue("250 OK\r\n"));
|
|
|
|
$this->socket->expects($this->at(6))->method('write')->with("RCPT TO:<mark@cakephp.org>\r\n");
|
|
|
|
$this->socket->expects($this->at(7))->method('read')->will($this->returnValue(false));
|
|
|
|
$this->socket->expects($this->at(8))->method('read')->will($this->returnValue("250 OK\r\n"));
|
|
|
|
$this->socket->expects($this->at(9))->method('write')->with("RCPT TO:<juan@cakephp.org>\r\n");
|
|
|
|
$this->socket->expects($this->at(10))->method('read')->will($this->returnValue(false));
|
|
|
|
$this->socket->expects($this->at(11))->method('read')->will($this->returnValue("250 OK\r\n"));
|
|
|
|
$this->socket->expects($this->at(12))->method('write')->with("RCPT TO:<phpnut@cakephp.org>\r\n");
|
|
|
|
$this->socket->expects($this->at(13))->method('read')->will($this->returnValue(false));
|
|
|
|
$this->socket->expects($this->at(14))->method('read')->will($this->returnValue("250 OK\r\n"));
|
|
|
|
|
|
|
|
$this->SmtpTransport->setCakeEmail($email);
|
|
|
|
$this->SmtpTransport->sendRcpt();
|
|
|
|
}
|
|
|
|
|
2013-06-12 11:31:49 +02:00
|
|
|
/**
|
|
|
|
* testRcptWithReturnPath method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testRcptWithReturnPath() {
|
|
|
|
$email = new CakeEmail();
|
|
|
|
$email->from('noreply@cakephp.org', 'CakePHP Test');
|
|
|
|
$email->to('cake@cakephp.org', 'CakePHP');
|
|
|
|
$email->returnPath('pleasereply@cakephp.org', 'CakePHP Return');
|
|
|
|
|
|
|
|
$this->socket->expects($this->at(0))->method('write')->with("MAIL FROM:<pleasereply@cakephp.org>\r\n");
|
|
|
|
$this->socket->expects($this->at(1))->method('read')->will($this->returnValue(false));
|
|
|
|
$this->socket->expects($this->at(2))->method('read')->will($this->returnValue("250 OK\r\n"));
|
|
|
|
$this->socket->expects($this->at(3))->method('write')->with("RCPT TO:<cake@cakephp.org>\r\n");
|
|
|
|
$this->socket->expects($this->at(4))->method('read')->will($this->returnValue(false));
|
|
|
|
$this->socket->expects($this->at(5))->method('read')->will($this->returnValue("250 OK\r\n"));
|
|
|
|
|
|
|
|
$this->SmtpTransport->setCakeEmail($email);
|
|
|
|
$this->SmtpTransport->sendRcpt();
|
|
|
|
}
|
|
|
|
|
2011-04-04 00:26:42 -04:00
|
|
|
/**
|
|
|
|
* testSendData method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testSendData() {
|
2014-03-01 19:01:36 +01:00
|
|
|
$email = $this->getMock('CakeEmail', array('message'), array(), 'SmtpCakeEmail');
|
2011-04-04 00:26:42 -04:00
|
|
|
$email->from('noreply@cakephp.org', 'CakePHP Test');
|
2011-12-22 23:16:43 -08:00
|
|
|
$email->returnPath('pleasereply@cakephp.org', 'CakePHP Return');
|
2011-04-04 00:26:42 -04:00
|
|
|
$email->to('cake@cakephp.org', 'CakePHP');
|
|
|
|
$email->cc(array('mark@cakephp.org' => 'Mark Story', 'juan@cakephp.org' => 'Juan Basso'));
|
|
|
|
$email->bcc('phpnut@cakephp.org');
|
|
|
|
$email->messageID('<4d9946cf-0a44-4907-88fe-1d0ccbdd56cb@localhost>');
|
|
|
|
$email->subject('Testing SMTP');
|
2012-02-10 19:53:04 +01:00
|
|
|
$date = date(DATE_RFC2822);
|
2012-03-14 15:01:19 +01:00
|
|
|
$email->setHeaders(array('X-Mailer' => SmtpCakeEmail::EMAIL_CLIENT, 'Date' => $date));
|
2014-03-01 19:01:36 +01:00
|
|
|
$email->expects($this->once())->method('message')->will($this->returnValue(array('First Line', 'Second Line', '.Third Line', '')));
|
2011-04-04 00:26:42 -04:00
|
|
|
|
|
|
|
$data = "From: CakePHP Test <noreply@cakephp.org>\r\n";
|
|
|
|
$data .= "To: CakePHP <cake@cakephp.org>\r\n";
|
|
|
|
$data .= "Cc: Mark Story <mark@cakephp.org>, Juan Basso <juan@cakephp.org>\r\n";
|
2011-04-24 01:10:33 -04:00
|
|
|
$data .= "X-Mailer: CakePHP Email\r\n";
|
2012-02-10 19:53:04 +01:00
|
|
|
$data .= "Date: " . $date . "\r\n";
|
2011-04-04 00:26:42 -04:00
|
|
|
$data .= "Message-ID: <4d9946cf-0a44-4907-88fe-1d0ccbdd56cb@localhost>\r\n";
|
|
|
|
$data .= "Subject: Testing SMTP\r\n";
|
2011-04-24 01:10:33 -04:00
|
|
|
$data .= "MIME-Version: 1.0\r\n";
|
2011-04-04 00:26:42 -04:00
|
|
|
$data .= "Content-Type: text/plain; charset=UTF-8\r\n";
|
2011-10-23 00:20:37 +11:00
|
|
|
$data .= "Content-Transfer-Encoding: 8bit\r\n";
|
2011-04-04 00:26:42 -04:00
|
|
|
$data .= "\r\n";
|
|
|
|
$data .= "First Line\r\n";
|
|
|
|
$data .= "Second Line\r\n";
|
2012-05-07 22:34:14 +00:00
|
|
|
$data .= "..Third Line\r\n"; // RFC5321 4.5.2.Transparency
|
2011-04-04 00:26:42 -04:00
|
|
|
$data .= "\r\n";
|
|
|
|
$data .= "\r\n\r\n.\r\n";
|
|
|
|
|
|
|
|
$this->socket->expects($this->at(0))->method('write')->with("DATA\r\n");
|
|
|
|
$this->socket->expects($this->at(1))->method('read')->will($this->returnValue(false));
|
|
|
|
$this->socket->expects($this->at(2))->method('read')->will($this->returnValue("354 OK\r\n"));
|
|
|
|
$this->socket->expects($this->at(3))->method('write')->with($data);
|
|
|
|
$this->socket->expects($this->at(4))->method('read')->will($this->returnValue(false));
|
|
|
|
$this->socket->expects($this->at(5))->method('read')->will($this->returnValue("250 OK\r\n"));
|
|
|
|
|
|
|
|
$this->SmtpTransport->setCakeEmail($email);
|
|
|
|
$this->SmtpTransport->sendData();
|
|
|
|
}
|
|
|
|
|
2011-04-04 00:28:48 -04:00
|
|
|
/**
|
|
|
|
* testQuit method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testQuit() {
|
|
|
|
$this->socket->expects($this->at(0))->method('write')->with("QUIT\r\n");
|
|
|
|
$this->SmtpTransport->disconnect();
|
|
|
|
}
|
|
|
|
|
2013-05-22 11:32:27 +05:30
|
|
|
/**
|
|
|
|
* testEmptyConfigArray method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testEmptyConfigArray() {
|
|
|
|
$expected = $this->SmtpTransport->config(array(
|
|
|
|
'client' => 'myhost.com',
|
|
|
|
'port' => 666
|
|
|
|
));
|
|
|
|
|
|
|
|
$this->assertEquals(666, $expected['port']);
|
|
|
|
|
|
|
|
$result = $this->SmtpTransport->config(array());
|
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
}
|
|
|
|
|
2014-03-13 16:28:54 +01:00
|
|
|
/**
|
|
|
|
* testGetLastResponse method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testGetLastResponse() {
|
|
|
|
$this->assertEmpty($this->SmtpTransport->getLastResponse());
|
|
|
|
|
|
|
|
$this->socket->expects($this->any())->method('connect')->will($this->returnValue(true));
|
|
|
|
$this->socket->expects($this->at(0))->method('read')->will($this->returnValue(false));
|
|
|
|
$this->socket->expects($this->at(1))->method('read')->will($this->returnValue("220 Welcome message\r\n"));
|
|
|
|
$this->socket->expects($this->at(2))->method('write')->with("EHLO localhost\r\n");
|
|
|
|
$this->socket->expects($this->at(3))->method('read')->will($this->returnValue(false));
|
|
|
|
$this->socket->expects($this->at(4))->method('read')->will($this->returnValue("250-PIPELINING\r\n"));
|
|
|
|
$this->socket->expects($this->at(5))->method('read')->will($this->returnValue("250-SIZE 102400000\r\n"));
|
|
|
|
$this->socket->expects($this->at(6))->method('read')->will($this->returnValue("250-VRFY\r\n"));
|
|
|
|
$this->socket->expects($this->at(7))->method('read')->will($this->returnValue("250-ETRN\r\n"));
|
|
|
|
$this->socket->expects($this->at(8))->method('read')->will($this->returnValue("250-STARTTLS\r\n"));
|
|
|
|
$this->socket->expects($this->at(9))->method('read')->will($this->returnValue("250-AUTH PLAIN LOGIN\r\n"));
|
|
|
|
$this->socket->expects($this->at(10))->method('read')->will($this->returnValue("250-AUTH=PLAIN LOGIN\r\n"));
|
|
|
|
$this->socket->expects($this->at(11))->method('read')->will($this->returnValue("250-ENHANCEDSTATUSCODES\r\n"));
|
|
|
|
$this->socket->expects($this->at(12))->method('read')->will($this->returnValue("250-8BITMIME\r\n"));
|
|
|
|
$this->socket->expects($this->at(13))->method('read')->will($this->returnValue("250 DSN\r\n"));
|
|
|
|
$this->SmtpTransport->connect();
|
|
|
|
|
|
|
|
$expected = array(
|
|
|
|
array('code' => '250', 'message' => 'PIPELINING'),
|
|
|
|
array('code' => '250', 'message' => 'SIZE 102400000'),
|
|
|
|
array('code' => '250', 'message' => 'VRFY'),
|
|
|
|
array('code' => '250', 'message' => 'ETRN'),
|
|
|
|
array('code' => '250', 'message' => 'STARTTLS'),
|
|
|
|
array('code' => '250', 'message' => 'AUTH PLAIN LOGIN'),
|
|
|
|
array('code' => '250', 'message' => 'AUTH=PLAIN LOGIN'),
|
|
|
|
array('code' => '250', 'message' => 'ENHANCEDSTATUSCODES'),
|
|
|
|
array('code' => '250', 'message' => '8BITMIME'),
|
|
|
|
array('code' => '250', 'message' => 'DSN')
|
|
|
|
);
|
|
|
|
$result = $this->SmtpTransport->getLastResponse();
|
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
|
|
|
|
$email = new CakeEmail();
|
|
|
|
$email->from('noreply@cakephp.org', 'CakePHP Test');
|
|
|
|
$email->to('cake@cakephp.org', 'CakePHP');
|
|
|
|
|
|
|
|
$this->socket->expects($this->at(0))->method('write')->with("MAIL FROM:<noreply@cakephp.org>\r\n");
|
|
|
|
$this->socket->expects($this->at(1))->method('read')->will($this->returnValue(false));
|
|
|
|
$this->socket->expects($this->at(2))->method('read')->will($this->returnValue("250 OK\r\n"));
|
|
|
|
$this->socket->expects($this->at(3))->method('write')->with("RCPT TO:<cake@cakephp.org>\r\n");
|
|
|
|
$this->socket->expects($this->at(4))->method('read')->will($this->returnValue(false));
|
|
|
|
$this->socket->expects($this->at(5))->method('read')->will($this->returnValue("250 OK\r\n"));
|
|
|
|
|
|
|
|
$this->SmtpTransport->setCakeEmail($email);
|
|
|
|
$this->SmtpTransport->sendRcpt();
|
|
|
|
|
|
|
|
$expected = array(
|
|
|
|
array('code' => '250', 'message' => 'OK'),
|
|
|
|
);
|
|
|
|
$result = $this->SmtpTransport->getLastResponse();
|
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* testBufferResponseLines method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testBufferResponseLines() {
|
|
|
|
$reponseLines = array(
|
|
|
|
'123',
|
|
|
|
'FOOBAR',
|
|
|
|
'250-PIPELINING',
|
|
|
|
'250-ENHANCEDSTATUSCODES',
|
|
|
|
'250-8BITMIME',
|
|
|
|
'250 DSN',
|
|
|
|
);
|
|
|
|
$this->SmtpTransport->bufferResponseLines($reponseLines);
|
|
|
|
|
|
|
|
$expected = array(
|
|
|
|
array('code' => '123', 'message' => null),
|
|
|
|
array('code' => '250', 'message' => 'PIPELINING'),
|
|
|
|
array('code' => '250', 'message' => 'ENHANCEDSTATUSCODES'),
|
|
|
|
array('code' => '250', 'message' => '8BITMIME'),
|
|
|
|
array('code' => '250', 'message' => 'DSN')
|
|
|
|
);
|
|
|
|
$result = $this->SmtpTransport->getLastResponse();
|
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
}
|
2011-11-03 21:16:29 -04:00
|
|
|
}
|