diff --git a/lib/Cake/Test/Case/View/ViewTest.php b/lib/Cake/Test/Case/View/ViewTest.php index 360f962ad37..e87e8950b3c 100644 --- a/lib/Cake/Test/Case/View/ViewTest.php +++ b/lib/Cake/Test/Case/View/ViewTest.php @@ -937,7 +937,7 @@ public function testBlockCapture() { echo 'Block content'; $this->View->end(); - $result = $this->View->get('test'); + $result = $this->View->getBlock('test'); $this->assertEquals('Block content', $result); } @@ -955,7 +955,7 @@ public function testBlockCaptureAppend() { echo ' content'; $this->View->end(); - $result = $this->View->get('test'); + $result = $this->View->getBlock('test'); $this->assertEquals('Block content', $result); } @@ -966,7 +966,7 @@ public function testBlockCaptureAppend() { */ public function testBlockSet() { $this->View->setBlock('test', 'Block content'); - $result = $this->View->get('test'); + $result = $this->View->getBlock('test'); $this->assertEquals('Block content', $result); } @@ -979,7 +979,7 @@ public function testBlockAppend() { $this->View->setBlock('test', 'Block'); $this->View->append('test', ' content'); - $result = $this->View->get('test'); + $result = $this->View->getBlock('test'); $this->assertEquals('Block content', $result); } @@ -990,7 +990,7 @@ public function testBlockAppend() { */ public function testBlockAppendUndefined() { $this->View->append('test', 'Unknown'); - $result = $this->View->get('test'); + $result = $this->View->getBlock('test'); $this->assertEquals('Unknown', $result); } diff --git a/lib/Cake/View/View.php b/lib/Cake/View/View.php index 76690144bb6..0d967de961d 100644 --- a/lib/Cake/View/View.php +++ b/lib/Cake/View/View.php @@ -499,12 +499,9 @@ public function getVar($var) { * @return mixed The content of the named var if its set, otherwise null. */ public function get($var) { - if (!isset($this->viewVars[$var]) && !isset($this->_blocks[$var])) { + if (!isset($this->viewVars[$var])) { return null; } - if (isset($this->_blocks[$var])) { - return $this->_blocks[$var]; - } return $this->viewVars[$var]; } @@ -577,6 +574,19 @@ public function setBlock($name, $value) { $this->_blocks[$name] = $value; } +/** + * Get the content for a block. + * + * @param string $name Name of the block + * @return The block content or '' if the block does not exist. + */ + public function getBlock($name) { + if (!isset($this->_blocks[$name])) { + return ''; + } + return $this->_blocks[$name]; + } + /** * End a capturing block. The compliment to View::start() *