Skip to content

Commit

Permalink
Element cache filename now properly includes extra param names passed…
Browse files Browse the repository at this point in the history
… along with 'cache' => true option. Fixes #2356
  • Loading branch information
ADmad committed Dec 9, 2011
1 parent 6836ce5 commit 850a33d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
14 changes: 8 additions & 6 deletions cake/libs/view/view.php
Expand Up @@ -163,7 +163,7 @@ class View extends Object {
* @access public
*/
var $subDir = null;

/**
* Theme name.
*
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
18 changes: 13 additions & 5 deletions cake/tests/cases/libs/view/view.test.php
Expand Up @@ -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');
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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'));
Expand All @@ -970,15 +978,15 @@ 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';
$View->fieldSuffix = 'title';
$View->entityPath = '0.Node.title';
$expected = array(0, 'Node', 'title');
$this->assertEqual($View->entity(), $expected);

$View->model = 'HelperTestTag';
$View->field = 'HelperTestTag';
$View->modelId = null;
Expand Down

0 comments on commit 850a33d

Please sign in to comment.