From 303261e23199efb3647feb622d5ed9e125dbd4cf Mon Sep 17 00:00:00 2001 From: fuga Date: Mon, 12 Aug 2013 10:28:17 +0900 Subject: [PATCH 1/2] making the config method of email-transport-classes mergable into the current config value. --- lib/Cake/Network/Email/AbstractTransport.php | 2 +- lib/Cake/Network/Email/SmtpTransport.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Cake/Network/Email/AbstractTransport.php b/lib/Cake/Network/Email/AbstractTransport.php index b081c0f4b..3f285a1d9 100644 --- a/lib/Cake/Network/Email/AbstractTransport.php +++ b/lib/Cake/Network/Email/AbstractTransport.php @@ -48,7 +48,7 @@ abstract class AbstractTransport { */ public function config($config = null) { if (is_array($config)) { - $this->_config = $config; + $this->_config = $config + $this->_config; } return $this->_config; } diff --git a/lib/Cake/Network/Email/SmtpTransport.php b/lib/Cake/Network/Email/SmtpTransport.php index 971a5cefd..e0b07156b 100644 --- a/lib/Cake/Network/Email/SmtpTransport.php +++ b/lib/Cake/Network/Email/SmtpTransport.php @@ -86,7 +86,7 @@ class SmtpTransport extends AbstractTransport { 'client' => null, 'tls' => false ); - $this->_config = empty($config) ? $this->_config + $default : $config + $default; + $this->_config = array_merge($default, $this->_config, $config); return $this->_config; } From 245611424fd39e727ec3e53d7fedf60187755533 Mon Sep 17 00:00:00 2001 From: fuga Date: Tue, 13 Aug 2013 17:42:52 +0900 Subject: [PATCH 2/2] Apply ADmad's patch and update testConfig method according to a new specification. --- .../Test/Case/Network/Email/CakeEmailTest.php | 46 ++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/lib/Cake/Test/Case/Network/Email/CakeEmailTest.php b/lib/Cake/Test/Case/Network/Email/CakeEmailTest.php index e9527280c..48ee47569 100644 --- a/lib/Cake/Test/Case/Network/Email/CakeEmailTest.php +++ b/lib/Cake/Test/Case/Network/Email/CakeEmailTest.php @@ -95,6 +95,20 @@ class EmailConfig { 'helpers' => array('Html', 'Form'), ); +/** + * test config 2 + * + * @var string + */ + public $test2 = array( + 'from' => array('some@example.com' => 'My website'), + 'to' => array('test@example.com' => 'Testname'), + 'subject' => 'Test mail subject', + 'transport' => 'Smtp', + 'host' => 'cakephp.org', + 'timeout' => 60 + ); + } /* @@ -726,12 +740,13 @@ class CakeEmailTest extends CakeTestCase { $this->assertSame($this->CakeEmail->config(), $config); $this->CakeEmail->config(array()); - $this->assertSame($transportClass->config(), array()); + $this->assertSame($transportClass->config(), $config); $config = array('test' => 'test@example.com'); $this->CakeEmail->config($config); $expected = array('test' => 'test@example.com', 'test2' => true); $this->assertSame($expected, $this->CakeEmail->config()); + $this->assertSame($expected, $transportClass->config()); } /** @@ -765,6 +780,35 @@ class CakeEmailTest extends CakeTestCase { $this->assertEquals($configs->test['helpers'], $result); } +/** + * Test updating config doesn't reset transport's config. + * + * @return void + */ + public function testConfigMerge() { + $this->CakeEmail->config('test2'); + + $expected = array( + 'host' => 'cakephp.org', + 'port' => 25, + 'timeout' => 60, + 'username' => null, + 'password' => null, + 'client' => null, + 'tls' => false + ); + $this->assertEquals($expected, $this->CakeEmail->transportClass()->config()); + + $this->CakeEmail->config(array('log' => true)); + $result = $this->CakeEmail->transportClass()->config(); + $expected += array('log' => true); + $this->assertEquals($expected, $this->CakeEmail->transportClass()->config()); + + $this->CakeEmail->config(array('timeout' => 45)); + $result = $this->CakeEmail->transportClass()->config(); + $this->assertEquals(45, $result['timeout']); + } + /** * testSendWithContent method *