mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Adding tests for Blocks in View.
Blocks should replace scripts_for_layout and content_for_layout in a future version of CakePHP.
This commit is contained in:
parent
577225b8a6
commit
3e2bde523b
1 changed files with 78 additions and 0 deletions
|
@ -926,4 +926,82 @@ class ViewTest extends CakeTestCase {
|
|||
$View->render('alt_ext');
|
||||
$result = str_replace(array("\t", "\r\n", "\n"), "", ob_get_clean());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test creating a block with capturing output.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testBlockCapture() {
|
||||
$this->View->start('test');
|
||||
echo 'Block content';
|
||||
$this->View->end();
|
||||
|
||||
$result = $this->View->get('test');
|
||||
$this->assertEquals('Block content', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test appending to a block with capturing output.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testBlockCaptureAppend() {
|
||||
$this->View->start('test');
|
||||
echo 'Block';
|
||||
$this->View->end();
|
||||
|
||||
$this->View->append('test');
|
||||
echo ' content';
|
||||
$this->View->end();
|
||||
|
||||
$result = $this->View->get('test');
|
||||
$this->assertEquals('Block content', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test setting a block's content.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testBlockSet() {
|
||||
$this->View->set('test', 'Block content');
|
||||
$result = $this->View->get('test');
|
||||
$this->assertEquals('Block content', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test appending to a block with append.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testBlockAppend() {
|
||||
$this->View->set('test', 'Block');
|
||||
$this->View->append('test', ' content');
|
||||
|
||||
$result = $this->View->get('test');
|
||||
$this->assertEquals('Block content', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* You should be able to append to undefined blocks.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testBlockAppendUndefined() {
|
||||
$this->View->append('test', 'Unknown');
|
||||
$result = $this->View->get('test');
|
||||
$this->assertEquals('Unknown', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Appending to an array should cause an exception.
|
||||
*
|
||||
* @expectedException CakeException
|
||||
* @return void
|
||||
*/
|
||||
public function testBlockAppendArrayException() {
|
||||
$this->View->set('test', array(1, 2, 3));
|
||||
$this->View->append('test', 'Kaboom');
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue