mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 09:06:17 +00:00
Fixing interaction between Model::_clearCache() and CacheHelper. Cached view files for camelCased controller or underscored URL's were not being cleared. Fixes #5611
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7783 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
b3a6a06f80
commit
5a2db7a5b4
4 changed files with 46 additions and 5 deletions
|
@ -2702,11 +2702,13 @@ class Model extends Overloadable {
|
|||
if ($type === null) {
|
||||
if (Configure::read('Cache.check') === true) {
|
||||
$assoc[] = strtolower(Inflector::pluralize($this->alias));
|
||||
$assoc[] = strtolower(Inflector::underscore(Inflector::pluralize($this->alias)));
|
||||
foreach ($this->__associations as $key => $association) {
|
||||
foreach ($this->$association as $key => $className) {
|
||||
$check = strtolower(Inflector::pluralize($className['className']));
|
||||
if (!in_array($check, $assoc)) {
|
||||
$assoc[] = strtolower(Inflector::pluralize($className['className']));
|
||||
$assoc[] = strtolower(Inflector::underscore(Inflector::pluralize($className['className'])));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -236,7 +236,7 @@ class CacheHelper extends AppHelper {
|
|||
if ($this->here == '/') {
|
||||
$path = 'home';
|
||||
}
|
||||
$cache = Inflector::slug($path);
|
||||
$cache = strtolower(Inflector::slug($path));
|
||||
|
||||
if (empty($cache)) {
|
||||
return;
|
||||
|
|
|
@ -2892,6 +2892,45 @@ class ModelTest extends CakeTestCase {
|
|||
);
|
||||
$this->assertEqual($result['Monkey'], $expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* test that Caches are getting cleared on save().
|
||||
* ensure that both inflections of controller names are getting cleared
|
||||
* as url for controller could be either overallFavorites/index or overall_favorites/index
|
||||
*
|
||||
* @return void
|
||||
**/
|
||||
function testCacheClearOnSave() {
|
||||
$_back = array(
|
||||
'check' => Configure::read('Cache.check'),
|
||||
'disable' => Configure::read('Cache.disable'),
|
||||
);
|
||||
Configure::write('Cache.check', true);
|
||||
Configure::write('Cache.disable', false);
|
||||
|
||||
$this->loadFixtures('OverallFavorite');
|
||||
$OverallFavorite =& new OverallFavorite();
|
||||
|
||||
touch(CACHE . 'views' . DS . 'some_dir_overallfavorites_index.php');
|
||||
touch(CACHE . 'views' . DS . 'some_dir_overall_favorites_index.php');
|
||||
|
||||
$data = array(
|
||||
'OverallFavorite' => array(
|
||||
'model_type' => '8-track',
|
||||
'model_id' => '3',
|
||||
'priority' => '1'
|
||||
)
|
||||
);
|
||||
$OverallFavorite->create($data);
|
||||
$OverallFavorite->save();
|
||||
|
||||
$this->assertFalse(file_exists(CACHE . 'views' . DS . 'some_dir_overallfavorites_index.php'));
|
||||
$this->assertFalse(file_exists(CACHE . 'views' . DS . 'some_dir_overall_favorites_index.php'));
|
||||
|
||||
Configure::write('Cache.check', $_back['check']);
|
||||
Configure::write('Cache.disable', $_back['disable']);
|
||||
}
|
||||
|
||||
/**
|
||||
* testSaveAll method
|
||||
*
|
||||
|
|
|
@ -105,7 +105,7 @@ class CacheHelperTest extends CakeTestCase {
|
|||
$this->assertNoPattern('/cake:nocache/', $result);
|
||||
$this->assertNoPattern('/php echo/', $result);
|
||||
|
||||
$filename = CACHE . 'views' . DS . 'cacheTest_cache_parsing.php';
|
||||
$filename = CACHE . 'views' . DS . 'cachetest_cache_parsing.php';
|
||||
$this->assertTrue(file_exists($filename));
|
||||
|
||||
$contents = file_get_contents($filename);
|
||||
|
@ -131,7 +131,7 @@ class CacheHelperTest extends CakeTestCase {
|
|||
$this->assertNoPattern('/cake:nocache/', $result);
|
||||
$this->assertNoPattern('/php echo/', $result);
|
||||
|
||||
$filename = CACHE . 'views' . DS . 'cacheTest_cache_parsing.php';
|
||||
$filename = CACHE . 'views' . DS . 'cachetest_cache_parsing.php';
|
||||
$this->assertTrue(file_exists($filename));
|
||||
|
||||
$contents = file_get_contents($filename);
|
||||
|
@ -175,7 +175,7 @@ class CacheHelperTest extends CakeTestCase {
|
|||
//$this->assertNoPattern('/6\. in element with no cache tags/', $result);
|
||||
$this->assertNoPattern('/7\. layout after content and after element with no cache tags/', $result);
|
||||
|
||||
$filename = CACHE . 'views' . DS . 'cacheTest_cache_complex.php';
|
||||
$filename = CACHE . 'views' . DS . 'cachetest_cache_complex.php';
|
||||
$this->assertTrue(file_exists($filename));
|
||||
$contents = file_get_contents($filename);
|
||||
@unlink($filename);
|
||||
|
@ -220,7 +220,7 @@ class CacheHelperTest extends CakeTestCase {
|
|||
'cached count is: 3\s*' .
|
||||
'</body>@', $result);
|
||||
|
||||
$filename = CACHE . 'views' . DS . 'cacheTest_cache_empty_sections.php';
|
||||
$filename = CACHE . 'views' . DS . 'cachetest_cache_empty_sections.php';
|
||||
$this->assertTrue(file_exists($filename));
|
||||
$contents = file_get_contents($filename);
|
||||
$this->assertNoPattern('/cake:nocache/', $contents);
|
||||
|
|
Loading…
Add table
Reference in a new issue