From 5092013304eba4d05789c6fc2aa8d7c575764f9c Mon Sep 17 00:00:00 2001 From: mark_story Date: Mon, 27 Dec 2010 15:12:27 -0500 Subject: [PATCH] Making EmailComponent register and un-register its view object, when rendering email templates. This allows helpers to use the view to do additional processing. Fixes #442 --- cake/libs/controller/components/email.php | 4 +++- cake/tests/cases/libs/controller/components/email.test.php | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/cake/libs/controller/components/email.php b/cake/libs/controller/components/email.php index 3bb1357ac..c5ff866d5 100755 --- a/cake/libs/controller/components/email.php +++ b/cake/libs/controller/components/email.php @@ -458,7 +458,7 @@ class EmailComponent extends Object{ App::import('View', $this->Controller->view); } - $View = new $viewClass($this->Controller, false); + $View = new $viewClass($this->Controller); $View->layout = $this->layout; $msg = array(); @@ -496,6 +496,7 @@ class EmailComponent extends Object{ $msg[] = '--alt-' . $this->__boundary . '--'; $msg[] = ''; + ClassRegistry::removeObject('view'); return $msg; } @@ -525,6 +526,7 @@ class EmailComponent extends Object{ } $msg = array_merge($msg, $content); + ClassRegistry::removeObject('view'); return $msg; } diff --git a/cake/tests/cases/libs/controller/components/email.test.php b/cake/tests/cases/libs/controller/components/email.test.php index 0dbb72d0e..72c14ace6 100755 --- a/cake/tests/cases/libs/controller/components/email.test.php +++ b/cake/tests/cases/libs/controller/components/email.test.php @@ -538,6 +538,8 @@ MSGBLOC; * @return void */ function testTemplates() { + ClassRegistry::flush(); + $this->Controller->EmailTest->to = 'postmaster@localhost'; $this->Controller->EmailTest->from = 'noreply@example.com'; $this->Controller->EmailTest->subject = 'Cake SMTP test'; @@ -629,6 +631,9 @@ HTMLBLOC; $expect = '
' . str_replace('{CONTENTTYPE}', 'text/html; charset=UTF-8', $header) . $html . '
'; $this->assertTrue($this->Controller->EmailTest->send('This is the body of the message', 'default', 'thin')); $this->assertEqual($this->Controller->Session->read('Message.email.message'), $this->__osFix($expect)); + + $result = ClassRegistry::getObject('view'); + $this->assertFalse($result); } /**