Permalink
Browse files

Throw an exception when starting a view block twice

  • Loading branch information...
1 parent 4048c68 commit 39cd7565efaa3e871b552a1ca1a6aef26eb9852a @ravage84 ravage84 committed Oct 25, 2013
Showing with 18 additions and 0 deletions.
  1. +14 −0 lib/Cake/Test/Case/View/ViewTest.php
  2. +4 −0 lib/Cake/View/ViewBlock.php
@@ -1515,6 +1515,20 @@ public function testNestedBlocks() {
$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();
}

0 comments on commit 39cd756

Please sign in to comment.