mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-18 18:46:17 +00:00
Throw an exception when starting a view block twice
This commit is contained in:
parent
4048c686b7
commit
39cd7565ef
2 changed files with 18 additions and 0 deletions
|
@ -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.
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue