posts index<\/div>/", $result);
+ $this->assertPattern("/
posts index<\/div>/", $result);
+ }
+
+ function testRenderElement() {
+ $View = new View($this->PostsController);
+ $element = 'element_name';
+ $result = $View->renderElement($element);
+ $this->assertPattern('/Not Found/i', $result);
+
+ $element = 'test_element';
+ $result = $View->renderElement($element);
+ $this->assertPattern('/this is the test element/i', $result);
+ }
+
+ function testRenderCache() {
+ $view = 'test_view';
+ $View = new View($this->PostsController);
+ $path = CACHE . 'views' . DS . 'view_cache_'.$view;
+
+ $cacheText = 'some cacheText';
+ $f = fopen($path, 'w+');
+ fwrite($f, $cacheText);
+ fclose($f);
+
+ $result = $View->renderCache($path, '+1 second');
+ $this->assertFalse($result);
+ @unlink($path);
+
+ $cacheText = 'some cacheText';
+ $f = fopen($path, 'w+');
+ fwrite($f, $cacheText);
+ fclose($f);
+ ob_start();
+ $View->renderCache($path, '+1 second');
+ $result = ob_get_clean();
+ $this->assertFalse(empty($result));
+ @unlink($path);
+ }
+
+ function testSet() {
+ $View = new TestView($this->PostsController);
+ $View->viewVars = array();
+ $View->set('somekey', 'someValue');
+ $this->assertIdentical($View->viewVars, array('somekey' => 'someValue'));
+ $this->assertIdentical($View->getVars(), array('somekey'));
+
+ $View->set('title', 'my_title');
+ $this->assertIdentical($View->pageTitle, 'my_title');
+
+ $View->viewVars = array();
+ $keys = array('key1', 'key2');
+ $values = array('value1', 'value2');
+ $View->set($keys, $values);
+ $this->assertIdentical($View->viewVars, array('key1' => 'value1', 'key2' => 'value2'));
+ $this->assertIdentical($View->getVars(), array('key1', 'key2'));
+ $this->assertIdentical($View->getVar('key1'), 'value1');
+ $this->assertNull($View->getVar('key3'));
}
function testBadExt() {
@@ -305,7 +375,6 @@ class ViewTest extends UnitTestCase {
unset($this->View);
unset($this->PostsController);
unset($this->Controller);
-
}
}
?>
\ No newline at end of file