Skip to content

Commit

Permalink
Cleaning up tests for EmailComponent
Browse files Browse the repository at this point in the history
  • Loading branch information
jperras committed Aug 10, 2009
1 parent a52a4fb commit a9a3138
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 20 deletions.
2 changes: 2 additions & 0 deletions cake/libs/controller/components/email.php
Expand Up @@ -325,11 +325,13 @@ function send($content = null, $template = null, $layout = null) {
}

$message = $this->_wrap($content);

if ($this->template === null) {
$message = $this->_formatMessage($message);
} else {
$message = $this->_render($message);
}

$message[] = '';
$this->__message = $message;

Expand Down
22 changes: 2 additions & 20 deletions cake/tests/cases/libs/controller/components/email.test.php
Expand Up @@ -262,7 +262,7 @@ function testSmtpSend() {
if (!$this->skipIf(!@fsockopen('localhost', 25), '%s No SMTP server running on localhost')) {
return;
}
$this->Controller->EmailTest->reset();

$this->Controller->EmailTest->to = 'postmaster@localhost';
$this->Controller->EmailTest->from = 'noreply@example.com';
$this->Controller->EmailTest->subject = 'Cake SMTP test';
Expand Down Expand Up @@ -310,7 +310,6 @@ function testSmtpSend() {
function testAuthenticatedSmtpSend() {
$this->skipIf(!@fsockopen('localhost', 25), '%s No SMTP server running on localhost');

$this->Controller->EmailTest->reset();
$this->Controller->EmailTest->to = 'postmaster@localhost';
$this->Controller->EmailTest->from = 'noreply@example.com';
$this->Controller->EmailTest->subject = 'Cake SMTP test';
Expand All @@ -335,7 +334,6 @@ function testAuthenticatedSmtpSend() {
* @return void
*/
function testSendFormats() {
$this->Controller->EmailTest->reset();
$this->Controller->EmailTest->to = 'postmaster@localhost';
$this->Controller->EmailTest->from = 'noreply@example.com';
$this->Controller->EmailTest->subject = 'Cake SMTP test';
Expand Down Expand Up @@ -386,7 +384,6 @@ function testSendFormats() {
* @return void
*/
function testTemplates() {
$this->Controller->EmailTest->reset();
$this->Controller->EmailTest->to = 'postmaster@localhost';
$this->Controller->EmailTest->from = 'noreply@example.com';
$this->Controller->EmailTest->subject = 'Cake SMTP test';
Expand Down Expand Up @@ -507,7 +504,6 @@ function testTemplates() {
function testSmtpSendSocket() {
$this->skipIf(!@fsockopen('localhost', 25), '%s No SMTP server running on localhost');

$this->Controller->EmailTest->reset();
$socket =& new CakeSocket(array_merge(array('protocol'=>'smtp'), $this->Controller->EmailTest->smtpOptions));
$this->Controller->EmailTest->setConnectionSocket($socket);

Expand All @@ -529,7 +525,6 @@ function testSmtpSendSocket() {
* @return void
*/
function testSendDebug() {
$this->Controller->EmailTest->reset();
$this->Controller->EmailTest->to = 'postmaster@localhost';
$this->Controller->EmailTest->from = 'noreply@example.com';
$this->Controller->EmailTest->subject = 'Cake Debug Test';
Expand Down Expand Up @@ -558,7 +553,6 @@ function testSendDebug() {
* @return void
*/
function testSendContentArray() {
$this->Controller->EmailTest->reset();
$this->Controller->EmailTest->to = 'postmaster@localhost';
$this->Controller->EmailTest->from = 'noreply@example.com';
$this->Controller->EmailTest->subject = 'Cake Debug Test';
Expand Down Expand Up @@ -617,7 +611,6 @@ function testContentStripping() {
* @return void
*/
function testMultibyte() {
$this->Controller->EmailTest->reset();
$this->Controller->EmailTest->to = 'postmaster@localhost';
$this->Controller->EmailTest->from = 'noreply@example.com';
$this->Controller->EmailTest->subject = 'هذه رسالة بعنوان طويل مرسل للمستلم';
Expand Down Expand Up @@ -650,7 +643,6 @@ function testMultibyte() {
* @access public
*/
function testSendAsIsNotIgnoredIfAttachmentsPresent() {
$this->Controller->EmailTest->reset();
$this->Controller->EmailTest->to = 'postmaster@localhost';
$this->Controller->EmailTest->from = 'noreply@example.com';
$this->Controller->EmailTest->subject = 'Attachment Test';
Expand Down Expand Up @@ -688,7 +680,6 @@ function testSendAsIsNotIgnoredIfAttachmentsPresent() {
* @access public
*/
function testNoDoubleNewlinesInHeaders() {
$this->Controller->EmailTest->reset();
$this->Controller->EmailTest->to = 'postmaster@localhost';
$this->Controller->EmailTest->from = 'noreply@example.com';
$this->Controller->EmailTest->subject = 'Attachment Test';
Expand Down Expand Up @@ -745,34 +736,25 @@ function testReset() {
$this->assertIdentical($this->Controller->EmailTest->attachments, array());
}

function testCustomViewClass() {
function testPluginCustomViewClass() {
App::build(array(
'plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS),
'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS)
));

$this->Controller->EmailTest->reset();

$this->Controller->view = 'TestPlugin.Email';

$this->Controller->EmailTest->to = 'postmaster@localhost';
$this->Controller->EmailTest->from = 'noreply@example.com';
$this->Controller->EmailTest->subject = 'CustomViewClass test';
$this->Controller->EmailTest->replyTo = 'noreply@example.com';

$this->Controller->EmailTest->template = 'default';
$this->Controller->EmailTest->layout = 'default';

$this->Controller->EmailTest->delivery = 'debug';
$body = 'Body of message';

$this->Controller->EmailTest->sendAs = 'text';
$this->assertTrue($this->Controller->EmailTest->send($body));
$result = $this->Controller->Session->read('Message.email.message');

$this->assertPattern('/Body of message/', $result);

debug($result, true);
}

/**
Expand Down

0 comments on commit a9a3138

Please sign in to comment.