Backport helper method for view blocks from 3.0

Related PR is #5385
This commit is contained in:
Walther Lalk 2014-12-11 16:44:11 +02:00
parent c32e165052
commit 9be725613e
3 changed files with 31 additions and 0 deletions

View file

@ -1425,6 +1425,17 @@ class ViewTest extends CakeTestCase {
$this->assertSame('', $result);
}
/**
* Test checking a block's existance.
*
* @return void
*/
public function testBlockExist() {
$this->assertFalse($this->View->exists('test'));
$this->View->assign('test', 'Block content');
$this->assertTrue($this->View->exists('test'));
}
/**
* Test setting a block's content to null
*

View file

@ -698,6 +698,16 @@ class View extends Object {
return $this->Blocks->get($name, $default);
}
/**
* Check if a block exists
*
* @param string $name Name of the block
* @return bool
*/
public function exists($name) {
return $this->Blocks->exists($name);
}
/**
* End a capturing block. The compliment to View::start()
*

View file

@ -196,6 +196,16 @@ class ViewBlock {
return $this->_blocks[$name];
}
/**
* Check if a block exists
*
* @param string $name Name of the block
* @return bool
*/
public function exists($name) {
return isset($this->_blocks[$name]);
}
/**
* Get the names of all the existing blocks.
*