Make full page caching + Themes work.

Dispatcher now uses ThemeView for rendering cache files.
This enables nocache blocks to reference theme elements.
Fixes #1858
This commit is contained in:
mark_story 2011-09-17 13:19:43 -04:00
parent 85b86cb282
commit 0e5797d69d
5 changed files with 60 additions and 3 deletions

View file

@ -218,8 +218,10 @@ class Dispatcher {
}
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 file

@ -442,6 +442,15 @@ class TestCachedPagesController extends Controller {
$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 @@ class DispatcherTest extends CakeTestCase {
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
*

View file

@ -1 +1,2 @@
default test_theme layout
default test_theme layout
<?php echo $content_for_layout ?>

View file

@ -0,0 +1,4 @@
posts themed themed file.
<!--nocache-->
<?php echo $this->element('test_element'); ?>
<!--/nocache-->

View file

@ -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;
}
}
/**