diff --git a/lib/Cake/Test/Case/View/ViewTest.php b/lib/Cake/Test/Case/View/ViewTest.php index 337591e7e..e9c40851f 100644 --- a/lib/Cake/Test/Case/View/ViewTest.php +++ b/lib/Cake/Test/Case/View/ViewTest.php @@ -1515,6 +1515,20 @@ class ViewTest extends CakeTestCase { $this->assertEquals('In second', $this->View->fetch('second')); } +/** + * Test that starting the same block twice throws an exception + * + * @expectedException CakeException + * @return void + */ + public function testStartBlocksTwice() { + $this->View->start('first'); + echo 'In first '; + $this->View->start('second'); + echo 'In second'; + $this->View->start('first'); + } + /** * Test that an exception gets thrown when you leave a block open at the end * of a view. diff --git a/lib/Cake/View/ViewBlock.php b/lib/Cake/View/ViewBlock.php index ecde67d4e..a48fe4c8d 100644 --- a/lib/Cake/View/ViewBlock.php +++ b/lib/Cake/View/ViewBlock.php @@ -72,9 +72,13 @@ class ViewBlock { * using View::get(); * * @param string $name The name of the block to capture for. + * @throws CakeException When starting a block twice * @return void */ public function start($name) { + if (in_array($name, $this->_active)) { + throw new CakeException(__("A view block with the name '%s' is already/still open.", $name)); + } $this->_active[] = $name; ob_start(); }