Skip to content
Browse files

Make full page caching + Themes work.

Dispatcher now uses ThemeView for rendering cache files.
This enables nocache blocks to reference theme elements.
Fixes #1858
  • Loading branch information...
1 parent 85b86cb commit 0e5797d69d75b2c54c710d278db3fba0cde779e4 @markstory markstory committed
View
4 lib/Cake/Routing/Dispatcher.php
@@ -218,8 +218,10 @@ public function cached($path) {
}
if (file_exists($filename)) {
+ App::uses('ThemeView', 'View');
+
$controller = null;
- $view = new View($controller);
+ $view = new ThemeView($controller);
return $view->renderCache($filename, microtime(true));
}
}
View
48 lib/Cake/Test/Case/Routing/DispatcherTest.php
@@ -442,6 +442,15 @@ public function cache_form() {
$this->cacheAction = 10;
$this->helpers[] = 'Form';
}
+
+/**
+ * Test cached views with themes.
+ */
+ public function themed() {
+ $this->cacheAction = 10;
+ $this->viewClass = 'Theme';
+ $this->theme = 'TestTheme';
+ }
}
/**
@@ -1425,6 +1434,45 @@ public function testFullPageCachingDispatch() {
}
/**
+ * Test full page caching with themes.
+ *
+ * @return void
+ */
+ public function testFullPageCachingWithThemes() {
+ Configure::write('Cache.disable', false);
+ Configure::write('Cache.check', true);
+ Configure::write('debug', 2);
+
+ Router::reload();
+ Router::connect('/:controller/:action/*');
+
+ App::build(array(
+ 'View' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS),
+ ), true);
+
+ $dispatcher = new TestDispatcher();
+ $request = new CakeRequest('/test_cached_pages/themed');
+ $response = new CakeResponse();
+
+ ob_start();
+ $dispatcher->dispatch($request, $response);
+ $out = ob_get_clean();
+
+ ob_start();
+ $dispatcher->cached($request->here);
+ $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($expected, $result);
+
+ $filename = $this->__cachePath($request->here);
+ unlink($filename);
+ }
+
+/**
* testHttpMethodOverrides method
*
* @return void
View
3 lib/Cake/Test/test_app/View/Themed/TestTheme/Layouts/default.ctp
@@ -1 +1,2 @@
-default test_theme layout
+default test_theme layout
+<?php echo $content_for_layout ?>
View
4 lib/Cake/Test/test_app/View/Themed/TestTheme/Posts/themed.ctp
@@ -0,0 +1,4 @@
+posts themed themed file.
+<!--nocache-->
+<?php echo $this->element('test_element'); ?>
+<!--/nocache-->
View
4 lib/Cake/View/ThemeView.php
@@ -38,7 +38,9 @@ class ThemeView extends View {
*/
public function __construct($controller) {
parent::__construct($controller);
- $this->theme = $controller->theme;
+ if ($controller) {
+ $this->theme = $controller->theme;
+ }
}
/**

0 comments on commit 0e5797d

Please sign in to comment.
Something went wrong with that request. Please try again.