2008-05-30 11:40:08 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2009-03-19 21:10:13 +00:00
|
|
|
* CacheHelperTest file
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
|
|
|
* PHP versions 4 and 5
|
|
|
|
*
|
|
|
|
* CakePHP(tm) Tests <https://trac.cakephp.org/wiki/Developement/TestSuite>
|
2010-01-26 19:18:20 +00:00
|
|
|
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
|
|
|
* Licensed under The Open Group Test Suite License
|
|
|
|
* Redistributions of files must retain the above copyright notice.
|
|
|
|
*
|
2010-01-26 19:18:20 +00:00
|
|
|
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2008-10-30 17:30:26 +00:00
|
|
|
* @link https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests
|
2009-03-19 21:10:13 +00:00
|
|
|
* @package cake
|
2008-10-30 17:30:26 +00:00
|
|
|
* @subpackage cake.tests.cases.libs.view.helpers
|
|
|
|
* @since CakePHP(tm) v 1.2.0.4206
|
|
|
|
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2008-07-21 02:40:58 +00:00
|
|
|
App::import('Core', array('Controller', 'Model', 'View'));
|
|
|
|
App::import('Helper', 'Cache');
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2009-03-19 21:10:13 +00:00
|
|
|
* CacheTestController class
|
2008-09-05 21:41:07 +00:00
|
|
|
*
|
2009-03-19 21:10:13 +00:00
|
|
|
* @package cake
|
2008-10-30 17:30:26 +00:00
|
|
|
* @subpackage cake.tests.cases.libs.view.helpers
|
2008-09-05 21:41:07 +00:00
|
|
|
*/
|
|
|
|
class CacheTestController extends Controller {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-03-19 21:10:13 +00:00
|
|
|
/**
|
|
|
|
* helpers property
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
* @access public
|
|
|
|
*/
|
2008-09-05 21:41:07 +00:00
|
|
|
var $helpers = array('Html', 'Cache');
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-03-19 21:10:13 +00:00
|
|
|
/**
|
|
|
|
* cache_parsing method
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-09-05 21:41:07 +00:00
|
|
|
function cache_parsing() {
|
|
|
|
$this->viewPath = 'posts';
|
|
|
|
$this->layout = 'cache_layout';
|
|
|
|
$this->set('variable', 'variableValue');
|
|
|
|
$this->set('superman', 'clark kent');
|
2009-10-01 05:03:47 +00:00
|
|
|
$this->set('batman', 'bruce wayne');
|
|
|
|
$this->set('spiderman', 'peter parker');
|
2008-09-05 21:41:07 +00:00
|
|
|
}
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-09-05 21:41:07 +00:00
|
|
|
/**
|
2009-03-19 21:10:13 +00:00
|
|
|
* CacheHelperTest class
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2009-03-19 21:10:13 +00:00
|
|
|
* @package cake
|
2008-10-30 17:30:26 +00:00
|
|
|
* @subpackage cake.tests.cases.libs.view.helpers
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2008-07-21 02:40:58 +00:00
|
|
|
class CacheHelperTest extends CakeTestCase {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-10-22 04:38:37 +00:00
|
|
|
/**
|
|
|
|
* Checks if TMP/views is writable, and skips the case if it is not.
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2009-10-22 04:38:37 +00:00
|
|
|
function skip() {
|
|
|
|
$this->skipUnless(is_writable(TMP . 'cache' . DS . 'views' . DS), 'TMP/views is not writable %s');
|
|
|
|
}
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
2008-09-05 21:41:07 +00:00
|
|
|
* setUp method
|
2008-09-10 16:48:43 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-09-05 21:41:07 +00:00
|
|
|
function setUp() {
|
|
|
|
$this->Controller = new CacheTestController();
|
2009-11-02 05:07:02 +00:00
|
|
|
$this->Cache = new CacheHelper();
|
|
|
|
$this->_cacheSettings = Configure::read('Cache');
|
2008-09-05 21:41:07 +00:00
|
|
|
Configure::write('Cache.check', true);
|
|
|
|
Configure::write('Cache.disable', false);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
2008-09-05 21:41:07 +00:00
|
|
|
* Start Case - switch view paths
|
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
2008-09-10 16:48:43 +00:00
|
|
|
*/
|
2008-09-05 21:41:07 +00:00
|
|
|
function startCase() {
|
2009-06-11 16:13:16 +00:00
|
|
|
App::build(array(
|
|
|
|
'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS)
|
2009-10-12 01:42:15 +00:00
|
|
|
), true);
|
2008-09-05 21:41:07 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-03-19 21:10:13 +00:00
|
|
|
/**
|
|
|
|
* End Case - restore view Paths
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function endCase() {
|
2009-06-11 16:13:16 +00:00
|
|
|
App::build();
|
2009-03-19 21:10:13 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-03-19 21:10:13 +00:00
|
|
|
/**
|
|
|
|
* tearDown method
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function tearDown() {
|
2009-07-26 01:27:02 +00:00
|
|
|
clearCache();
|
2009-03-19 21:10:13 +00:00
|
|
|
unset($this->Cache);
|
2009-11-02 05:07:02 +00:00
|
|
|
Configure::write('Cache', $this->_cacheSettings);
|
2009-03-19 21:10:13 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-09-05 21:41:07 +00:00
|
|
|
/**
|
|
|
|
* test cache parsing with no cake:nocache tags in view file.
|
|
|
|
*
|
2009-03-19 21:10:13 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2008-09-05 21:44:30 +00:00
|
|
|
function testLayoutCacheParsingNoTagsInView() {
|
2008-09-05 21:41:07 +00:00
|
|
|
$this->Controller->cache_parsing();
|
2009-12-28 18:38:36 +00:00
|
|
|
$this->Controller->params = array(
|
|
|
|
'controller' => 'cache_test',
|
|
|
|
'action' => 'cache_parsing',
|
|
|
|
'url' => array(),
|
|
|
|
'pass' => array(),
|
|
|
|
'named' => array()
|
|
|
|
);
|
2008-09-05 21:41:07 +00:00
|
|
|
$this->Controller->cacheAction = 21600;
|
|
|
|
$this->Controller->here = '/cacheTest/cache_parsing';
|
|
|
|
$this->Controller->action = 'cache_parsing';
|
2008-09-10 16:48:43 +00:00
|
|
|
|
2008-09-05 21:41:07 +00:00
|
|
|
$View = new View($this->Controller);
|
2008-09-10 16:48:43 +00:00
|
|
|
$result = $View->render('index');
|
2008-09-05 21:41:07 +00:00
|
|
|
$this->assertNoPattern('/cake:nocache/', $result);
|
|
|
|
$this->assertNoPattern('/php echo/', $result);
|
2008-09-10 16:48:43 +00:00
|
|
|
|
2008-10-26 18:51:38 +00:00
|
|
|
$filename = CACHE . 'views' . DS . 'cachetest_cache_parsing.php';
|
2008-09-05 21:41:07 +00:00
|
|
|
$this->assertTrue(file_exists($filename));
|
2008-09-10 16:48:43 +00:00
|
|
|
|
2008-09-05 21:41:07 +00:00
|
|
|
$contents = file_get_contents($filename);
|
|
|
|
$this->assertPattern('/php echo \$variable/', $contents);
|
|
|
|
$this->assertPattern('/php echo microtime()/', $contents);
|
|
|
|
$this->assertPattern('/clark kent/', $result);
|
2008-09-10 16:48:43 +00:00
|
|
|
|
2008-09-05 21:41:07 +00:00
|
|
|
@unlink($filename);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-09-05 21:41:07 +00:00
|
|
|
/**
|
2009-07-25 19:11:52 +00:00
|
|
|
* test cache parsing with non-latin characters in current route
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testCacheNonLatinCharactersInRoute() {
|
|
|
|
$this->Controller->cache_parsing();
|
2009-12-28 18:38:36 +00:00
|
|
|
$this->Controller->params = array(
|
|
|
|
'controller' => 'cache_test',
|
|
|
|
'action' => 'cache_parsing',
|
|
|
|
'url' => array(),
|
|
|
|
'pass' => array('風街ろまん'),
|
|
|
|
'named' => array()
|
|
|
|
);
|
2009-07-25 19:11:52 +00:00
|
|
|
$this->Controller->cacheAction = 21600;
|
|
|
|
$this->Controller->here = '/posts/view/風街ろまん';
|
|
|
|
$this->Controller->action = 'view';
|
|
|
|
|
|
|
|
$View = new View($this->Controller);
|
|
|
|
$result = $View->render('index');
|
|
|
|
|
|
|
|
$filename = CACHE . 'views' . DS . 'posts_view_風街ろまん.php';
|
|
|
|
$this->assertTrue(file_exists($filename));
|
|
|
|
|
|
|
|
@unlink($filename);
|
|
|
|
}
|
2008-09-05 21:41:07 +00:00
|
|
|
/**
|
|
|
|
* Test cache parsing with cake:nocache tags in view file.
|
|
|
|
*
|
2009-03-19 21:10:13 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
2008-09-05 21:41:07 +00:00
|
|
|
*/
|
|
|
|
function testLayoutCacheParsingWithTagsInView() {
|
|
|
|
$this->Controller->cache_parsing();
|
2009-12-28 18:38:36 +00:00
|
|
|
$this->Controller->params = array(
|
|
|
|
'controller' => 'cache_test',
|
|
|
|
'action' => 'cache_parsing',
|
|
|
|
'url' => array(),
|
|
|
|
'pass' => array(),
|
|
|
|
'named' => array()
|
|
|
|
);
|
2008-09-05 21:41:07 +00:00
|
|
|
$this->Controller->cacheAction = 21600;
|
|
|
|
$this->Controller->here = '/cacheTest/cache_parsing';
|
|
|
|
$this->Controller->action = 'cache_parsing';
|
2008-09-10 16:48:43 +00:00
|
|
|
|
2008-09-05 21:41:07 +00:00
|
|
|
$View = new View($this->Controller);
|
2008-09-10 16:48:43 +00:00
|
|
|
$result = $View->render('test_nocache_tags');
|
2008-09-05 21:41:07 +00:00
|
|
|
$this->assertNoPattern('/cake:nocache/', $result);
|
|
|
|
$this->assertNoPattern('/php echo/', $result);
|
|
|
|
|
2008-10-26 18:51:38 +00:00
|
|
|
$filename = CACHE . 'views' . DS . 'cachetest_cache_parsing.php';
|
2008-09-05 21:41:07 +00:00
|
|
|
$this->assertTrue(file_exists($filename));
|
2008-09-10 16:48:43 +00:00
|
|
|
|
2008-09-05 21:41:07 +00:00
|
|
|
$contents = file_get_contents($filename);
|
|
|
|
$this->assertPattern('/if \(is_writable\(TMP\)\)\:/', $contents);
|
|
|
|
$this->assertPattern('/php echo \$variable/', $contents);
|
|
|
|
$this->assertPattern('/php echo microtime()/', $contents);
|
2009-10-01 05:03:47 +00:00
|
|
|
$this->assertNoPattern('/cake:nocache/', $contents);
|
2008-09-10 16:48:43 +00:00
|
|
|
|
2008-09-05 21:41:07 +00:00
|
|
|
@unlink($filename);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-10-01 05:03:47 +00:00
|
|
|
/**
|
|
|
|
* test that multiple <cake:nocache> tags function with multiple nocache tags in the layout.
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2009-10-01 05:03:47 +00:00
|
|
|
function testMultipleNoCacheTagsInViewfile() {
|
|
|
|
$this->Controller->cache_parsing();
|
2009-12-28 18:38:36 +00:00
|
|
|
$this->Controller->params = array(
|
|
|
|
'controller' => 'cache_test',
|
|
|
|
'action' => 'cache_parsing',
|
|
|
|
'url' => array(),
|
|
|
|
'pass' => array(),
|
|
|
|
'named' => array()
|
|
|
|
);
|
2009-10-01 05:03:47 +00:00
|
|
|
$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);
|
|
|
|
}
|
2009-10-14 04:51:55 +00:00
|
|
|
|
2008-09-10 16:48:43 +00:00
|
|
|
/**
|
|
|
|
* testComplexNoCache method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
* @access public
|
|
|
|
*/
|
|
|
|
function testComplexNoCache () {
|
|
|
|
$this->Controller->cache_parsing();
|
2009-12-28 18:38:36 +00:00
|
|
|
$this->Controller->params = array(
|
|
|
|
'controller' => 'cache_test',
|
|
|
|
'action' => 'cache_complex',
|
|
|
|
'url' => array(),
|
|
|
|
'pass' => array(),
|
|
|
|
'named' => array()
|
|
|
|
);
|
2009-11-02 05:07:02 +00:00
|
|
|
$this->Controller->cacheAction = array('cache_complex' => 21600);
|
2008-09-10 16:48:43 +00:00
|
|
|
$this->Controller->here = '/cacheTest/cache_complex';
|
|
|
|
$this->Controller->action = 'cache_complex';
|
|
|
|
$this->Controller->layout = 'multi_cache';
|
|
|
|
$this->Controller->viewPath = 'posts';
|
|
|
|
|
|
|
|
$View = new View($this->Controller);
|
|
|
|
$result = $View->render('sequencial_nocache');
|
|
|
|
|
|
|
|
$this->assertNoPattern('/cake:nocache/', $result);
|
|
|
|
$this->assertNoPattern('/php echo/', $result);
|
|
|
|
$this->assertPattern('/A\. Layout Before Content/', $result);
|
|
|
|
$this->assertPattern('/B\. In Plain Element/', $result);
|
|
|
|
$this->assertPattern('/C\. Layout After Test Element/', $result);
|
|
|
|
$this->assertPattern('/D\. In View File/', $result);
|
|
|
|
$this->assertPattern('/E\. Layout After Content/', $result);
|
|
|
|
//$this->assertPattern('/F\. In Element With No Cache Tags/', $result);
|
|
|
|
$this->assertPattern('/G\. Layout After Content And After Element With No Cache Tags/', $result);
|
|
|
|
$this->assertNoPattern('/1\. layout before content/', $result);
|
|
|
|
$this->assertNoPattern('/2\. in plain element/', $result);
|
|
|
|
$this->assertNoPattern('/3\. layout after test element/', $result);
|
|
|
|
$this->assertNoPattern('/4\. in view file/', $result);
|
|
|
|
$this->assertNoPattern('/5\. layout after content/', $result);
|
|
|
|
//$this->assertNoPattern('/6\. in element with no cache tags/', $result);
|
|
|
|
$this->assertNoPattern('/7\. layout after content and after element with no cache tags/', $result);
|
|
|
|
|
2008-10-26 18:51:38 +00:00
|
|
|
$filename = CACHE . 'views' . DS . 'cachetest_cache_complex.php';
|
2008-09-10 16:48:43 +00:00
|
|
|
$this->assertTrue(file_exists($filename));
|
|
|
|
$contents = file_get_contents($filename);
|
|
|
|
@unlink($filename);
|
|
|
|
|
|
|
|
$this->assertPattern('/A\. Layout Before Content/', $contents);
|
|
|
|
$this->assertNoPattern('/B\. In Plain Element/', $contents);
|
|
|
|
$this->assertPattern('/C\. Layout After Test Element/', $contents);
|
|
|
|
$this->assertPattern('/D\. In View File/', $contents);
|
|
|
|
$this->assertPattern('/E\. Layout After Content/', $contents);
|
|
|
|
//$this->assertPattern('/F\. In Element With No Cache Tags/', $contents);
|
|
|
|
$this->assertPattern('/G\. Layout After Content And After Element With No Cache Tags/', $contents);
|
|
|
|
$this->assertPattern('/1\. layout before content/', $contents);
|
|
|
|
$this->assertNoPattern('/2\. in plain element/', $contents);
|
|
|
|
$this->assertPattern('/3\. layout after test element/', $contents);
|
|
|
|
$this->assertPattern('/4\. in view file/', $contents);
|
|
|
|
$this->assertPattern('/5\. layout after content/', $contents);
|
|
|
|
//$this->assertPattern('/6\. in element with no cache tags/', $contents);
|
|
|
|
$this->assertPattern('/7\. layout after content and after element with no cache tags/', $contents);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-11-02 05:07:02 +00:00
|
|
|
/**
|
|
|
|
* test cacheAction set to a boolean
|
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2009-11-02 05:07:02 +00:00
|
|
|
function testCacheActionArray() {
|
|
|
|
$this->Controller->cache_parsing();
|
2009-12-28 18:38:36 +00:00
|
|
|
$this->Controller->params = array(
|
|
|
|
'controller' => 'cache_test',
|
|
|
|
'action' => 'cache_parsing',
|
|
|
|
'url' => array(),
|
|
|
|
'pass' => array(),
|
|
|
|
'named' => array()
|
|
|
|
);
|
2009-11-02 05:07:02 +00:00
|
|
|
$this->Controller->cacheAction = array(
|
|
|
|
'cache_parsing' => 21600
|
|
|
|
);
|
|
|
|
$this->Controller->here = '/cache_test/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 . 'cache_test_cache_parsing.php';
|
|
|
|
$this->assertTrue(file_exists($filename));
|
|
|
|
@unlink($filename);
|
|
|
|
|
|
|
|
|
|
|
|
$this->Controller->cache_parsing();
|
|
|
|
$this->Controller->cacheAction = array(
|
2009-12-29 02:26:51 +00:00
|
|
|
'cache_parsing' => 21600
|
2009-11-02 05:07:02 +00:00
|
|
|
);
|
|
|
|
$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));
|
|
|
|
@unlink($filename);
|
|
|
|
|
|
|
|
|
|
|
|
$this->Controller->cache_parsing();
|
2009-12-28 18:38:36 +00:00
|
|
|
$this->Controller->params = array(
|
|
|
|
'controller' => 'cache_test',
|
|
|
|
'action' => 'cache_parsing',
|
|
|
|
'url' => array(),
|
2009-12-29 02:26:51 +00:00
|
|
|
'pass' => array(),
|
2009-12-28 18:38:36 +00:00
|
|
|
'named' => array()
|
|
|
|
);
|
2009-11-02 05:07:02 +00:00
|
|
|
$this->Controller->cacheAction = array(
|
2009-12-29 02:26:51 +00:00
|
|
|
'some_other_action' => 21600
|
2009-11-02 05:07:02 +00:00
|
|
|
);
|
2009-12-29 02:26:51 +00:00
|
|
|
$this->Controller->here = '/cacheTest/cache_parsing';
|
2009-11-02 05:07:02 +00:00
|
|
|
$this->Controller->action = 'cache_parsing';
|
|
|
|
|
|
|
|
$View = new View($this->Controller);
|
|
|
|
$result = $View->render('index');
|
|
|
|
|
|
|
|
$this->assertNoPattern('/cake:nocache/', $result);
|
|
|
|
$this->assertNoPattern('/php echo/', $result);
|
|
|
|
|
2009-12-29 02:26:51 +00:00
|
|
|
$filename = CACHE . 'views' . DS . 'cachetest_cache_parsing.php';
|
|
|
|
$this->assertFalse(file_exists($filename));
|
|
|
|
}
|
2009-12-28 18:38:36 +00:00
|
|
|
|
2009-12-29 02:26:51 +00:00
|
|
|
/**
|
|
|
|
* test that custom routes are respected when generating cache files.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testCacheWithCustomRoutes() {
|
|
|
|
Router::reload();
|
|
|
|
Router::connect('/:lang/:controller/:action/*', array(), array('lang' => '[a-z]{3}'));
|
|
|
|
|
2009-11-02 05:07:02 +00:00
|
|
|
$this->Controller->cache_parsing();
|
2009-12-28 18:38:36 +00:00
|
|
|
$this->Controller->params = array(
|
2009-12-29 02:26:51 +00:00
|
|
|
'lang' => 'en',
|
2009-12-28 18:38:36 +00:00
|
|
|
'controller' => 'cache_test',
|
|
|
|
'action' => 'cache_parsing',
|
|
|
|
'url' => array(),
|
|
|
|
'pass' => array(),
|
|
|
|
'named' => array()
|
|
|
|
);
|
2009-11-02 05:07:02 +00:00
|
|
|
$this->Controller->cacheAction = array(
|
2009-12-29 02:26:51 +00:00
|
|
|
'cache_parsing' => 21600
|
2009-11-02 05:07:02 +00:00
|
|
|
);
|
2009-12-29 02:26:51 +00:00
|
|
|
$this->Controller->here = '/en/cache_test/cache_parsing';
|
2009-11-02 05:07:02 +00:00
|
|
|
$this->Controller->action = 'cache_parsing';
|
|
|
|
|
|
|
|
$View = new View($this->Controller);
|
|
|
|
$result = $View->render('index');
|
|
|
|
|
|
|
|
$this->assertNoPattern('/cake:nocache/', $result);
|
|
|
|
$this->assertNoPattern('/php echo/', $result);
|
|
|
|
|
2009-12-29 02:26:51 +00:00
|
|
|
$filename = CACHE . 'views' . DS . 'en_cache_test_cache_parsing.php';
|
|
|
|
$this->assertTrue(file_exists($filename));
|
|
|
|
@unlink($filename);
|
2009-12-28 18:38:36 +00:00
|
|
|
}
|
2008-10-05 18:27:02 +00:00
|
|
|
/**
|
|
|
|
* testCacheEmptySections method
|
|
|
|
*
|
2008-11-08 03:47:09 +00:00
|
|
|
* This test must be uncommented/fixed in next release (1.2+)
|
|
|
|
*
|
2008-10-05 18:27:02 +00:00
|
|
|
* @return void
|
|
|
|
* @access public
|
2008-11-08 03:47:09 +00:00
|
|
|
*
|
2008-10-05 18:27:02 +00:00
|
|
|
function testCacheEmptySections () {
|
|
|
|
$this->Controller->cache_parsing();
|
|
|
|
$this->Controller->cacheAction = array('cacheTest' => 21600);
|
|
|
|
$this->Controller->here = '/cacheTest/cache_empty_sections';
|
|
|
|
$this->Controller->action = 'cache_empty_sections';
|
|
|
|
$this->Controller->layout = 'cache_empty_sections';
|
|
|
|
$this->Controller->viewPath = 'posts';
|
|
|
|
|
|
|
|
$View = new View($this->Controller);
|
|
|
|
$result = $View->render('cache_empty_sections');
|
|
|
|
$this->assertNoPattern('/cake:nocache/', $result);
|
|
|
|
$this->assertNoPattern('/php echo/', $result);
|
|
|
|
$this->assertPattern(
|
|
|
|
'@</title>\s*</head>\s*' .
|
|
|
|
'<body>\s*' .
|
|
|
|
'View Content\s*' .
|
|
|
|
'cached count is: 3\s*' .
|
|
|
|
'</body>@', $result);
|
|
|
|
|
2008-10-26 18:51:38 +00:00
|
|
|
$filename = CACHE . 'views' . DS . 'cachetest_cache_empty_sections.php';
|
2008-10-05 18:27:02 +00:00
|
|
|
$this->assertTrue(file_exists($filename));
|
|
|
|
$contents = file_get_contents($filename);
|
|
|
|
$this->assertNoPattern('/cake:nocache/', $contents);
|
|
|
|
$this->assertPattern(
|
|
|
|
'@<head>\s*<title>Posts</title>\s*' .
|
|
|
|
"<\?php \$x = 1; \?>\s*" .
|
|
|
|
'</head>\s*' .
|
|
|
|
'<body>\s*' .
|
|
|
|
"<\?php \$x\+\+; \?>\s*" .
|
|
|
|
"<\?php \$x\+\+; \?>\s*" .
|
|
|
|
'View Content\s*' .
|
|
|
|
"<\?php \$y = 1; \?>\s*" .
|
|
|
|
"<\?php echo 'cached count is:' . \$x; \?>\s*" .
|
|
|
|
'@', $contents);
|
|
|
|
@unlink($filename);
|
|
|
|
}
|
2008-11-08 03:47:09 +00:00
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2008-06-27 08:17:02 +00:00
|
|
|
?>
|