Skip to content
Browse files

Fixing issue where an app that was in a directory that had the same name

as a controller would end up failing to find view cache files.
Adding test for app name in controller name failure to create cache
Fixes #1025
  • Loading branch information...
1 parent ea92924 commit 96e636d0b434224a5bc7a6b85c1a9573765d0dfc @markstory markstory committed
Showing with 32 additions and 1 deletion.
  1. +2 −1 cake/libs/view/helpers/cache.php
  2. +30 −0 cake/tests/cases/libs/view/helpers/cache.test.php
View
3 cake/libs/view/helpers/cache.php
@@ -72,7 +72,8 @@ function cache($file, $out, $cache = false) {
$check = str_replace('/', '_', $this->here);
$basePath = str_replace('/', '_', $this->base);
- $match = str_replace($this->base, '', $this->here);
+ $search = '/' . preg_quote($this->base, '/') . '/';
+ $match = preg_replace($search, '', $this->here, 1);
$match = str_replace('//', '/', $match);
$match = str_replace('/' . $controller . '/', '', $match);
$match = str_replace('/' . $controllerAlternate . '/', '', $match);
View
30 cake/tests/cases/libs/view/helpers/cache.test.php
@@ -316,6 +316,36 @@ function testCacheActionArray() {
$filename = CACHE . 'views' . DS . 'cachetest_cache_parsing.php';
$this->assertFalse(file_exists($filename));
}
+
+/**
+ * test ControllerName contains AppName
+ *
+ * This test verifys view cache is created correctly when the app name is contained in part of the controller name.
+ * (webapp Name) base name is 'cache' controller is 'cacheTest' action is 'cache_name'
+ * apps url would look somehing like http://localhost/cache/cacheTest/cache_name
+ *
+ * @return void
+ **/
+ function testCacheBaseNameControllerName() {
+ $this->Controller->cache_parsing();
+ $this->Controller->cacheAction = array(
+ 'cache_name' => 21600
+ );
+ $this->Controller->here = '/cache/cacheTest/cache_name';
+ $this->Controller->action = 'cache_name';
+ $this->Controller->base = '/cache';
+
+ $View = new View($this->Controller);
+ $result = $View->render('index');
+
+ $this->assertNoPattern('/cake:nocache/', $result);
+ $this->assertNoPattern('/php echo/', $result);
+
+ $filename = CACHE . 'views' . DS . 'cache_cachetest_cache_name.php';
+ $this->assertTrue(file_exists($filename));
+ @unlink($filename);
+ }
+
/**
* testCacheEmptySections method
*

0 comments on commit 96e636d

Please sign in to comment.
Something went wrong with that request. Please try again.