Browse Source

Patch for issue #7561

Add reset method and tests
jeffblack360 10 years ago
parent
commit
2714e1459e
2 changed files with 29 additions and 0 deletions
  1. 13 0
      src/View/View.php
  2. 16 0
      tests/TestCase/View/ViewTest.php

+ 13 - 0
src/View/View.php

@@ -738,6 +738,19 @@ class View implements EventDispatcherInterface
     }
 
     /**
+     * Reset the content for a block. This will overwrite any
+     * existing content.
+     *
+     * @param string $name Name of the block
+     * @return void
+     * @see ViewBlock::set()
+     */
+    public function reset($name)
+    {
+        $this->assign($name, '');
+    }
+
+    /**
      * Fetch the content for a block. If a block is
      * empty or undefined '' will be returned.
      *

+ 16 - 0
tests/TestCase/View/ViewTest.php

@@ -1489,6 +1489,22 @@ class ViewTest extends TestCase
     }
 
     /**
+     * Test resetting a block's content with reset.
+     *
+     * @return void
+     */
+    public function testBlockResetFunc()
+    {
+        $this->View->assign('test', 'Block content');
+        $result = $this->View->fetch('test', 'This should not be returned');
+        $this->assertSame('Block content', $result);
+
+        $this->View->reset('test');
+        $result = $this->View->fetch('test', 'This should not be returned');
+        $this->assertSame('', $result);
+    }
+
+    /**
      * Test checking a block's existance.
      *
      * @return void