diff --git a/lib/Cake/Test/Case/View/ViewTest.php b/lib/Cake/Test/Case/View/ViewTest.php index f18a02093..d154e8dea 100644 --- a/lib/Cake/Test/Case/View/ViewTest.php +++ b/lib/Cake/Test/Case/View/ViewTest.php @@ -1425,6 +1425,17 @@ class ViewTest extends CakeTestCase { $this->assertSame('', $result); } +/** + * Test checking a block's existance. + * + * @return void + */ + public function testBlockExist() { + $this->assertFalse($this->View->exists('test')); + $this->View->assign('test', 'Block content'); + $this->assertTrue($this->View->exists('test')); + } + /** * Test setting a block's content to null * diff --git a/lib/Cake/View/View.php b/lib/Cake/View/View.php index a33dd1a1f..01bacfef5 100644 --- a/lib/Cake/View/View.php +++ b/lib/Cake/View/View.php @@ -698,6 +698,16 @@ class View extends Object { return $this->Blocks->get($name, $default); } +/** + * Check if a block exists + * + * @param string $name Name of the block + * @return bool + */ + public function exists($name) { + return $this->Blocks->exists($name); + } + /** * End a capturing block. The compliment to View::start() * diff --git a/lib/Cake/View/ViewBlock.php b/lib/Cake/View/ViewBlock.php index f45119db7..51ec8e767 100644 --- a/lib/Cake/View/ViewBlock.php +++ b/lib/Cake/View/ViewBlock.php @@ -196,6 +196,16 @@ class ViewBlock { return $this->_blocks[$name]; } +/** + * Check if a block exists + * + * @param string $name Name of the block + * @return bool + */ + public function exists($name) { + return isset($this->_blocks[$name]); + } + /** * Get the names of all the existing blocks. *