diff --git a/lib/Cake/Test/Case/View/ViewTest.php b/lib/Cake/Test/Case/View/ViewTest.php index 78a149bb0..fdf52d6e2 100644 --- a/lib/Cake/Test/Case/View/ViewTest.php +++ b/lib/Cake/Test/Case/View/ViewTest.php @@ -1660,7 +1660,7 @@ TEXT; } /** - * Tests that a vew block uses default value when not assigned and uses assigned value when it is + * Tests that a view block uses default value when not assigned and uses assigned value when it is * * @return void */ @@ -1674,4 +1674,20 @@ TEXT; $result = $this->View->fetch('title', $default); $this->assertEquals($expected, $result); } + +/** + * Tests that a view variable uses default value when not assigned and uses assigned value when it is + * + * @return void + */ + public function testViewVarDefaultValue() { + $default = 'Default'; + $result = $this->View->get('title', $default); + $this->assertEquals($default, $result); + + $expected = 'Back to the Future'; + $this->View->set('title', $expected); + $result = $this->View->get('title', $default); + $this->assertEquals($expected, $result); + } } diff --git a/lib/Cake/View/View.php b/lib/Cake/View/View.php index 79fd648fa..6292f926f 100644 --- a/lib/Cake/View/View.php +++ b/lib/Cake/View/View.php @@ -582,11 +582,12 @@ class View extends Object { * Blocks are checked before view variables. * * @param string $var The view var you want the contents of. - * @return mixed The content of the named var if its set, otherwise null. + * @param mixed $default The default/fallback content of $var. + * @return mixed The content of the named var if its set, otherwise $default. */ - public function get($var) { + public function get($var, $default = null) { if (!isset($this->viewVars[$var])) { - return null; + return $default; } return $this->viewVars[$var]; }