Merge pull request #1508 from fuga/feature/email-config

making the config method of email-transport-classes mergable
This commit is contained in:
Mark Story 2013-08-15 08:26:11 -07:00
commit 7c29aa5155
3 changed files with 47 additions and 3 deletions

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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
*