Skip to content
Permalink
Browse files

Finish reverting useConfig() changes.

Complete transition to using Configure for configuration.
  • Loading branch information...
markstory committed Sep 2, 2012
1 parent da4b48b commit 61fb794f66145dd5d1fd1639b44f9cb44b63661c
Showing with 32 additions and 52 deletions.
  1. +3 −3 App/Config/email.php.default
  2. +7 −27 lib/Cake/Network/Email/Email.php
  3. +22 −22 lib/Cake/Test/TestCase/Network/Email/EmailTest.php
@@ -14,7 +14,7 @@
*/
namespace App\Config;

use Cake\Network\Email\Email;
use Cake\Core\Configure;
/**
* Email configuration.
*
@@ -33,14 +33,14 @@ use Cake\Network\Email\Email;
* from =>
* The origin email. See Cake\Network\Email\Email::from() about the valid values
*/
Email::config('default', [
Configure::write('Email.default', [
'transport' => 'Mail',
'from' => 'you@localhost',
//'charset' => 'utf-8',
//'headerCharset' => 'utf-8',
]);

Email::config('smtp', [
Configure::write('Email.smtp', [
'transport' => 'Smtp',
'host' => 'localhost',
'port' => 25,
@@ -298,14 +298,6 @@ class Email {
*/
protected $_config = array();
/**
* An array of preconfigured Email types.
*
* @var array
* @see Email::config()
*/
protected static $_preConfig = array();
/**
* 8Bit character sets
*
@@ -338,7 +330,7 @@ public function __construct($config = null) {
}
if ($config) {
$this->useConfig($config);
$this->config($config);
}
if (empty($this->headerCharset)) {
$this->headerCharset = $this->charset;
@@ -1025,19 +1017,6 @@ public function message($type = null) {
return $this->_message;
}
/**
* Set configuration to use when sending email later.
* Typically this is used during bootstrapping to configure
* presets for email.
*
* @param string $name The name of the config you want set.
* @param array $config Array of configuration data.
* @return void
*/
public static function config($name, array $config) {
static::$_preConfig[$name] = $config;
}
/**
* Sets the configuration for this Email instance.
*
@@ -1049,7 +1028,7 @@ public static function config($name, array $config) {
* an array with config or null to return current config.
* @return string|array|Cake\Network\Email\Email
*/
public function useConfig($config = null) {
public function config($config = null) {
if ($config === null) {
return $this->_config;
}
@@ -1117,7 +1096,7 @@ public static function deliver($to = null, $subject = null, $message = null, $tr
if (is_array($message)) {
$instance->viewVars($message);
$message = null;
} elseif ($message === null && array_key_exists('message', $config = $instance->useConfig())) {
} elseif ($message === null && array_key_exists('message', $config = $instance->config())) {
$message = $config['message'];
}
@@ -1138,10 +1117,11 @@ public static function deliver($to = null, $subject = null, $message = null, $tr
*/
protected function _applyConfig($config) {
if (is_string($config)) {
if (!isset(static::$_preConfig[$config])) {
throw new Error\ConfigureException(__d('cake_dev', 'Unknown email configuration "%s".', $config));
$name = $config;
$config = Configure::read('Email.' . $name);
if (empty($config)) {
throw new Error\ConfigureException(__d('cake_dev', 'Unknown email configuration "%s".', $name));
}
$config = static::$_preConfig[$config];
}
$this->_config += $config;
if (!empty($config['charset'])) {
@@ -705,11 +705,11 @@ public function testUseConfig() {
$transportClass = $this->CakeEmail->transport('debug')->transportClass();
$config = array('test' => 'ok', 'test2' => true);
$this->CakeEmail->useConfig($config);
$this->CakeEmail->config($config);
$this->assertSame($transportClass->config(), $config);
$this->assertSame($this->CakeEmail->useConfig(), $config);
$this->assertSame($this->CakeEmail->config(), $config);
$this->CakeEmail->useConfig(array());
$this->CakeEmail->config(array());
$this->assertSame($transportClass->config(), array());
}
@@ -727,9 +727,9 @@ public function testConfigString() {
'theme' => 'TestTheme',
'helpers' => array('Html', 'Form'),
];
Email::config('test', $config);
Configure::write('Email.test', $config);
$this->CakeEmail->useConfig('test');
$this->CakeEmail->config('test');
$result = $this->CakeEmail->to();
$this->assertEquals($config['to'], $result);
@@ -764,7 +764,7 @@ public function testSendWithContent() {
$this->CakeEmail->from('cake@cakephp.org');
$this->CakeEmail->to(array('you@cakephp.org' => 'You'));
$this->CakeEmail->subject('My title');
$this->CakeEmail->useConfig(array('empty'));
$this->CakeEmail->config(array('empty'));
$result = $this->CakeEmail->send("Here is my body, with multi lines.\nThis is the second line.\r\n\r\nAnd the last.");
$expected = array('headers', 'message');
@@ -787,7 +787,7 @@ public function testSendWithContent() {
$this->CakeEmail->from('cake@cakephp.org');
$this->CakeEmail->to(array('you@cakephp.org' => 'You'));
$this->CakeEmail->subject('My title');
$this->CakeEmail->useConfig(array('empty'));
$this->CakeEmail->config(array('empty'));
$result = $this->CakeEmail->send(array('Sending content', 'As array'));
$expected = "Sending content\r\nAs array\r\n\r\n\r\n";
$this->assertSame($result['message'], $expected);
@@ -802,7 +802,7 @@ public function testSendWithoutFrom() {
$this->CakeEmail->transport('Debug');
$this->CakeEmail->to('cake@cakephp.org');
$this->CakeEmail->subject('My title');
$this->CakeEmail->useConfig(array('empty'));
$this->CakeEmail->config(array('empty'));
$this->setExpectedException('Cake\Error\SocketException');
$this->CakeEmail->send("Forgot to set From");
}
@@ -816,7 +816,7 @@ public function testSendWithoutTo() {
$this->CakeEmail->transport('Debug');
$this->CakeEmail->from('cake@cakephp.org');
$this->CakeEmail->subject('My title');
$this->CakeEmail->useConfig(array('empty'));
$this->CakeEmail->config(array('empty'));
$this->setExpectedException('Cake\Error\SocketException');
$this->CakeEmail->send("Forgot to set To");
}
@@ -1004,7 +1004,7 @@ public function testSendWithLog() {
$this->CakeEmail->to('me@cakephp.org');
$this->CakeEmail->from('cake@cakephp.org');
$this->CakeEmail->subject('My title');
$this->CakeEmail->useConfig(array('log' => 'cake_test_emails'));
$this->CakeEmail->config(array('log' => 'cake_test_emails'));
$result = $this->CakeEmail->send("Logging This");
$File = new File(TMP . 'cake_test_emails.log');
@@ -1027,7 +1027,7 @@ public function testSendRender() {
$this->CakeEmail->from('cake@cakephp.org');
$this->CakeEmail->to(array('you@cakephp.org' => 'You'));
$this->CakeEmail->subject('My title');
$this->CakeEmail->useConfig(array('empty'));
$this->CakeEmail->config(array('empty'));
$this->CakeEmail->template('default', 'default');
$result = $this->CakeEmail->send();
@@ -1050,7 +1050,7 @@ public function testSendRenderJapanese() {
$this->CakeEmail->from('cake@cakephp.org');
$this->CakeEmail->to(array('you@cakephp.org' => 'You'));
$this->CakeEmail->subject('My title');
$this->CakeEmail->useConfig(array('empty'));
$this->CakeEmail->config(array('empty'));
$this->CakeEmail->template('default', 'japanese');
$this->CakeEmail->charset = 'ISO-2022-JP';
$result = $this->CakeEmail->send();
@@ -1073,7 +1073,7 @@ public function testSendRenderThemed() {
$this->CakeEmail->from('cake@cakephp.org');
$this->CakeEmail->to(array('you@cakephp.org' => 'You'));
$this->CakeEmail->subject('My title');
$this->CakeEmail->useConfig(array('empty'));
$this->CakeEmail->config(array('empty'));
$this->CakeEmail->theme('TestTheme');
$this->CakeEmail->template('themed', 'default');
$result = $this->CakeEmail->send();
@@ -1095,7 +1095,7 @@ public function testSendRenderWithVars() {
$this->CakeEmail->from('cake@cakephp.org');
$this->CakeEmail->to(array('you@cakephp.org' => 'You'));
$this->CakeEmail->subject('My title');
$this->CakeEmail->useConfig(array('empty'));
$this->CakeEmail->config(array('empty'));
$this->CakeEmail->template('custom', 'default');
$this->CakeEmail->viewVars(array('value' => 12345));
$result = $this->CakeEmail->send();
@@ -1116,7 +1116,7 @@ public function testSendRenderWithVarsJapanese() {
$this->CakeEmail->from('cake@cakephp.org');
$this->CakeEmail->to(array('you@cakephp.org' => 'You'));
$this->CakeEmail->subject('My title');
$this->CakeEmail->useConfig(array('empty'));
$this->CakeEmail->config(array('empty'));
$this->CakeEmail->template('japanese', 'default');
$this->CakeEmail->viewVars(array('value' => '日本語の差し込み123'));
$this->CakeEmail->charset = 'ISO-2022-JP';
@@ -1139,7 +1139,7 @@ public function testSendRenderWithHelpers() {
$this->CakeEmail->from('cake@cakephp.org');
$this->CakeEmail->to(array('you@cakephp.org' => 'You'));
$this->CakeEmail->subject('My title');
$this->CakeEmail->useConfig(array('empty'));
$this->CakeEmail->config(array('empty'));
$this->CakeEmail->template('custom_helper', 'default');
$this->CakeEmail->viewVars(array('time' => $timestamp));
@@ -1165,7 +1165,7 @@ public function testSendRenderWithImage() {
$this->CakeEmail->from('cake@cakephp.org');
$this->CakeEmail->to(array('you@cakephp.org' => 'You'));
$this->CakeEmail->subject('My title');
$this->CakeEmail->useConfig(array('empty'));
$this->CakeEmail->config(array('empty'));
$this->CakeEmail->template('image');
$this->CakeEmail->emailFormat('html');
$server = env('SERVER_NAME') ? env('SERVER_NAME') : 'localhost';
@@ -1195,7 +1195,7 @@ public function testSendRenderPlugin() {
$this->CakeEmail->from('cake@cakephp.org');
$this->CakeEmail->to(array('you@cakephp.org' => 'You'));
$this->CakeEmail->subject('My title');
$this->CakeEmail->useConfig(array('empty'));
$this->CakeEmail->config(array('empty'));
$result = $this->CakeEmail->template('TestPlugin.test_plugin_tpl', 'default')->send();
$this->assertContains('Into TestPlugin.', $result['message']);
@@ -1237,7 +1237,7 @@ public function testSendMultipleMIME() {
$this->CakeEmail->to(array('you@cakephp.org' => 'You'));
$this->CakeEmail->subject('My title');
$this->CakeEmail->template('custom', 'default');
$this->CakeEmail->useConfig(array());
$this->CakeEmail->config(array());
$this->CakeEmail->viewVars(array('value' => 12345));
$this->CakeEmail->emailFormat('both');
$result = $this->CakeEmail->send();
@@ -1273,7 +1273,7 @@ public function testSendAttachment() {
$this->CakeEmail->from('cake@cakephp.org');
$this->CakeEmail->to(array('you@cakephp.org' => 'You'));
$this->CakeEmail->subject('My title');
$this->CakeEmail->useConfig(array());
$this->CakeEmail->config(array());
$this->CakeEmail->attachments(array(CAKE . 'basics.php'));
$result = $this->CakeEmail->send('body');
$this->assertContains("Content-Type: application/octet-stream\r\nContent-Transfer-Encoding: base64\r\nContent-Disposition: attachment; filename=\"basics.php\"", $result['message']);
@@ -1337,7 +1337,7 @@ public function testMessage() {
$this->CakeEmail->from('cake@cakephp.org');
$this->CakeEmail->to(array('you@cakephp.org' => 'You'));
$this->CakeEmail->subject('My title');
$this->CakeEmail->useConfig(array('empty'));
$this->CakeEmail->config(array('empty'));
$this->CakeEmail->template('default', 'default');
$this->CakeEmail->emailFormat('both');
$result = $this->CakeEmail->send();
@@ -1506,7 +1506,7 @@ public function testConstructWithConfigString() {
'subject' => 'Test mail subject',
'transport' => 'Debug',
);
Email::config('test', $configs);
Configure::write('Email.test', $configs);
$this->CakeEmail = new Email('test');

0 comments on commit 61fb794

Please sign in to comment.
You can’t perform that action at this time.