Skip to content
This repository
Browse code

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
  • Loading branch information...
commit 5c481f127602432320b43ab6b21f38da8bb97e51 1 parent bcc0626
Mark Story authored December 27, 2010
4  cake/libs/controller/components/email.php
@@ -391,7 +391,7 @@ function __renderTemplate($content) {
391 391
 			$viewClass = $viewClass . 'View';
392 392
 			App::import('View', $this->Controller->view);
393 393
 		}
394  
-		$View = new $viewClass($this->Controller, false);
  394
+		$View = new $viewClass($this->Controller);
395 395
 		$View->layout = $this->layout;
396 396
 		$msg = array();
397 397
 
@@ -428,6 +428,7 @@ function __renderTemplate($content) {
428 428
 			$msg[] = '--alt-' . $this->__boundary . '--';
429 429
 			$msg[] = '';
430 430
 
  431
+			ClassRegistry::removeObject('view');
431 432
 			return $msg;
432 433
 		}
433 434
 
@@ -450,6 +451,7 @@ function __renderTemplate($content) {
450 451
 		$View->layoutPath = 'email' . DS . $this->sendAs;
451 452
 		$content = explode("\n", str_replace(array("\r\n", "\r"), "\n", $View->renderLayout($content)));
452 453
 		$msg = array_merge($msg, $content);
  454
+		ClassRegistry::removeObject('view');
453 455
 
454 456
 		return $msg;
455 457
 	}
27  cake/tests/cases/libs/controller/components/email.test.php
@@ -359,7 +359,8 @@ function testSendFormats() {
359 359
  * @return void
360 360
  */
361 361
 	function testTemplates() {
362  
-		$this->Controller->EmailTest->reset();
  362
+		ClassRegistry::flush();
  363
+
363 364
 		$this->Controller->EmailTest->to = 'postmaster@localhost';
364 365
 		$this->Controller->EmailTest->from = 'noreply@example.com';
365 366
 		$this->Controller->EmailTest->subject = 'Cake SMTP test';
@@ -453,25 +454,11 @@ function testTemplates() {
453 454
 		$expect = '<pre>' . str_replace('{CONTENTTYPE}', 'text/html; charset=UTF-8', $header) . $html . "\n" . '</pre>';
454 455
 		$this->assertTrue($this->Controller->EmailTest->send('This is the body of the message', 'default', 'thin'));
455 456
 		$this->assertEqual($this->Controller->Session->read('Message.email.message'), $this->__osFix($expect));
456  
-
457  
-		return;
458  
-
459  
-		$text = <<<TEXTBLOC
460  
-
461  
-This element has some text that is just too wide to comply with email
462  
-standards.
463  
-This is the body of the message
464  
-
465  
-This email was sent using the CakePHP Framework, http://cakephp.org.
466  
-
467  
-
468  
-TEXTBLOC;
469  
-
470  
-		$this->Controller->EmailTest->sendAs = 'text';
471  
-		$expect = '<pre>' . str_replace('{CONTENTTYPE}', 'text/plain; charset=UTF-8', $header) . $text . "\n" . '</pre>';
472  
-		$this->assertTrue($this->Controller->EmailTest->send('This is the body of the message', 'wide', 'default'));
473  
-		$this->assertEqual($this->Controller->Session->read('Message.email.message'), $this->__osFix($expect));
  457
+		
  458
+		$result = ClassRegistry::getObject('view');
  459
+		$this->assertFalse($result);
474 460
 	}
  461
+
475 462
 /**
476 463
  * testSmtpSendSocket method
477 464
  *
@@ -767,4 +754,4 @@ function testFormatAddressAliases() {
767 754
 		$this->assertEqual($result, '<email@example.com>');
768 755
 	}
769 756
 }
770  
-?>
  757
+?>

0 notes on commit 5c481f1

Please sign in to comment.
Something went wrong with that request. Please try again.