Skip to content
Permalink
Browse files

Fixing CacheHelper and multiple cake:nocache tags in a view file, bre…

…aking cake:nocache following $content_for_layout. Fixes #136
  • Loading branch information...
markstory committed Oct 1, 2009
1 parent 347c175 commit f12cbdba380479b96bb842c11e6e8f250e584728
@@ -156,27 +156,30 @@ function __parseFile($file, $cache) {
} elseif ($file = fileExistsInPath($file)) {
$file = file_get_contents($file);
}
preg_match_all('/(<cake:nocache>(?<=<cake:nocache>)[\\s\\S]*?(?=<\/cake:nocache>)<\/cake:nocache>)/i', $cache, $oresult, PREG_PATTERN_ORDER);
preg_match_all('/(?<=<cake:nocache>)([\\s\\S]*?)(?=<\/cake:nocache>)/i', $file, $result, PREG_PATTERN_ORDER);
preg_match_all('/(<cake:nocache>(?<=<cake:nocache>)[\\s\\S]*?(?=<\/cake:nocache>)<\/cake:nocache>)/i', $cache, $outputResult, PREG_PATTERN_ORDER);
preg_match_all('/(?<=<cake:nocache>)([\\s\\S]*?)(?=<\/cake:nocache>)/i', $file, $fileResult, PREG_PATTERN_ORDER);
$fileResult = $fileResult[0];
$outputResult = $outputResult[0];
if (!empty($this->__replace)) {
foreach ($oresult['0'] as $k => $element) {
foreach ($outputResult as $i => $element) {
$index = array_search($element, $this->__match);
if ($index !== false) {
array_splice($oresult[0], $k, 1);
unset($outputResult[$i]);
}
}
$outputResult = array_values($outputResult);
}
if (!empty($result['0'])) {
$count = 0;
foreach ($result['0'] as $block) {
if (isset($oresult['0'][$count])) {
$this->__replace[] = $block;
$this->__match[] = $oresult['0'][$count];
if (!empty($fileResult)) {
$i = 0;
foreach ($fileResult as $cacheBlock) {
if (isset($outputResult[$i])) {
$this->__replace[] = $cacheBlock;
$this->__match[] = $outputResult[$i];
}
$count++;
$i++;
}
}
}
@@ -62,6 +62,8 @@ function cache_parsing() {
$this->layout = 'cache_layout';
$this->set('variable', 'variableValue');
$this->set('superman', 'clark kent');
$this->set('batman', 'bruce wayne');
$this->set('spiderman', 'peter parker');
}
}
/**
@@ -162,7 +164,33 @@ function testLayoutCacheParsingWithTagsInView() {
$this->assertPattern('/if \(is_writable\(TMP\)\)\:/', $contents);
$this->assertPattern('/php echo \$variable/', $contents);
$this->assertPattern('/php echo microtime()/', $contents);
$this->assertNoPattern('/cake:nocache/', $contents);
@unlink($filename);
}
/**
* test that multiple <cake:nocache> tags function with multiple nocache tags in the layout.
*
* @return void
**/
function testMultipleNoCacheTagsInViewfile() {
$this->Controller->cache_parsing();
$this->Controller->cacheAction = 21600;
$this->Controller->here = '/cacheTest/cache_parsing';
$this->Controller->action = 'cache_parsing';
$View = new View($this->Controller);
$result = $View->render('multiple_nocache');
$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->assertNoPattern('/cake:nocache/', $contents);
@unlink($filename);
}
/**
@@ -0,0 +1,15 @@
--view start--
<cake:nocache>
<?php echo $batman ?>
</cake:nocache>

this view has 3 nocache blocks

<cake:nocache>
<?php echo $spiderman; ?>
</cake:nocache>

<cake:nocache>
<?php echo 'some string'; ?>
</cake:nocache>
--view end--

0 comments on commit f12cbdb

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