mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Implemented methods to configure "to".
This commit is contained in:
parent
5cb58e8f99
commit
fae641e619
2 changed files with 131 additions and 0 deletions
|
@ -223,6 +223,93 @@ class CakeEmail {
|
|||
return $this->_from;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set To
|
||||
*
|
||||
* @param mixed $email String with email, Array with email as key, name as value or email as value (without name)
|
||||
* @param string $name
|
||||
* @return void
|
||||
*/
|
||||
public function setTo($email, $name = null) {
|
||||
$this->_setEmail('_to', $email, $name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add To
|
||||
*
|
||||
* @param mixed $email String with email, Array with email as key, name as value or email as value (without name)
|
||||
* @param string $name
|
||||
* @return void
|
||||
*/
|
||||
public function addTo($email, $name = null) {
|
||||
$this->_addEmail('_to', $email, $name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get To
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getTo() {
|
||||
return $this->_to;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set email
|
||||
*
|
||||
* @param string $varName
|
||||
* @param mixed $email
|
||||
* @param mixed $name
|
||||
* @return void
|
||||
*/
|
||||
protected function _setEmail($varName, $email, $name) {
|
||||
if (!is_array($email)) {
|
||||
if ($name === null) {
|
||||
$this->{$varName} = array($email => $email);
|
||||
} else {
|
||||
$this->{$varName} = array($email => $name);
|
||||
}
|
||||
return;
|
||||
}
|
||||
$list = array();
|
||||
foreach ($email as $key => $value) {
|
||||
if (is_int($key)) {
|
||||
$list[$value] = $value;
|
||||
} else {
|
||||
$list[$key] = $value;
|
||||
}
|
||||
}
|
||||
$this->{$varName} = $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add email
|
||||
*
|
||||
* @param string $varName
|
||||
* @param mixed $email
|
||||
* @param mixed $name
|
||||
* @return void
|
||||
*/
|
||||
protected function _addEmail($varName, $email, $name) {
|
||||
if (!is_array($email)) {
|
||||
if ($name === null) {
|
||||
$this->{$varName}[$email] = $email;
|
||||
} else {
|
||||
$this->{$varName}[$email] = $name;
|
||||
}
|
||||
return;
|
||||
}
|
||||
$list = array();
|
||||
foreach ($email as $key => $value) {
|
||||
if (is_int($key)) {
|
||||
$list[$value] = $value;
|
||||
} else {
|
||||
$list[$key] = $value;
|
||||
}
|
||||
}
|
||||
$this->{$varName} = array_merge($this->{$varName}, $list);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets headers for the message
|
||||
*
|
||||
|
|
|
@ -52,6 +52,50 @@ class CakeEmailTest extends CakeTestCase {
|
|||
$this->assertIdentical($this->CakeEmail->getFrom(), $expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* testTo method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testTo() {
|
||||
$this->assertIdentical($this->CakeEmail->getTo(), array());
|
||||
|
||||
$this->CakeEmail->setTo('cake@cakephp.org');
|
||||
$expected = array('cake@cakephp.org' => 'cake@cakephp.org');
|
||||
$this->assertIdentical($this->CakeEmail->getTo(), $expected);
|
||||
|
||||
$this->CakeEmail->setTo('cake@cakephp.org', 'CakePHP');
|
||||
$expected = array('cake@cakephp.org' => 'CakePHP');
|
||||
$this->assertIdentical($this->CakeEmail->getTo(), $expected);
|
||||
|
||||
$list = array(
|
||||
'cake@cakephp.org' => 'Cake PHP',
|
||||
'cake-php@googlegroups.com' => 'Cake Groups',
|
||||
'root@cakephp.org'
|
||||
);
|
||||
$this->CakeEmail->setTo($list);
|
||||
$expected = array(
|
||||
'cake@cakephp.org' => 'Cake PHP',
|
||||
'cake-php@googlegroups.com' => 'Cake Groups',
|
||||
'root@cakephp.org' => 'root@cakephp.org'
|
||||
);
|
||||
$this->assertIdentical($this->CakeEmail->getTo(), $expected);
|
||||
|
||||
$this->CakeEmail->addTo('jrbasso@cakephp.org');
|
||||
$this->CakeEmail->addTo('mark_story@cakephp.org', 'Mark Story');
|
||||
$this->CakeEmail->addTo(array('phpnut@cakephp.org' => 'PhpNut', 'jose_zap@cakephp.org'));
|
||||
$expected = array(
|
||||
'cake@cakephp.org' => 'Cake PHP',
|
||||
'cake-php@googlegroups.com' => 'Cake Groups',
|
||||
'root@cakephp.org' => 'root@cakephp.org',
|
||||
'jrbasso@cakephp.org' => 'jrbasso@cakephp.org',
|
||||
'mark_story@cakephp.org' => 'Mark Story',
|
||||
'phpnut@cakephp.org' => 'PhpNut',
|
||||
'jose_zap@cakephp.org' => 'jose_zap@cakephp.org'
|
||||
);
|
||||
$this->assertIdentical($this->CakeEmail->getTo(), $expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* testHeaders method
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue