Skip to content

Commit

Permalink
Ajusting smtpOption in EmailComponent. Fixes #779
Browse files Browse the repository at this point in the history
  • Loading branch information
jrbasso committed Jun 3, 2010
1 parent b480d80 commit 3c27c4c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
3 changes: 2 additions & 1 deletion cake/libs/controller/components/email.php
Expand Up @@ -793,7 +793,8 @@ function _smtp() {
'protocol' => 'smtp',
'timeout' => 30
);
$this->__smtpConnection =& new CakeSocket(array_merge($defaults, $this->smtpOptions));
$this->smtpOptions = array_merge($defaults, $this->smtpOptions);
$this->__smtpConnection =& new CakeSocket($this->smtpOptions);

if (!$this->__smtpConnection->connect()) {
$this->smtpError = $this->__smtpConnection->lastError();
Expand Down
26 changes: 26 additions & 0 deletions cake/tests/cases/libs/controller/components/email.test.php
Expand Up @@ -234,6 +234,30 @@ function __osFix($string) {
return str_replace(array("\r\n", "\r"), "\n", $string);
}

/**
* testSmtpConfig method
*
* @access public
* @return void
*/
function testSmtpConfig() {
$this->Controller->EmailTest->delivery = 'smtp';
$this->Controller->EmailTest->smtpOptions = array();
$this->Controller->EmailTest->send('anything');
$config = array(
'host' => 'localhost',
'port' => 25,
'protocol' => 'smtp',
'timeout' => 30
);
$this->assertEqual($config, $this->Controller->EmailTest->smtpOptions);

$this->Controller->EmailTest->smtpOptions = array('port' => 80);
$this->Controller->EmailTest->send('anything');
$config['port'] = 80;
$this->assertEqual($config, $this->Controller->EmailTest->smtpOptions);
}

/**
* testBadSmtpSend method
*
Expand Down Expand Up @@ -308,6 +332,7 @@ function testSmtpEhlo() {

$connection =& new CakeSocket(array('protocol'=>'smtp', 'host' => 'localhost', 'port' => 25));
$this->Controller->EmailTest->setConnectionSocket($connection);
$this->Controller->EmailTest->smtpOptions['timeout'] = 10;
$this->assertTrue($connection->connect());
$this->assertTrue($this->Controller->EmailTest->smtpSend(null, '220') !== false);
$this->skipIf($this->Controller->EmailTest->smtpSend('EHLO locahost', '250') === false, '%s do not support EHLO.');
Expand Down Expand Up @@ -600,6 +625,7 @@ function testTemplates() {
function testSmtpSendSocket() {
$this->skipIf(!@fsockopen('localhost', 25), '%s No SMTP server running on localhost');

$this->Controller->EmailTest->smtpOptions['timeout'] = 10;
$socket =& new CakeSocket(array_merge(array('protocol'=>'smtp'), $this->Controller->EmailTest->smtpOptions));
$this->Controller->EmailTest->setConnectionSocket($socket);

Expand Down

0 comments on commit 3c27c4c

Please sign in to comment.