Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adding test case for cached view files, and fatal errors caused by th…

…e view instance not being registered. View instances are now registered when rendering view caches, and unregistered if the cached view fails. This fixes issues rendering flash messages with custom layouts and fixes FormHelper methods inside nocache blocks.

Fixes #60
  • Loading branch information...
commit 47a9401d4343c36c5518f104177066dceaf9ce27 1 parent c3bf6bc
Mark Story markstory authored
8 cake/dispatcher.php
View
@@ -678,8 +678,12 @@ function cached($url) {
App::import('Core', 'View');
}
$controller = null;
- $view =& new View($controller, false);
- return $view->renderCache($filename, getMicrotime());
+ $view =& new View($controller);
+ $return = $view->renderCache($filename, getMicrotime());
+ if (!$return) {
+ ClassRegistry::removeObject('view');
+ }
+ return $return;
}
}
return false;
51 cake/tests/cases/dispatcher.test.php
View
@@ -448,6 +448,15 @@ function test_nocache_tags() {
function view($id = null) {
$this->render('index');
}
+/**
+ * test cached forms / tests view object being registered
+ *
+ * @return void
+ */
+ function cache_form() {
+ $this->cacheAction = 10;
+ $this->helpers[] = 'Form';
+ }
}
/**
* TimesheetsController class
@@ -1899,6 +1908,48 @@ function testFullPageCachingDispatch() {
$filename = $this->__cachePath($dispatcher->here);
$this->assertTrue(file_exists($filename));
unlink($filename);
+
+ $url = 'TestCachedPages/test_nocache_tags';
+ }
+/**
+ * test that cached() registers a view and un-registers it. Tests
+ * that helpers using ClassRegistry::getObject('view'); don't fail
+ *
+ * @return void
+ */
+ function testCachedRegisteringViewObject() {
+ Configure::write('Cache.disable', false);
+ Configure::write('Cache.check', true);
+ Configure::write('debug', 2);
+
+ $_POST = array();
+ $_SERVER['PHP_SELF'] = '/';
+
+ Router::reload();
+ Configure::write('viewPaths', array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS));
+
+ $dispatcher =& new Dispatcher();
+ $dispatcher->base = false;
+
+ $url = 'test_cached_pages/cache_form';
+ ob_start();
+ $dispatcher->dispatch($url);
+ $out = ob_get_clean();
+
+ ClassRegistry::flush();
+
+ ob_start();
+ $dispatcher->cached($url);
+ $cached = ob_get_clean();
+
+ $result = str_replace(array("\t", "\r\n", "\n"), "", $out);
+ $cached = preg_replace('/<!--+[^<>]+-->/', '', $cached);
+ $expected = str_replace(array("\t", "\r\n", "\n"), "", $cached);
+
+ $this->assertEqual($result, $expected);
+ $filename = $this->__cachePath($dispatcher->here);
+ unlink($filename);
+ ClassRegistry::flush();
}
/**
* testHttpMethodOverrides method
14 cake/tests/test_app/views/posts/cache_form.ctp
View
@@ -0,0 +1,14 @@
+<div class="users form">
+<cake:nocache>
+ <?php echo $form->create('User');?>
+ <fieldset>
+ <legend><?php __('Add User');?></legend>
+ <?php
+ echo $form->input('username');
+ echo $form->input('email');
+ echo $form->input('password');
+ ?>
+ </fieldset>
+ <?php echo $form->end('Submit');?>
+</cake:nocache>
+</div>
Please sign in to comment.
Something went wrong with that request. Please try again.