mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
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:
parent
85b86cb282
commit
0e5797d69d
5 changed files with 60 additions and 3 deletions
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
*
|
||||
|
|
|
@ -1 +1,2 @@
|
|||
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,8 +38,10 @@ class ThemeView extends View {
|
|||
*/
|
||||
public function __construct($controller) {
|
||||
parent::__construct($controller);
|
||||
if ($controller) {
|
||||
$this->theme = $controller->theme;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all possible paths to find view files in order
|
||||
|
|
Loading…
Reference in a new issue