Permalink
Browse files

Passing viewVars to cache views, avoiding cake:nocache problems.

  • Loading branch information...
1 parent 7416e58 commit a7c7436d8ec758795e0cf38b6062befd12933134 @jrbasso jrbasso committed Dec 18, 2010
Showing with 39 additions and 0 deletions.
  1. +2 −0 cake/libs/view/helpers/cache.php
  2. +1 −0 cake/libs/view/view.php
  3. +36 −0 cake/tests/cases/libs/view/helpers/cache.test.php
@@ -233,6 +233,7 @@ function __writeFile($content, $timestamp, $useCallbacks = false) {
$controller->params = $this->params = unserialize(stripslashes(\'' . addslashes(serialize($this->params)) . '\'));
$controller->action = $this->action = unserialize(\'' . serialize($this->action) . '\');
$controller->data = $this->data = unserialize(stripslashes(\'' . addslashes(serialize($this->data)) . '\'));
+ $controller->viewVars = $this->viewVars = unserialize(stripslashes(\'' . addslashes(serialize($this->viewVars)) . '\'));
$controller->theme = $this->theme = \'' . $this->theme . '\';
Router::setRequestInfo(array($this->params, array(\'base\' => $this->base, \'webroot\' => $this->webroot)));';
@@ -253,6 +254,7 @@ function __writeFile($content, $timestamp, $useCallbacks = false) {
$this->loaded[$camelBackedHelper] =& ${$camelBackedHelper};
$this->{$helper} =& $loadedHelpers[$helper];
}
+ extract($this->viewVars, EXTR_SKIP);
?>';
$content = preg_replace("/(<\\?xml)/", "<?php echo '$1';?>",$content);
$file .= $content;
View
@@ -751,6 +751,7 @@ function _render($___viewFn, $___dataForView, $loadHelpers = true, $cached = fal
$cache->controllerName = $this->name;
$cache->layout = $this->layout;
$cache->cacheAction = $this->cacheAction;
+ $cache->viewVars = $this->viewVars;
$cache->cache($___viewFn, $out, $cached);
}
}
@@ -308,6 +308,42 @@ function testComplexNoCache () {
$this->assertPattern('/7\. layout after content and after element with no cache tags/', $contents);
}
+/**
+ * test cache of view vars
+ *
+ * @access public
+ * @return void
+ */
+ function testCacheViewVars() {
+ $this->Controller->cache_parsing();
+ $this->Controller->params = array(
+ 'controller' => 'cache_test',
+ 'action' => 'cache_parsing',
+ 'url' => array(),
+ 'pass' => array(),
+ 'named' => array()
+ );
+ $this->Controller->cacheAction = 21600;
+ $this->Controller->here = '/cacheTest/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 . 'cachetest_cache_parsing.php';
+ $this->assertTrue(file_exists($filename));
+
+ $contents = file_get_contents($filename);
+ $this->assertPattern('/\$this\-\>viewVars.*variable/', $contents);
+ $this->assertPattern('/extract\(\$this\-\>viewVars, EXTR_SKIP\);/', $contents);
+ $this->assertPattern('/php echo \$variable/', $contents);
+ $this->assertPattern('/variableValue/', $contents);
+
+ @unlink($filename);
+ }
+
/**
* test cacheAction set to a boolean
*

0 comments on commit a7c7436

Please sign in to comment.