Permalink
Browse files

Add View::getBlock()

View::get() had two jobs.  That's almost always a bad thing.
Add a new method instead.
  • Loading branch information...
1 parent 90f035c commit 7854f9dd5253a20a968d5abcd1f3a55473ae5427 @markstory markstory committed Sep 15, 2011
Showing with 19 additions and 9 deletions.
  1. +5 −5 lib/Cake/Test/Case/View/ViewTest.php
  2. +14 −4 lib/Cake/View/View.php
@@ -937,7 +937,7 @@ public function testBlockCapture() {
echo 'Block content';
$this->View->end();
- $result = $this->View->get('test');
+ $result = $this->View->getBlock('test');
$this->assertEquals('Block content', $result);
}
@@ -955,7 +955,7 @@ public function testBlockCaptureAppend() {
echo ' content';
$this->View->end();
- $result = $this->View->get('test');
+ $result = $this->View->getBlock('test');
$this->assertEquals('Block content', $result);
}
@@ -966,7 +966,7 @@ public function testBlockCaptureAppend() {
*/
public function testBlockSet() {
$this->View->setBlock('test', 'Block content');
- $result = $this->View->get('test');
+ $result = $this->View->getBlock('test');
$this->assertEquals('Block content', $result);
}
@@ -979,7 +979,7 @@ public function testBlockAppend() {
$this->View->setBlock('test', 'Block');
$this->View->append('test', ' content');
- $result = $this->View->get('test');
+ $result = $this->View->getBlock('test');
$this->assertEquals('Block content', $result);
}
@@ -990,7 +990,7 @@ public function testBlockAppend() {
*/
public function testBlockAppendUndefined() {
$this->View->append('test', 'Unknown');
- $result = $this->View->get('test');
+ $result = $this->View->getBlock('test');
$this->assertEquals('Unknown', $result);
}
View
@@ -499,12 +499,9 @@ public function getVar($var) {
* @return mixed The content of the named var if its set, otherwise null.
*/
public function get($var) {
- if (!isset($this->viewVars[$var]) && !isset($this->_blocks[$var])) {
+ if (!isset($this->viewVars[$var])) {
return null;
}
- if (isset($this->_blocks[$var])) {
- return $this->_blocks[$var];
- }
return $this->viewVars[$var];
}
@@ -578,6 +575,19 @@ public function setBlock($name, $value) {
}
/**
+ * Get the content for a block.
+ *
+ * @param string $name Name of the block
+ * @return The block content or '' if the block does not exist.
+ */
+ public function getBlock($name) {
+ if (!isset($this->_blocks[$name])) {
+ return '';
+ }
+ return $this->_blocks[$name];
+ }
+
+/**
* End a capturing block. The compliment to View::start()
*
* @return void

0 comments on commit 7854f9d

Please sign in to comment.