2011-02-27 18:25:23 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* CakeEmailTest file
|
|
|
|
*
|
|
|
|
* PHP 5
|
|
|
|
*
|
|
|
|
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
|
|
|
|
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
|
|
|
*
|
|
|
|
* Licensed under The MIT License
|
|
|
|
* Redistributions of files must retain the above copyright notice
|
|
|
|
*
|
|
|
|
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
|
|
|
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
|
|
|
|
* @package cake.tests.cases.libs
|
|
|
|
* @since CakePHP(tm) v 2.0.0
|
|
|
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
|
|
|
*/
|
|
|
|
App::import('Core', 'CakeEmail');
|
|
|
|
|
2011-03-01 22:30:01 +00:00
|
|
|
/**
|
|
|
|
* Help to test CakeEmail
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
class TestCakeEmail extends CakeEmail {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Wrap to protected method
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public function formatAddress($address) {
|
|
|
|
return $this->_formatAddress($address);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-02-27 18:25:23 +00:00
|
|
|
/**
|
|
|
|
* CakeEmailTest class
|
|
|
|
*
|
|
|
|
* @package cake.tests.cases.libs
|
|
|
|
*/
|
|
|
|
class CakeEmailTest extends CakeTestCase {
|
|
|
|
|
2011-03-01 04:31:30 +00:00
|
|
|
/**
|
|
|
|
* setUp
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function setUp() {
|
|
|
|
parent::setUp();
|
2011-03-01 22:30:01 +00:00
|
|
|
$this->CakeEmail = new TestCakeEmail();
|
2011-03-01 04:31:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* testFrom method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testFrom() {
|
|
|
|
$this->assertIdentical($this->CakeEmail->getFrom(), array());
|
|
|
|
|
|
|
|
$this->CakeEmail->setFrom('cake@cakephp.org');
|
|
|
|
$expected = array('cake@cakephp.org' => 'cake@cakephp.org');
|
|
|
|
$this->assertIdentical($this->CakeEmail->getFrom(), $expected);
|
|
|
|
|
2011-03-01 16:50:54 +00:00
|
|
|
$this->CakeEmail->setFrom(array('cake@cakephp.org'));
|
|
|
|
$this->assertIdentical($this->CakeEmail->getFrom(), $expected);
|
|
|
|
|
2011-03-01 04:31:30 +00:00
|
|
|
$this->CakeEmail->setFrom('cake@cakephp.org', 'CakePHP');
|
|
|
|
$expected = array('cake@cakephp.org' => 'CakePHP');
|
|
|
|
$this->assertIdentical($this->CakeEmail->getFrom(), $expected);
|
2011-03-01 16:50:54 +00:00
|
|
|
|
|
|
|
$this->CakeEmail->setFrom(array('cake@cakephp.org' => 'CakePHP'));
|
|
|
|
$this->assertIdentical($this->CakeEmail->getFrom(), $expected);
|
2011-03-01 04:31:30 +00:00
|
|
|
}
|
|
|
|
|
2011-03-01 05:09:05 +00:00
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
}
|
|
|
|
|
2011-03-01 22:30:01 +00:00
|
|
|
/**
|
|
|
|
* testFormatAddress method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testFormatAddress() {
|
|
|
|
$result = $this->CakeEmail->formatAddress(array('cake@cakephp.org' => 'cake@cakephp.org'));
|
|
|
|
$expected = array('cake@cakephp.org');
|
|
|
|
$this->assertIdentical($result, $expected);
|
|
|
|
|
|
|
|
$result = $this->CakeEmail->formatAddress(array('cake@cakephp.org' => 'cake@cakephp.org', 'php@cakephp.org' => 'php@cakephp.org'));
|
|
|
|
$expected = array('cake@cakephp.org', 'php@cakephp.org');
|
|
|
|
$this->assertIdentical($result, $expected);
|
|
|
|
|
|
|
|
$result = $this->CakeEmail->formatAddress(array('cake@cakephp.org' => 'CakePHP', 'php@cakephp.org' => 'Cake'));
|
|
|
|
$expected = array('CakePHP <cake@cakephp.org>', 'Cake <php@cakephp.org>');
|
|
|
|
$this->assertIdentical($result, $expected);
|
|
|
|
|
|
|
|
$result = $this->CakeEmail->formatAddress(array('cake@cakephp.org' => 'ÄÖÜTest'));
|
|
|
|
$expected = array('=?UTF-8?B?w4TDlsOcVGVzdA==?= <cake@cakephp.org>');
|
|
|
|
$this->assertIdentical($result, $expected);
|
|
|
|
}
|
|
|
|
|
2011-03-01 17:20:13 +00:00
|
|
|
/**
|
|
|
|
* testSubject method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testSubject() {
|
|
|
|
$this->CakeEmail->setSubject('You have a new message.');
|
|
|
|
$this->assertIdentical($this->CakeEmail->getSubject(), 'You have a new message.');
|
|
|
|
|
|
|
|
$this->CakeEmail->setSubject(1);
|
|
|
|
$this->assertIdentical($this->CakeEmail->getSubject(), '1');
|
|
|
|
|
|
|
|
$this->CakeEmail->setSubject(array('something'));
|
|
|
|
$this->assertIdentical($this->CakeEmail->getSubject(), 'Array');
|
|
|
|
}
|
|
|
|
|
2011-02-27 18:25:23 +00:00
|
|
|
/**
|
2011-03-01 04:19:47 +00:00
|
|
|
* testHeaders method
|
2011-02-27 18:25:23 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-03-01 04:19:47 +00:00
|
|
|
public function testHeaders() {
|
2011-03-01 18:16:50 +00:00
|
|
|
$this->CakeEmail->setHeaders(array('X-Something' => 'nice'));
|
|
|
|
$expected = array(
|
|
|
|
'X-Something' => 'nice',
|
|
|
|
'X-Mailer' => 'CakePHP Email Component',
|
|
|
|
'Date' => date(DATE_RFC2822)
|
|
|
|
);
|
|
|
|
$this->assertIdentical($this->CakeEmail->getHeaders(), $expected);
|
|
|
|
|
|
|
|
$this->CakeEmail->addHeaders(array('X-Something' => 'very nice', 'X-Other' => 'cool'));
|
|
|
|
$expected = array(
|
|
|
|
'X-Something' => 'very nice',
|
|
|
|
'X-Other' => 'cool',
|
|
|
|
'X-Mailer' => 'CakePHP Email Component',
|
|
|
|
'Date' => date(DATE_RFC2822)
|
|
|
|
);
|
|
|
|
$this->assertIdentical($this->CakeEmail->getHeaders(), $expected);
|
|
|
|
|
|
|
|
$this->CakeEmail->setFrom('cake@cakephp.org');
|
|
|
|
$this->assertIdentical($this->CakeEmail->getHeaders(), $expected);
|
|
|
|
|
|
|
|
$expected['From'] = 'cake@cakephp.org';
|
|
|
|
$this->assertIdentical($this->CakeEmail->getHeaders(array('from' => true)), $expected);
|
|
|
|
|
|
|
|
$this->CakeEmail->setFrom('cake@cakephp.org', 'CakePHP');
|
|
|
|
$expected['From'] = 'CakePHP <cake@cakephp.org>';
|
|
|
|
$this->assertIdentical($this->CakeEmail->getHeaders(array('from' => true)), $expected);
|
|
|
|
|
|
|
|
$this->CakeEmail->setTo(array('cake@cakephp.org', 'php@cakephp.org' => 'CakePHP'));
|
|
|
|
$expected['To'] = 'cake@cakephp.org, CakePHP <php@cakephp.org>';
|
|
|
|
$this->assertIdentical($this->CakeEmail->getHeaders(array('from' => true, 'to' => true)), $expected);
|
2011-02-27 18:25:23 +00:00
|
|
|
}
|
|
|
|
|
2011-03-01 21:51:12 +00:00
|
|
|
/**
|
|
|
|
* testAttachments
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testAttachments() {
|
|
|
|
$this->CakeEmail->setAttachments(WWW_ROOT . 'index.php');
|
|
|
|
$expected = array(WWW_ROOT . 'index.php');
|
|
|
|
$this->assertIdentical($this->CakeEmail->getAttachments(), $expected);
|
|
|
|
|
|
|
|
$this->CakeEmail->setAttachments(array());
|
|
|
|
$this->assertIdentical($this->CakeEmail->getAttachments(), array());
|
|
|
|
|
|
|
|
$this->CakeEmail->setAttachments(WWW_ROOT . 'index.php');
|
|
|
|
$this->CakeEmail->addAttachments(WWW_ROOT . 'test.php');
|
|
|
|
$this->CakeEmail->addAttachments(array(WWW_ROOT . 'test.php', WWW_ROOT . '.htaccess'));
|
|
|
|
$expected = array(WWW_ROOT . 'index.php', WWW_ROOT . 'test.php', WWW_ROOT . '.htaccess');
|
|
|
|
$this->assertIdentical(array_values($this->CakeEmail->getAttachments()), $expected);
|
|
|
|
}
|
|
|
|
|
2011-02-27 18:25:23 +00:00
|
|
|
/**
|
|
|
|
* testSend method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testSend() {
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* testReset method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testReset() {
|
2011-03-01 17:25:25 +00:00
|
|
|
$this->CakeEmail->setTo('cake@cakephp.org');
|
|
|
|
$this->assertIdentical($this->CakeEmail->getTo(), array('cake@cakephp.org' => 'cake@cakephp.org'));
|
|
|
|
|
|
|
|
$this->CakeEmail->reset();
|
|
|
|
$this->assertIdentical($this->CakeEmail->getTo(), array());
|
2011-02-27 18:25:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|