diff --git a/cake/libs/view/view.php b/cake/libs/view/view.php index 276265515b6..6702ca0b8a4 100644 --- a/cake/libs/view/view.php +++ b/cake/libs/view/view.php @@ -163,7 +163,7 @@ class View extends Object { * @access public */ var $subDir = null; - + /** * Theme name. * @@ -357,9 +357,11 @@ function element($name, $params = array(), $loadHelpers = false) { if (is_array($params['cache'])) { $expires = $params['cache']['time']; $key = Inflector::slug($params['cache']['key']); - } elseif ($params['cache'] !== true) { - $expires = $params['cache']; + } else { $key = implode('_', array_keys($params)); + if ($params['cache'] !== true) { + $expires = $params['cache']; + } } if ($expires) { @@ -503,7 +505,7 @@ function renderLayout($content_for_layout, $layout = null) { } /** - * Fire a callback on all loaded Helpers. All helpers must implement this method, + * Fire a callback on all loaded Helpers. All helpers must implement this method, * it is not checked before being called. You can add additional helper callbacks in AppHelper. * * @param string $callback name of callback fire. @@ -526,7 +528,7 @@ function _triggerHelpers($callback) { } /** - * Render cached view. Works in concert with CacheHelper and Dispatcher to + * Render cached view. Works in concert with CacheHelper and Dispatcher to * render cached view files. * * @param string $filename the cache file to include @@ -866,7 +868,7 @@ function _getViewFileName($name = null) { } } $paths = $this->_paths(Inflector::underscore($this->plugin)); - + $exts = $this->_getExtensions(); foreach ($exts as $ext) { foreach ($paths as $path) { diff --git a/cake/tests/cases/libs/view/view.test.php b/cake/tests/cases/libs/view/view.test.php index 5b3d1cf5cfa..da1f136a674 100644 --- a/cake/tests/cases/libs/view/view.test.php +++ b/cake/tests/cases/libs/view/view.test.php @@ -474,10 +474,10 @@ function testAddInlineScripts() { function testElement() { $result = $this->View->element('test_element'); $this->assertEqual($result, 'this is the test element'); - + $result = $this->View->element('plugin_element', array('plugin' => 'test_plugin')); $this->assertEqual($result, 'this is the plugin element using params[plugin]'); - + $this->View->plugin = 'test_plugin'; $result = $this->View->element('test_plugin_element'); $this->assertEqual($result, 'this is the test set using View::$plugin plugin element'); @@ -557,6 +557,14 @@ function testElementCache() { } $this->assertTrue($cached); + $cached = false; + $result = $View->element($element, array('cache' => true, 'param' => 'val')); + if (file_exists(CACHE . 'views' . DS . 'element_cache_param_'.$element)) { + $cached = true; + unlink(CACHE . 'views' . DS . 'element_cache_param_'.$element); + } + $this->assertTrue($cached); + $cached = false; $result = $View->element($element, array('cache'=>'+1 second', 'other_param'=> true, 'anotherParam'=> true)); if (file_exists(CACHE . 'views' . DS . 'element_cache_other_param_anotherParam_'.$element)) { @@ -947,7 +955,7 @@ function testSet() { $View->set(array('key3' => 'value3')); $this->assertIdentical($View->getVar('key3'), 'value3'); - + $View->viewVars = array(); $View->set(array(3 => 'three', 4 => 'four')); $View->set(array(1 => 'one', 2 => 'two')); @@ -970,7 +978,7 @@ function testEntityReference() { $View->association = 'Comment'; $View->field = 'user_id'; $this->assertEqual($View->entity(), array('Comment', 'user_id')); - + $View->model = 0; $View->association = null; $View->field = 'Node'; @@ -978,7 +986,7 @@ function testEntityReference() { $View->entityPath = '0.Node.title'; $expected = array(0, 'Node', 'title'); $this->assertEqual($View->entity(), $expected); - + $View->model = 'HelperTestTag'; $View->field = 'HelperTestTag'; $View->modelId = null;