mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
Adding test layout with cake:nocache tags.
Adding tests to CacheHelper Fixing CacheHelper not parsing cake:nocache after $content_for_layout when view file has cake:nocache tags as well. Closes #5275 git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7560 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
f96f7f0926
commit
e5cfd69636
3 changed files with 158 additions and 15 deletions
|
@ -163,12 +163,20 @@ class CacheHelper extends AppHelper {
|
|||
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);
|
||||
|
||||
if (!empty($result['0'])) {
|
||||
$count = 0;
|
||||
if (!empty($this->__replace)) {
|
||||
foreach ($oresult['0'] as $k => $element) {
|
||||
$index = array_search($element, $this->__match);
|
||||
if ($index !== false) {
|
||||
array_splice($oresult[0], $k, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($result['0'] as $result) {
|
||||
if (!empty($result['0'])) {
|
||||
$count = 0;
|
||||
foreach ($result['0'] as $block) {
|
||||
if (isset($oresult['0'][$count])) {
|
||||
$this->__replace[] = $result;
|
||||
$this->__replace[] = $block;
|
||||
$this->__match[] = $oresult['0'][$count];
|
||||
}
|
||||
$count++;
|
||||
|
|
|
@ -31,22 +31,41 @@ if (!defined('CAKEPHP_UNIT_TEST_EXECUTION')) {
|
|||
}
|
||||
App::import('Core', array('Controller', 'Model', 'View'));
|
||||
App::import('Helper', 'Cache');
|
||||
|
||||
/**
|
||||
* Short description for class.
|
||||
* Test Cache Helper
|
||||
*
|
||||
* @package cake.tests
|
||||
* @subpackage cake.tests.cases.libs.view.helpers
|
||||
*/
|
||||
class TestCacheHelper extends CacheHelper {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test Cache Helper
|
||||
*
|
||||
* @package cake.tests
|
||||
* @subpackage cake.tests.cases.libs.view.helpers
|
||||
*/
|
||||
class CacheTestController extends Controller {
|
||||
var $helpers = array('Html', 'Cache');
|
||||
|
||||
function cache_parsing() {
|
||||
$this->viewPath = 'posts';
|
||||
$this->layout = 'cache_layout';
|
||||
$this->set('variable', 'variableValue');
|
||||
$this->set('superman', 'clark kent');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Cache Helper Test Case
|
||||
*
|
||||
* @package cake.tests
|
||||
* @subpackage cake.tests.cases.libs.view.helpers
|
||||
*/
|
||||
class CacheHelperTest extends CakeTestCase {
|
||||
/**
|
||||
* skip method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function skip() {
|
||||
$this->skipif (true, 'CacheHelper test not implemented');
|
||||
}
|
||||
/**
|
||||
* setUp method
|
||||
*
|
||||
|
@ -54,7 +73,82 @@ class CacheHelperTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
function setUp() {
|
||||
$this->Cache = new CacheHelper();
|
||||
$this->Controller = new CacheTestController();
|
||||
$this->Cache = new TestCacheHelper();
|
||||
Configure::write('Cache.check', true);
|
||||
Configure::write('Cache.disable', false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Start Case - switch view paths
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function startCase() {
|
||||
$this->_viewPaths = Configure::read('viewPaths');
|
||||
Configure::write('viewPaths', array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS));
|
||||
}
|
||||
|
||||
/**
|
||||
* test cache parsing with no cake:nocache tags in view file.
|
||||
*
|
||||
*/
|
||||
function xxtestLayoutCacheParsingNoTagsInView() {
|
||||
$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('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('/php echo \$variable/', $contents);
|
||||
$this->assertPattern('/php echo microtime()/', $contents);
|
||||
$this->assertPattern('/clark kent/', $result);
|
||||
|
||||
@unlink($filename);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test cache parsing with cake:nocache tags in view file.
|
||||
*
|
||||
*/
|
||||
function testLayoutCacheParsingWithTagsInView() {
|
||||
$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('test_nocache_tags');
|
||||
$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('/if \(is_writable\(TMP\)\)\:/', $contents);
|
||||
$this->assertPattern('/php echo \$variable/', $contents);
|
||||
$this->assertPattern('/php echo microtime()/', $contents);
|
||||
|
||||
@unlink($filename);
|
||||
}
|
||||
/**
|
||||
* End Case - restore view Paths
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function endCase() {
|
||||
Configure::write('viewPaths', $this->_viewPaths);
|
||||
}
|
||||
/**
|
||||
* tearDown method
|
||||
|
|
41
cake/tests/test_app/views/layouts/cache_layout.ctp
Normal file
41
cake/tests/test_app/views/layouts/cache_layout.ctp
Normal file
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
/* SVN FILE: $Id$ */
|
||||
/**
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework <http://www.cakephp.org/>
|
||||
* Copyright 2005-2008, Cake Software Foundation, Inc.
|
||||
* 1785 E. Sahara Avenue, Suite 490-204
|
||||
* Las Vegas, Nevada 89104
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @filesource
|
||||
* @copyright Copyright 2005-2008, Cake Software Foundation, Inc.
|
||||
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
|
||||
* @package cake
|
||||
* @subpackage cake.cake.libs.view.templates.layouts
|
||||
* @since CakePHP(tm) v 0.10.0.1076
|
||||
* @version $Revision$
|
||||
* @modifiedby $LastChangedBy$
|
||||
* @lastmodified $Date$
|
||||
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
||||
*/
|
||||
?>
|
||||
<p>This is regular text</p>
|
||||
<cake:nocache>
|
||||
<?php echo microtime(); ?>
|
||||
</cake:nocache>
|
||||
|
||||
<?php echo $content_for_layout; ?>
|
||||
|
||||
<?php echo $superman; ?>
|
||||
|
||||
<cake:nocache>
|
||||
<?php echo $variable; ?>
|
||||
</cake:nocache>
|
||||
<p>Additional regular text.</p>
|
||||
|
||||
|
Loading…
Reference in a new issue