From 5ea3b75b2fc0dfce45dd169ca1d877554c2f40a3 Mon Sep 17 00:00:00 2001 From: Juan Basso Date: Sun, 17 Apr 2011 20:57:57 -0400 Subject: [PATCH] CakeEmail::viewVars() now merge the param with previous config. --- lib/Cake/Network/CakeEmail.php | 4 ++-- lib/Cake/tests/Case/Network/CakeEmailTest.php | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/lib/Cake/Network/CakeEmail.php b/lib/Cake/Network/CakeEmail.php index ae62d4a40..c2f60c4cc 100644 --- a/lib/Cake/Network/CakeEmail.php +++ b/lib/Cake/Network/CakeEmail.php @@ -675,14 +675,14 @@ class CakeEmail { /** * Variables to be set on render * - * @param array + * @param array $viewVars * @return mixed */ public function viewVars($viewVars = null) { if ($viewVars === null) { return $this->_viewVars; } - $this->_viewVars = $viewVars; + $this->_viewVars = array_merge($this->_viewVars, (array)$viewVars); return $this; } diff --git a/lib/Cake/tests/Case/Network/CakeEmailTest.php b/lib/Cake/tests/Case/Network/CakeEmailTest.php index d96503a0e..0186d9a69 100644 --- a/lib/Cake/tests/Case/Network/CakeEmailTest.php +++ b/lib/Cake/tests/Case/Network/CakeEmailTest.php @@ -431,6 +431,24 @@ class CakeEmailTest extends CakeTestCase { $this->assertIdentical($this->CakeEmail->template(), $expected); } +/** + * testViewVars method + * + * @return void + */ + public function testViewVars() { + $this->assertIdentical($this->CakeEmail->viewVars(), array()); + + $this->CakeEmail->viewVars(array('value' => 12345)); + $this->assertIdentical($this->CakeEmail->viewVars(), array('value' => 12345)); + + $this->CakeEmail->viewVars(array('name' => 'CakePHP')); + $this->assertIdentical($this->CakeEmail->viewVars(), array('value' => 12345, 'name' => 'CakePHP')); + + $this->CakeEmail->viewVars(array('value' => 4567)); + $this->assertIdentical($this->CakeEmail->viewVars(), array('value' => 4567, 'name' => 'CakePHP')); + } + /** * testAttachments method *