Skip to content
Permalink
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...
markstory committed Sep 17, 2011
1 parent 85b86cb commit 0e5797d69d75b2c54c710d278db3fba0cde779e4
@@ -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));
}
}
@@ -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';
}
}
/**
@@ -1424,6 +1433,45 @@ public function testFullPageCachingDispatch() {
unlink($filename);
}
/**
* 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
*
@@ -1 +1,2 @@
default test_theme layout
default test_theme layout
<?php echo $content_for_layout ?>
@@ -0,0 +1,4 @@
posts themed themed file.
<!--nocache-->
<?php echo $this->element('test_element'); ?>
<!--/nocache-->
@@ -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.
You can’t perform that action at this time.