diff --git a/lib/Cake/Routing/Dispatcher.php b/lib/Cake/Routing/Dispatcher.php index f526a2f9190..3acfc71bff1 100644 --- a/lib/Cake/Routing/Dispatcher.php +++ b/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)); } } diff --git a/lib/Cake/Test/Case/Routing/DispatcherTest.php b/lib/Cake/Test/Case/Routing/DispatcherTest.php index 24197dadb0c..d5f4f1d5b0f 100644 --- a/lib/Cake/Test/Case/Routing/DispatcherTest.php +++ b/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'; + } } /** @@ -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 * diff --git a/lib/Cake/Test/test_app/View/Themed/TestTheme/Layouts/default.ctp b/lib/Cake/Test/test_app/View/Themed/TestTheme/Layouts/default.ctp index 89107d39314..f055297e29c 100644 --- a/lib/Cake/Test/test_app/View/Themed/TestTheme/Layouts/default.ctp +++ b/lib/Cake/Test/test_app/View/Themed/TestTheme/Layouts/default.ctp @@ -1 +1,2 @@ -default test_theme layout \ No newline at end of file +default test_theme layout + diff --git a/lib/Cake/Test/test_app/View/Themed/TestTheme/Posts/themed.ctp b/lib/Cake/Test/test_app/View/Themed/TestTheme/Posts/themed.ctp new file mode 100644 index 00000000000..b8492b1bc15 --- /dev/null +++ b/lib/Cake/Test/test_app/View/Themed/TestTheme/Posts/themed.ctp @@ -0,0 +1,4 @@ +posts themed themed file. + +element('test_element'); ?> + diff --git a/lib/Cake/View/ThemeView.php b/lib/Cake/View/ThemeView.php index bd4cb885d6e..ed5a0e73bf4 100644 --- a/lib/Cake/View/ThemeView.php +++ b/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; + } } /**