Browse files

Adding tests for Blocks in View.

Blocks should replace scripts_for_layout and content_for_layout
in a future version of CakePHP.
  • Loading branch information...
1 parent 577225b commit 3e2bde523b137949556252447e2598ff509f8f99 @markstory markstory committed with markstory Aug 16, 2011
Showing with 78 additions and 0 deletions.
  1. +78 −0 lib/Cake/Test/Case/View/ViewTest.php
View
78 lib/Cake/Test/Case/View/ViewTest.php
@@ -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.