diff --git a/cake/libs/view/helpers/cache.php b/cake/libs/view/helpers/cache.php index 60c1a9eae..59baef793 100644 --- a/cake/libs/view/helpers/cache.php +++ b/cake/libs/view/helpers/cache.php @@ -70,19 +70,15 @@ class CacheHelper extends AppHelper { $check = Inflector::slug(Router::reverse($this->params)); $base = trim(str_replace('/', '_', $this->base), '_'); $check = trim(str_replace($base, '', $check), '_'); - $match = $check; - $keys = str_replace('/', '_', array_keys($this->cacheAction)); - $found = array_keys($this->cacheAction); + $keys = array_keys($this->cacheAction); $index = null; - $count = 0; - foreach ($keys as $key => $value) { - if (strpos($check, rtrim($value, '_')) !== false) { - $index = $found[$count]; + foreach ($keys as $action) { + if ($action == $this->params['action']) { + $index = $action; break; } - $count++; } if (!isset($index) && $this->action == 'index') { @@ -92,19 +88,17 @@ class CacheHelper extends AppHelper { $options = $this->cacheAction; if (isset($this->cacheAction[$index])) { if (is_array($this->cacheAction[$index])) { - $options = array_merge(array('duration'=> 0, 'callbacks' => false), $this->cacheAction[$index]); + $options = array_merge(array('duration' => 0, 'callbacks' => false), $this->cacheAction[$index]); } else { $cacheTime = $this->cacheAction[$index]; } } - - if (array_key_exists('duration', $options)) { + if (isset($options['duration'])) { $cacheTime = $options['duration']; } - if (array_key_exists('callbacks', $options)) { + if (isset($options['callbacks'])) { $useCallbacks = $options['callbacks']; } - } else { $cacheTime = $this->cacheAction; } diff --git a/cake/tests/cases/libs/view/helpers/cache.test.php b/cake/tests/cases/libs/view/helpers/cache.test.php index 3cc5966c6..d804e2f1d 100644 --- a/cake/tests/cases/libs/view/helpers/cache.test.php +++ b/cake/tests/cases/libs/view/helpers/cache.test.php @@ -17,9 +17,6 @@ * @since CakePHP(tm) v 1.2.0.4206 * @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License */ -if (!defined('CAKEPHP_UNIT_TEST_EXECUTION')) { - define('CAKEPHP_UNIT_TEST_EXECUTION', 1); -} App::import('Core', array('Controller', 'Model', 'View')); App::import('Helper', 'Cache'); @@ -344,7 +341,7 @@ class CacheHelperTest extends CakeTestCase { $this->Controller->cache_parsing(); $this->Controller->cacheAction = array( - 'cache_parsing/' => 21600 + 'cache_parsing' => 21600 ); $this->Controller->here = '/cacheTest/cache_parsing'; $this->Controller->action = 'cache_parsing'; @@ -360,30 +357,6 @@ class CacheHelperTest extends CakeTestCase { @unlink($filename); - $this->Controller->cache_parsing(); - $this->Controller->params = array( - 'controller' => 'cache_test', - 'action' => 'cache_parsing', - 'url' => array(), - 'pass' => array(33), - 'named' => array() - ); - $this->Controller->cacheAction = array( - 'cache_parsing/33' => 21600 - ); - $this->Controller->here = '/cacheTest/cache_parsing/33'; - $this->Controller->action = 'cache_parsing'; - - $View = new View($this->Controller); - $result = $View->render('index'); - - $this->assertNoPattern('/cake:nocache/', $result); - $this->assertNoPattern('/php echo/', $result); - - $filename = CACHE . 'views' . DS . 'cachetest_cache_parsing_33.php'; - $this->assertTrue(file_exists($filename)); - @unlink($filename); - $this->Controller->cache_parsing(); $this->Controller->params = array( 'controller' => 'cache_test', @@ -393,7 +366,7 @@ class CacheHelperTest extends CakeTestCase { 'named' => array() ); $this->Controller->cacheAction = array( - 'cache_parsing/33' => 21600 + 'some_other_action' => 21600 ); $this->Controller->here = '/cacheTest/cache_parsing'; $this->Controller->action = 'cache_parsing'; @@ -416,7 +389,31 @@ class CacheHelperTest extends CakeTestCase { function testCacheWithCustomRoutes() { Router::reload(); Router::connect('/:lang/:controller/:action/*', array(), array('lang' => '[a-z]{3}')); + + $this->Controller->cache_parsing(); + $this->Controller->params = array( + 'lang' => 'en', + 'controller' => 'cache_test', + 'action' => 'cache_parsing', + 'url' => array(), + 'pass' => array(), + 'named' => array() + ); + $this->Controller->cacheAction = array( + 'cache_parsing' => 21600 + ); + $this->Controller->here = '/en/cache_test/cache_parsing'; + $this->Controller->action = 'cache_parsing'; + $View = new View($this->Controller); + $result = $View->render('index'); + + $this->assertNoPattern('/cake:nocache/', $result); + $this->assertNoPattern('/php echo/', $result); + + $filename = CACHE . 'views' . DS . 'en_cache_test_cache_parsing.php'; + $this->assertTrue(file_exists($filename)); + @unlink($filename); } /** * testCacheEmptySections method