Skip to content
Permalink
Browse files

Updating CacheHelper to use CakeRequest.

  • Loading branch information...
markstory committed May 14, 2010
1 parent 657073a commit 0d3011d2c3adbe9ecb9cdccf0d083440be626204
Showing with 32 additions and 30 deletions.
  1. +4 −3 cake/libs/view/helpers/cache.php
  2. +28 −27 cake/tests/cases/libs/view/helpers/cache.test.php
@@ -72,13 +72,13 @@ function cache($file, $out, $cache = false) {
$index = null; $index = null;
foreach ($keys as $action) { foreach ($keys as $action) {
if ($action == $this->params['action']) { if ($action == $this->request->params['action']) {
$index = $action; $index = $action;
break; break;
} }
} }
if (!isset($index) && $this->action == 'index') { if (!isset($index) && $this->request->params['action'] == 'index') {
$index = 'index'; $index = 'index';
} }
@@ -201,7 +201,7 @@ function __writeFile($content, $timestamp, $useCallbacks = false) {
} else { } else {
$cacheTime = strtotime($timestamp, $now); $cacheTime = strtotime($timestamp, $now);
} }
$path = $this->here; $path = $this->request->here;
if ($this->here == '/') { if ($this->here == '/') {
$path = 'home'; $path = 'home';
} }
@@ -231,6 +231,7 @@ function __writeFile($content, $timestamp, $useCallbacks = false) {
$controller->webroot = $this->webroot = \'' . $this->webroot . '\'; $controller->webroot = $this->webroot = \'' . $this->webroot . '\';
$controller->here = $this->here = \'' . $this->here . '\'; $controller->here = $this->here = \'' . $this->here . '\';
$controller->params = $this->params = unserialize(\'' . str_replace("'", "\\'", serialize($this->params)) . '\'); $controller->params = $this->params = unserialize(\'' . str_replace("'", "\\'", serialize($this->params)) . '\');
$controller->request = $this->request = unserialize(\'' . str_replace("'", "\\'", serialize($this->request)) . '\');
$controller->action = $this->action = unserialize(\'' . serialize($this->action) . '\'); $controller->action = $this->action = unserialize(\'' . serialize($this->action) . '\');
$controller->data = $this->data = unserialize(\'' . str_replace("'", "\\'", serialize($this->data)) . '\'); $controller->data = $this->data = unserialize(\'' . str_replace("'", "\\'", serialize($this->data)) . '\');
$controller->theme = $this->theme = \'' . $this->theme . '\'; $controller->theme = $this->theme = \'' . $this->theme . '\';
@@ -75,7 +75,8 @@ function skip() {
* @return void * @return void
*/ */
function setUp() { function setUp() {
$this->Controller = new CacheTestController(); $request = new CakeRequest();
$this->Controller = new CacheTestController($request);
$this->Cache = new CacheHelper(); $this->Cache = new CacheHelper();
$this->_cacheSettings = Configure::read('Cache'); $this->_cacheSettings = Configure::read('Cache');
Configure::write('Cache.check', true); Configure::write('Cache.check', true);
@@ -124,16 +125,16 @@ function tearDown() {
*/ */
function testLayoutCacheParsingNoTagsInView() { function testLayoutCacheParsingNoTagsInView() {
$this->Controller->cache_parsing(); $this->Controller->cache_parsing();
$this->Controller->params = array( $this->Controller->request->addParams(array(
'controller' => 'cache_test', 'controller' => 'cache_test',
'action' => 'cache_parsing', 'action' => 'cache_parsing',
'url' => array(), 'url' => array(),
'pass' => array(), 'pass' => array(),
'named' => array() 'named' => array()
); ));
$this->Controller->cacheAction = 21600; $this->Controller->cacheAction = 21600;
$this->Controller->here = '/cacheTest/cache_parsing'; $this->Controller->request->here = '/cacheTest/cache_parsing';
$this->Controller->action = 'cache_parsing'; $this->Controller->request->action = 'cache_parsing';
$View = new View($this->Controller); $View = new View($this->Controller);
$result = $View->render('index'); $result = $View->render('index');
@@ -159,15 +160,15 @@ function testLayoutCacheParsingNoTagsInView() {
*/ */
function testCacheNonLatinCharactersInRoute() { function testCacheNonLatinCharactersInRoute() {
$this->Controller->cache_parsing(); $this->Controller->cache_parsing();
$this->Controller->params = array( $this->Controller->request->addParams(array(
'controller' => 'cache_test', 'controller' => 'cache_test',
'action' => 'cache_parsing', 'action' => 'cache_parsing',
'url' => array(), 'url' => array(),
'pass' => array('風街ろまん'), 'pass' => array('風街ろまん'),
'named' => array() 'named' => array()
); ));
$this->Controller->cacheAction = 21600; $this->Controller->cacheAction = 21600;
$this->Controller->here = '/posts/view/風街ろまん'; $this->Controller->request->here = '/posts/view/風街ろまん';
$this->Controller->action = 'view'; $this->Controller->action = 'view';
$View = new View($this->Controller); $View = new View($this->Controller);
@@ -186,15 +187,15 @@ function testCacheNonLatinCharactersInRoute() {
*/ */
function testLayoutCacheParsingWithTagsInView() { function testLayoutCacheParsingWithTagsInView() {
$this->Controller->cache_parsing(); $this->Controller->cache_parsing();
$this->Controller->params = array( $this->Controller->request->addParams(array(
'controller' => 'cache_test', 'controller' => 'cache_test',
'action' => 'cache_parsing', 'action' => 'cache_parsing',
'url' => array(), 'url' => array(),
'pass' => array(), 'pass' => array(),
'named' => array() 'named' => array()
); ));
$this->Controller->cacheAction = 21600; $this->Controller->cacheAction = 21600;
$this->Controller->here = '/cacheTest/cache_parsing'; $this->Controller->request->here = '/cacheTest/cache_parsing';
$this->Controller->action = 'cache_parsing'; $this->Controller->action = 'cache_parsing';
$View = new View($this->Controller); $View = new View($this->Controller);
@@ -221,15 +222,15 @@ function testLayoutCacheParsingWithTagsInView() {
*/ */
function testMultipleNoCacheTagsInViewfile() { function testMultipleNoCacheTagsInViewfile() {
$this->Controller->cache_parsing(); $this->Controller->cache_parsing();
$this->Controller->params = array( $this->Controller->request->addParams(array(
'controller' => 'cache_test', 'controller' => 'cache_test',
'action' => 'cache_parsing', 'action' => 'cache_parsing',
'url' => array(), 'url' => array(),
'pass' => array(), 'pass' => array(),
'named' => array() 'named' => array()
); ));
$this->Controller->cacheAction = 21600; $this->Controller->cacheAction = 21600;
$this->Controller->here = '/cacheTest/cache_parsing'; $this->Controller->request->here = '/cacheTest/cache_parsing';
$this->Controller->action = 'cache_parsing'; $this->Controller->action = 'cache_parsing';
$View = new View($this->Controller); $View = new View($this->Controller);
@@ -253,15 +254,15 @@ function testMultipleNoCacheTagsInViewfile() {
*/ */
public function testComplexNoCache () { public function testComplexNoCache () {
$this->Controller->cache_parsing(); $this->Controller->cache_parsing();
$this->Controller->params = array( $this->Controller->request->addParams(array(
'controller' => 'cache_test', 'controller' => 'cache_test',
'action' => 'cache_complex', 'action' => 'cache_complex',
'url' => array(), 'url' => array(),
'pass' => array(), 'pass' => array(),
'named' => array() 'named' => array()
); ));
$this->Controller->cacheAction = array('cache_complex' => 21600); $this->Controller->cacheAction = array('cache_complex' => 21600);
$this->Controller->here = '/cacheTest/cache_complex'; $this->Controller->request->here = '/cacheTest/cache_complex';
$this->Controller->action = 'cache_complex'; $this->Controller->action = 'cache_complex';
$this->Controller->layout = 'multi_cache'; $this->Controller->layout = 'multi_cache';
$this->Controller->viewPath = 'posts'; $this->Controller->viewPath = 'posts';
@@ -314,17 +315,17 @@ public function testComplexNoCache () {
*/ */
function testCacheActionArray() { function testCacheActionArray() {
$this->Controller->cache_parsing(); $this->Controller->cache_parsing();
$this->Controller->params = array( $this->Controller->request->addParams(array(
'controller' => 'cache_test', 'controller' => 'cache_test',
'action' => 'cache_parsing', 'action' => 'cache_parsing',
'url' => array(), 'url' => array(),
'pass' => array(), 'pass' => array(),
'named' => array() 'named' => array()
); ));
$this->Controller->cacheAction = array( $this->Controller->cacheAction = array(
'cache_parsing' => 21600 'cache_parsing' => 21600
); );
$this->Controller->here = '/cache_test/cache_parsing'; $this->Controller->request->here = '/cache_test/cache_parsing';
$this->Controller->action = 'cache_parsing'; $this->Controller->action = 'cache_parsing';
$View = new View($this->Controller); $View = new View($this->Controller);
@@ -342,7 +343,7 @@ function testCacheActionArray() {
$this->Controller->cacheAction = array( $this->Controller->cacheAction = array(
'cache_parsing' => 21600 'cache_parsing' => 21600
); );
$this->Controller->here = '/cacheTest/cache_parsing'; $this->Controller->request->here = '/cacheTest/cache_parsing';
$this->Controller->action = 'cache_parsing'; $this->Controller->action = 'cache_parsing';
$View = new View($this->Controller); $View = new View($this->Controller);
@@ -357,17 +358,17 @@ function testCacheActionArray() {
$this->Controller->cache_parsing(); $this->Controller->cache_parsing();
$this->Controller->params = array( $this->Controller->request->addParams(array(
'controller' => 'cache_test', 'controller' => 'cache_test',
'action' => 'cache_parsing', 'action' => 'cache_parsing',
'url' => array(), 'url' => array(),
'pass' => array(), 'pass' => array(),
'named' => array() 'named' => array()
); ));
$this->Controller->cacheAction = array( $this->Controller->cacheAction = array(
'some_other_action' => 21600 'some_other_action' => 21600
); );
$this->Controller->here = '/cacheTest/cache_parsing'; $this->Controller->request->here = '/cacheTest/cache_parsing';
$this->Controller->action = 'cache_parsing'; $this->Controller->action = 'cache_parsing';
$View = new View($this->Controller); $View = new View($this->Controller);
@@ -390,18 +391,18 @@ function testCacheWithCustomRoutes() {
Router::connect('/:lang/:controller/:action/*', array(), array('lang' => '[a-z]{3}')); Router::connect('/:lang/:controller/:action/*', array(), array('lang' => '[a-z]{3}'));
$this->Controller->cache_parsing(); $this->Controller->cache_parsing();
$this->Controller->params = array( $this->Controller->request->addParams(array(
'lang' => 'en', 'lang' => 'en',
'controller' => 'cache_test', 'controller' => 'cache_test',
'action' => 'cache_parsing', 'action' => 'cache_parsing',
'url' => array(), 'url' => array(),
'pass' => array(), 'pass' => array(),
'named' => array() 'named' => array()
); ));
$this->Controller->cacheAction = array( $this->Controller->cacheAction = array(
'cache_parsing' => 21600 'cache_parsing' => 21600
); );
$this->Controller->here = '/en/cache_test/cache_parsing'; $this->Controller->request->here = '/en/cache_test/cache_parsing';
$this->Controller->action = 'cache_parsing'; $this->Controller->action = 'cache_parsing';
$View = new View($this->Controller); $View = new View($this->Controller);

0 comments on commit 0d3011d

Please sign in to comment.
You can’t perform that action at this time.