Throw an exception when starting a view block twice

This commit is contained in:
Marc Würth 2013-10-25 21:43:53 +02:00
parent 4048c686b7
commit 39cd7565ef
2 changed files with 18 additions and 0 deletions

View file

@ -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.

View file

@ -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();
}