Skip to content

Commit

Permalink
Adding tests for Blocks in View.
Browse files Browse the repository at this point in the history
Blocks should replace scripts_for_layout and content_for_layout
in a future version of CakePHP.
  • Loading branch information
markstory committed Dec 18, 2011
1 parent 577225b commit 3e2bde5
Showing 1 changed file with 78 additions and 0 deletions.
78 changes: 78 additions & 0 deletions lib/Cake/Test/Case/View/ViewTest.php
Expand Up @@ -926,4 +926,82 @@ public function testAltBadExt() {
$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');
}
}

0 comments on commit 3e2bde5

Please sign in to comment.