From eccdf3bf6037b65586d9f5e868a1c772fd4010df Mon Sep 17 00:00:00 2001 From: ADmad Date: Wed, 22 May 2013 11:32:27 +0530 Subject: [PATCH] Ensure passing empty array to SmtpTransport::config() does not reset existing config. Synced args and return value with AbstractTransport::config(). Fixes #3840 --- lib/Cake/Network/Email/SmtpTransport.php | 10 +++++++--- .../Case/Network/Email/SmtpTransportTest.php | 17 +++++++++++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/lib/Cake/Network/Email/SmtpTransport.php b/lib/Cake/Network/Email/SmtpTransport.php index a003e467c79..22ba6568ba5 100644 --- a/lib/Cake/Network/Email/SmtpTransport.php +++ b/lib/Cake/Network/Email/SmtpTransport.php @@ -71,9 +71,12 @@ public function send(CakeEmail $email) { * Set the configuration * * @param array $config - * @return void + * @return array Returns configs */ - public function config($config = array()) { + public function config($config = null) { + if ($config === null) { + return $this->_config; + } $default = array( 'host' => 'localhost', 'port' => 25, @@ -83,7 +86,8 @@ public function config($config = array()) { 'client' => null, 'tls' => false ); - $this->_config = $config + $default; + $this->_config = empty($config) ? $this->_config + $default : $config + $default; + return $this->_config; } /** diff --git a/lib/Cake/Test/Case/Network/Email/SmtpTransportTest.php b/lib/Cake/Test/Case/Network/Email/SmtpTransportTest.php index 625fcdcbea6..e97bb0ce231 100644 --- a/lib/Cake/Test/Case/Network/Email/SmtpTransportTest.php +++ b/lib/Cake/Test/Case/Network/Email/SmtpTransportTest.php @@ -327,4 +327,21 @@ public function testQuit() { $this->SmtpTransport->disconnect(); } +/** + * 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); + } + }