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
|
|
|
*
|
2017-06-10 22:15:34 +00:00
|
|
|
* CakePHP(tm) Tests <https://book.cakephp.org/2.0/en/development/testing.html>
|
2017-06-10 22:10:52 +00:00
|
|
|
* Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2010-10-03 16:31:21 +00:00
|
|
|
* Licensed under The MIT License
|
2013-02-08 12:22:51 +00:00
|
|
|
* For full copyright and license information, please see the LICENSE.txt
|
2010-10-03 16:31:21 +00:00
|
|
|
* Redistributions of files must retain the above copyright notice
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2017-06-10 22:10:52 +00:00
|
|
|
* @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
|
2017-06-10 22:15:34 +00:00
|
|
|
* @link https://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.View.Helper
|
2008-10-30 17:30:26 +00:00
|
|
|
* @since CakePHP(tm) v 1.2.0.4206
|
2017-06-10 22:23:14 +00:00
|
|
|
* @license https://opensource.org/licenses/mit-license.php MIT License
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-12-10 06:23:27 +00:00
|
|
|
|
|
|
|
App::uses('Controller', 'Controller');
|
|
|
|
App::uses('Model', 'Model');
|
|
|
|
App::uses('View', 'View');
|
|
|
|
App::uses('CacheHelper', 'View/Helper');
|
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
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.View.Helper
|
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
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $helpers = array('Html', 'Cache');
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-03-19 21:10:13 +00:00
|
|
|
/**
|
|
|
|
* cache_parsing method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function cache_parsing() {
|
2011-05-16 22:25:16 +00:00
|
|
|
$this->viewPath = 'Posts';
|
2008-09-05 21:41:07 +00:00
|
|
|
$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
|
|
|
}
|
2012-03-16 02:50:05 +00:00
|
|
|
|
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
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.View.Helper
|
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
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function skip() {
|
2011-11-16 18:07:53 +00:00
|
|
|
if (!is_writable(TMP . 'cache' . DS . 'views' . DS)) {
|
|
|
|
$this->markTestSkipped('TMP/views is not writable %s');
|
|
|
|
}
|
2009-10-22 04:38:37 +00:00
|
|
|
}
|
2011-12-06 20:52:48 +00:00
|
|
|
|
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
|
|
|
* @return void
|
|
|
|
*/
|
2022-12-28 07:03:39 +00:00
|
|
|
public function setUp() : void {
|
2010-11-06 04:32:20 +00:00
|
|
|
parent::setUp();
|
2011-05-10 04:03:58 +00:00
|
|
|
$_GET = array();
|
2010-05-14 04:12:29 +00:00
|
|
|
$request = new CakeRequest();
|
|
|
|
$this->Controller = new CacheTestController($request);
|
2010-07-03 16:16:40 +00:00
|
|
|
$View = new View($this->Controller);
|
|
|
|
$this->Cache = new CacheHelper($View);
|
2008-09-05 21:41:07 +00:00
|
|
|
Configure::write('Cache.check', true);
|
|
|
|
Configure::write('Cache.disable', false);
|
2009-06-11 16:13:16 +00:00
|
|
|
App::build(array(
|
2012-03-16 02:50:05 +00:00
|
|
|
'View' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS)
|
2012-02-18 12:04:54 +00:00
|
|
|
), App::RESET);
|
2008-09-05 21:41:07 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-03-19 21:10:13 +00:00
|
|
|
/**
|
|
|
|
* tearDown method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2022-12-28 07:03:39 +00:00
|
|
|
public function tearDown() : void {
|
2009-07-26 01:27:02 +00:00
|
|
|
clearCache();
|
2009-03-19 21:10:13 +00:00
|
|
|
unset($this->Cache);
|
2010-11-06 04:32:20 +00:00
|
|
|
parent::tearDown();
|
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
|
|
|
* @return void
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testLayoutCacheParsingNoTagsInView() {
|
2008-09-05 21:41:07 +00:00
|
|
|
$this->Controller->cache_parsing();
|
2010-05-14 04:12:29 +00:00
|
|
|
$this->Controller->request->addParams(array(
|
2009-12-28 18:38:36 +00:00
|
|
|
'controller' => 'cache_test',
|
|
|
|
'action' => 'cache_parsing',
|
|
|
|
'pass' => array(),
|
|
|
|
'named' => array()
|
2010-05-14 04:12:29 +00:00
|
|
|
));
|
2008-09-05 21:41:07 +00:00
|
|
|
$this->Controller->cacheAction = 21600;
|
2010-05-14 04:12:29 +00:00
|
|
|
$this->Controller->request->here = '/cacheTest/cache_parsing';
|
|
|
|
$this->Controller->request->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');
|
2022-12-30 08:32:45 +00:00
|
|
|
$this->assertDoesNotMatchRegularExpression('/cake:nocache/', $result);
|
|
|
|
$this->assertDoesNotMatchRegularExpression('/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);
|
2022-12-30 08:28:11 +00:00
|
|
|
$this->assertMatchesRegularExpression('/php echo \$variable/', $contents);
|
|
|
|
$this->assertMatchesRegularExpression('/php echo microtime()/', $contents);
|
|
|
|
$this->assertMatchesRegularExpression('/clark kent/', $result);
|
2008-09-10 16:48:43 +00:00
|
|
|
|
2012-09-04 00:13:30 +00:00
|
|
|
unlink($filename);
|
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-07-25 19:11:52 +00:00
|
|
|
* test cache parsing with non-latin characters in current route
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testCacheNonLatinCharactersInRoute() {
|
2009-07-25 19:11:52 +00:00
|
|
|
$this->Controller->cache_parsing();
|
2010-05-14 04:12:29 +00:00
|
|
|
$this->Controller->request->addParams(array(
|
2009-12-28 18:38:36 +00:00
|
|
|
'controller' => 'cache_test',
|
|
|
|
'action' => 'cache_parsing',
|
|
|
|
'pass' => array('風街ろまん'),
|
|
|
|
'named' => array()
|
2010-05-14 04:12:29 +00:00
|
|
|
));
|
2009-07-25 19:11:52 +00:00
|
|
|
$this->Controller->cacheAction = 21600;
|
2010-05-14 04:12:29 +00:00
|
|
|
$this->Controller->request->here = '/posts/view/風街ろまん';
|
2009-07-25 19:11:52 +00:00
|
|
|
$this->Controller->action = 'view';
|
|
|
|
|
|
|
|
$View = new View($this->Controller);
|
2013-01-23 12:45:50 +00:00
|
|
|
$View->render('index');
|
2009-07-25 19:11:52 +00:00
|
|
|
|
|
|
|
$filename = CACHE . 'views' . DS . 'posts_view_風街ろまん.php';
|
|
|
|
$this->assertTrue(file_exists($filename));
|
|
|
|
|
2012-09-04 00:13:30 +00:00
|
|
|
unlink($filename);
|
2009-07-25 19:11:52 +00:00
|
|
|
}
|
2011-12-06 20:52:48 +00:00
|
|
|
|
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
|
|
|
* @return void
|
2008-09-05 21:41:07 +00:00
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testLayoutCacheParsingWithTagsInView() {
|
2008-09-05 21:41:07 +00:00
|
|
|
$this->Controller->cache_parsing();
|
2010-05-14 04:12:29 +00:00
|
|
|
$this->Controller->request->addParams(array(
|
2009-12-28 18:38:36 +00:00
|
|
|
'controller' => 'cache_test',
|
|
|
|
'action' => 'cache_parsing',
|
|
|
|
'pass' => array(),
|
|
|
|
'named' => array()
|
2010-05-14 04:12:29 +00:00
|
|
|
));
|
2008-09-05 21:41:07 +00:00
|
|
|
$this->Controller->cacheAction = 21600;
|
2010-05-14 04:12:29 +00:00
|
|
|
$this->Controller->request->here = '/cacheTest/cache_parsing';
|
2008-09-05 21:41:07 +00:00
|
|
|
$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');
|
2022-12-30 08:32:45 +00:00
|
|
|
$this->assertDoesNotMatchRegularExpression('/cake:nocache/', $result);
|
|
|
|
$this->assertDoesNotMatchRegularExpression('/php echo/', $result);
|
2008-09-05 21:41:07 +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);
|
2022-12-30 08:28:11 +00:00
|
|
|
$this->assertMatchesRegularExpression('/if \(is_writable\(TMP\)\)\:/', $contents);
|
|
|
|
$this->assertMatchesRegularExpression('/php echo \$variable/', $contents);
|
|
|
|
$this->assertMatchesRegularExpression('/php echo microtime()/', $contents);
|
2022-12-30 08:32:45 +00:00
|
|
|
$this->assertDoesNotMatchRegularExpression('/cake:nocache/', $contents);
|
2008-09-10 16:48:43 +00:00
|
|
|
|
2012-09-04 00:13:30 +00:00
|
|
|
unlink($filename);
|
2008-09-05 21:41:07 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-10-01 05:03:47 +00:00
|
|
|
/**
|
2010-11-06 05:18:23 +00:00
|
|
|
* test that multiple <!--nocache--> tags function with multiple nocache tags in the layout.
|
2009-10-01 05:03:47 +00:00
|
|
|
*
|
|
|
|
* @return void
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testMultipleNoCacheTagsInViewfile() {
|
2009-10-01 05:03:47 +00:00
|
|
|
$this->Controller->cache_parsing();
|
2010-05-14 04:12:29 +00:00
|
|
|
$this->Controller->request->addParams(array(
|
2009-12-28 18:38:36 +00:00
|
|
|
'controller' => 'cache_test',
|
|
|
|
'action' => 'cache_parsing',
|
|
|
|
'pass' => array(),
|
|
|
|
'named' => array()
|
2010-05-14 04:12:29 +00:00
|
|
|
));
|
2009-10-01 05:03:47 +00:00
|
|
|
$this->Controller->cacheAction = 21600;
|
2010-05-14 04:12:29 +00:00
|
|
|
$this->Controller->request->here = '/cacheTest/cache_parsing';
|
2009-10-01 05:03:47 +00:00
|
|
|
$this->Controller->action = 'cache_parsing';
|
|
|
|
|
|
|
|
$View = new View($this->Controller);
|
|
|
|
$result = $View->render('multiple_nocache');
|
|
|
|
|
2022-12-30 08:32:45 +00:00
|
|
|
$this->assertDoesNotMatchRegularExpression('/cake:nocache/', $result);
|
|
|
|
$this->assertDoesNotMatchRegularExpression('/php echo/', $result);
|
2009-10-01 05:03:47 +00:00
|
|
|
|
|
|
|
$filename = CACHE . 'views' . DS . 'cachetest_cache_parsing.php';
|
|
|
|
$this->assertTrue(file_exists($filename));
|
|
|
|
|
|
|
|
$contents = file_get_contents($filename);
|
2022-12-30 08:32:45 +00:00
|
|
|
$this->assertDoesNotMatchRegularExpression('/cake:nocache/', $contents);
|
2012-09-04 00:13:30 +00:00
|
|
|
unlink($filename);
|
2009-10-01 05:03:47 +00:00
|
|
|
}
|
2009-10-14 04:51:55 +00:00
|
|
|
|
2008-09-10 16:48:43 +00:00
|
|
|
/**
|
|
|
|
* testComplexNoCache method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2012-02-23 13:38:02 +00:00
|
|
|
public function testComplexNoCache() {
|
2008-09-10 16:48:43 +00:00
|
|
|
$this->Controller->cache_parsing();
|
2010-05-14 04:12:29 +00:00
|
|
|
$this->Controller->request->addParams(array(
|
2009-12-28 18:38:36 +00:00
|
|
|
'controller' => 'cache_test',
|
|
|
|
'action' => 'cache_complex',
|
|
|
|
'pass' => array(),
|
|
|
|
'named' => array()
|
2010-05-14 04:12:29 +00:00
|
|
|
));
|
2009-11-02 05:07:02 +00:00
|
|
|
$this->Controller->cacheAction = array('cache_complex' => 21600);
|
2010-05-14 04:12:29 +00:00
|
|
|
$this->Controller->request->here = '/cacheTest/cache_complex';
|
2008-09-10 16:48:43 +00:00
|
|
|
$this->Controller->action = 'cache_complex';
|
|
|
|
$this->Controller->layout = 'multi_cache';
|
2011-05-16 22:25:16 +00:00
|
|
|
$this->Controller->viewPath = 'Posts';
|
2008-09-10 16:48:43 +00:00
|
|
|
|
|
|
|
$View = new View($this->Controller);
|
|
|
|
$result = $View->render('sequencial_nocache');
|
|
|
|
|
2022-12-30 08:32:45 +00:00
|
|
|
$this->assertDoesNotMatchRegularExpression('/cake:nocache/', $result);
|
|
|
|
$this->assertDoesNotMatchRegularExpression('/php echo/', $result);
|
2022-12-30 08:28:11 +00:00
|
|
|
$this->assertMatchesRegularExpression('/A\. Layout Before Content/', $result);
|
|
|
|
$this->assertMatchesRegularExpression('/B\. In Plain Element/', $result);
|
|
|
|
$this->assertMatchesRegularExpression('/C\. Layout After Test Element/', $result);
|
|
|
|
$this->assertMatchesRegularExpression('/D\. In View File/', $result);
|
|
|
|
$this->assertMatchesRegularExpression('/E\. Layout After Content/', $result);
|
|
|
|
$this->assertMatchesRegularExpression('/F\. In Element With No Cache Tags/', $result);
|
|
|
|
$this->assertMatchesRegularExpression('/G\. Layout After Content And After Element With No Cache Tags/', $result);
|
2022-12-30 08:32:45 +00:00
|
|
|
$this->assertDoesNotMatchRegularExpression('/1\. layout before content/', $result);
|
|
|
|
$this->assertDoesNotMatchRegularExpression('/2\. in plain element/', $result);
|
|
|
|
$this->assertDoesNotMatchRegularExpression('/3\. layout after test element/', $result);
|
|
|
|
$this->assertDoesNotMatchRegularExpression('/4\. in view file/', $result);
|
|
|
|
$this->assertDoesNotMatchRegularExpression('/5\. layout after content/', $result);
|
|
|
|
$this->assertDoesNotMatchRegularExpression('/6\. in element with no cache tags/', $result);
|
|
|
|
$this->assertDoesNotMatchRegularExpression('/7\. layout after content and after element with no cache tags/', $result);
|
2008-09-10 16:48:43 +00:00
|
|
|
|
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);
|
2012-09-04 00:13:30 +00:00
|
|
|
unlink($filename);
|
2008-09-10 16:48:43 +00:00
|
|
|
|
2022-12-30 08:28:11 +00:00
|
|
|
$this->assertMatchesRegularExpression('/A\. Layout Before Content/', $contents);
|
2022-12-30 08:32:45 +00:00
|
|
|
$this->assertDoesNotMatchRegularExpression('/B\. In Plain Element/', $contents);
|
2022-12-30 08:28:11 +00:00
|
|
|
$this->assertMatchesRegularExpression('/C\. Layout After Test Element/', $contents);
|
|
|
|
$this->assertMatchesRegularExpression('/D\. In View File/', $contents);
|
|
|
|
$this->assertMatchesRegularExpression('/E\. Layout After Content/', $contents);
|
|
|
|
$this->assertMatchesRegularExpression('/F\. In Element With No Cache Tags/', $contents);
|
|
|
|
$this->assertMatchesRegularExpression('/G\. Layout After Content And After Element With No Cache Tags/', $contents);
|
|
|
|
$this->assertMatchesRegularExpression('/1\. layout before content/', $contents);
|
2022-12-30 08:32:45 +00:00
|
|
|
$this->assertDoesNotMatchRegularExpression('/2\. in plain element/', $contents);
|
2022-12-30 08:28:11 +00:00
|
|
|
$this->assertMatchesRegularExpression('/3\. layout after test element/', $contents);
|
|
|
|
$this->assertMatchesRegularExpression('/4\. in view file/', $contents);
|
|
|
|
$this->assertMatchesRegularExpression('/5\. layout after content/', $contents);
|
|
|
|
$this->assertMatchesRegularExpression('/6\. in element with no cache tags/', $contents);
|
|
|
|
$this->assertMatchesRegularExpression('/7\. layout after content and after element with no cache tags/', $contents);
|
2008-09-10 16:48:43 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2010-12-18 21:31:10 +00:00
|
|
|
/**
|
|
|
|
* test cache of view vars
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testCacheViewVars() {
|
2010-12-18 21:31:10 +00:00
|
|
|
$this->Controller->cache_parsing();
|
2012-05-15 01:32:31 +00:00
|
|
|
$this->Controller->request->addParams(array(
|
2010-12-18 21:31:10 +00:00
|
|
|
'controller' => 'cache_test',
|
|
|
|
'action' => 'cache_parsing',
|
|
|
|
'pass' => array(),
|
|
|
|
'named' => array()
|
2012-05-15 01:32:31 +00:00
|
|
|
));
|
|
|
|
$this->Controller->request->here = '/cacheTest/cache_parsing';
|
2010-12-18 21:31:10 +00:00
|
|
|
$this->Controller->cacheAction = 21600;
|
|
|
|
|
|
|
|
$View = new View($this->Controller);
|
|
|
|
$result = $View->render('index');
|
2022-12-30 08:32:45 +00:00
|
|
|
$this->assertDoesNotMatchRegularExpression('/cake:nocache/', $result);
|
|
|
|
$this->assertDoesNotMatchRegularExpression('/php echo/', $result);
|
2010-12-18 21:31:10 +00:00
|
|
|
|
|
|
|
$filename = CACHE . 'views' . DS . 'cachetest_cache_parsing.php';
|
|
|
|
$this->assertTrue(file_exists($filename));
|
|
|
|
|
|
|
|
$contents = file_get_contents($filename);
|
2022-12-30 08:28:11 +00:00
|
|
|
$this->assertMatchesRegularExpression('/\$this\-\>viewVars/', $contents);
|
|
|
|
$this->assertMatchesRegularExpression('/extract\(\$this\-\>viewVars, EXTR_SKIP\);/', $contents);
|
|
|
|
$this->assertMatchesRegularExpression('/php echo \$variable/', $contents);
|
2010-12-18 21:31:10 +00:00
|
|
|
|
2012-09-04 00:13:30 +00:00
|
|
|
unlink($filename);
|
2010-12-18 21:31:10 +00:00
|
|
|
}
|
2011-08-17 02:40:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test that callback code is generated correctly.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testCacheCallbacks() {
|
2012-05-15 01:32:31 +00:00
|
|
|
$this->Controller->request->addParams(array(
|
2011-08-06 02:59:13 +00:00
|
|
|
'controller' => 'cache_test',
|
|
|
|
'action' => 'cache_parsing',
|
|
|
|
'pass' => array(),
|
|
|
|
'named' => array()
|
2012-05-15 01:32:31 +00:00
|
|
|
));
|
2011-08-06 02:59:13 +00:00
|
|
|
$this->Controller->cacheAction = array(
|
|
|
|
'cache_parsing' => array(
|
|
|
|
'duration' => 21600,
|
|
|
|
'callbacks' => true
|
|
|
|
)
|
|
|
|
);
|
2012-05-15 01:32:31 +00:00
|
|
|
$this->Controller->request->here = '/cacheTest/cache_parsing';
|
|
|
|
$this->Controller->cache_parsing();
|
2011-08-06 02:59:13 +00:00
|
|
|
|
|
|
|
$View = new View($this->Controller);
|
2013-01-23 12:45:50 +00:00
|
|
|
$View->render('index');
|
2011-08-06 02:59:13 +00:00
|
|
|
|
|
|
|
$filename = CACHE . 'views' . DS . 'cachetest_cache_parsing.php';
|
|
|
|
$this->assertTrue(file_exists($filename));
|
|
|
|
|
|
|
|
$contents = file_get_contents($filename);
|
|
|
|
|
2022-12-30 08:28:11 +00:00
|
|
|
$this->assertMatchesRegularExpression('/\$controller->startupProcess\(\);/', $contents);
|
2011-08-06 02:59:13 +00:00
|
|
|
|
2012-09-04 00:13:30 +00:00
|
|
|
unlink($filename);
|
2011-08-06 02:59:13 +00:00
|
|
|
}
|
2010-12-18 21:31:10 +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
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testCacheActionArray() {
|
2010-05-14 04:12:29 +00:00
|
|
|
$this->Controller->request->addParams(array(
|
2009-12-28 18:38:36 +00:00
|
|
|
'controller' => 'cache_test',
|
|
|
|
'action' => 'cache_parsing',
|
|
|
|
'pass' => array(),
|
|
|
|
'named' => array()
|
2010-05-14 04:12:29 +00:00
|
|
|
));
|
2012-05-15 01:32:31 +00:00
|
|
|
$this->Controller->request->here = '/cache_test/cache_parsing';
|
2009-11-02 05:07:02 +00:00
|
|
|
$this->Controller->cacheAction = array(
|
|
|
|
'cache_parsing' => 21600
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->Controller->cache_parsing();
|
|
|
|
|
|
|
|
$View = new View($this->Controller);
|
|
|
|
$result = $View->render('index');
|
|
|
|
|
2022-12-30 08:32:45 +00:00
|
|
|
$this->assertDoesNotMatchRegularExpression('/cake:nocache/', $result);
|
|
|
|
$this->assertDoesNotMatchRegularExpression('/php echo/', $result);
|
2009-11-02 05:07:02 +00:00
|
|
|
|
2012-05-15 01:32:31 +00:00
|
|
|
$filename = CACHE . 'views' . DS . 'cache_test_cache_parsing.php';
|
2009-11-02 05:07:02 +00:00
|
|
|
$this->assertTrue(file_exists($filename));
|
2012-09-04 00:13:30 +00:00
|
|
|
unlink($filename);
|
2012-05-15 01:32:31 +00:00
|
|
|
}
|
2009-11-02 05:07:02 +00:00
|
|
|
|
2012-05-15 01:32:31 +00:00
|
|
|
/**
|
|
|
|
* Test that cacheAction works with camelcased controller names.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testCacheActionArrayCamelCase() {
|
2010-05-14 04:12:29 +00:00
|
|
|
$this->Controller->request->addParams(array(
|
2009-12-28 18:38:36 +00:00
|
|
|
'controller' => 'cache_test',
|
|
|
|
'action' => 'cache_parsing',
|
2009-12-29 02:26:51 +00:00
|
|
|
'pass' => array(),
|
2009-12-28 18:38:36 +00:00
|
|
|
'named' => array()
|
2010-05-14 04:12:29 +00:00
|
|
|
));
|
2009-11-02 05:07:02 +00:00
|
|
|
$this->Controller->cacheAction = array(
|
2012-05-15 01:32:31 +00:00
|
|
|
'cache_parsing' => 21600
|
2009-11-02 05:07:02 +00:00
|
|
|
);
|
2010-05-14 04:12:29 +00:00
|
|
|
$this->Controller->request->here = '/cacheTest/cache_parsing';
|
2012-05-15 01:32:31 +00:00
|
|
|
$this->Controller->cache_parsing();
|
2009-11-02 05:07:02 +00:00
|
|
|
|
|
|
|
$View = new View($this->Controller);
|
|
|
|
$result = $View->render('index');
|
|
|
|
|
2022-12-30 08:32:45 +00:00
|
|
|
$this->assertDoesNotMatchRegularExpression('/cake:nocache/', $result);
|
|
|
|
$this->assertDoesNotMatchRegularExpression('/php echo/', $result);
|
2009-11-02 05:07:02 +00:00
|
|
|
|
2009-12-29 02:26:51 +00:00
|
|
|
$filename = CACHE . 'views' . DS . 'cachetest_cache_parsing.php';
|
2012-05-15 01:32:31 +00:00
|
|
|
$this->assertTrue(file_exists($filename));
|
2012-09-04 00:13:30 +00:00
|
|
|
unlink($filename);
|
2009-12-29 02:26:51 +00:00
|
|
|
}
|
2009-12-28 18:38:36 +00:00
|
|
|
|
2010-08-05 03:08:43 +00:00
|
|
|
/**
|
|
|
|
* test with named and pass args.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testCacheWithNamedAndPassedArgs() {
|
2010-08-05 03:08:43 +00:00
|
|
|
Router::reload();
|
|
|
|
|
|
|
|
$this->Controller->cache_parsing();
|
2010-08-28 04:40:12 +00:00
|
|
|
$this->Controller->request->addParams(array(
|
2010-08-05 03:08:43 +00:00
|
|
|
'controller' => 'cache_test',
|
|
|
|
'action' => 'cache_parsing',
|
|
|
|
'pass' => array(1, 2),
|
|
|
|
'named' => array(
|
|
|
|
'name' => 'mark',
|
|
|
|
'ice' => 'cream'
|
|
|
|
)
|
2010-08-28 04:40:12 +00:00
|
|
|
));
|
2010-08-05 03:08:43 +00:00
|
|
|
$this->Controller->cacheAction = array(
|
|
|
|
'cache_parsing' => 21600
|
|
|
|
);
|
2010-08-28 04:40:12 +00:00
|
|
|
$this->Controller->request->here = '/cache_test/cache_parsing/1/2/name:mark/ice:cream';
|
2011-04-17 10:35:21 +00:00
|
|
|
|
2010-08-05 03:08:43 +00:00
|
|
|
$View = new View($this->Controller);
|
|
|
|
$result = $View->render('index');
|
|
|
|
|
2022-12-30 08:32:45 +00:00
|
|
|
$this->assertDoesNotMatchRegularExpression('/cake:nocache/', $result);
|
|
|
|
$this->assertDoesNotMatchRegularExpression('/php echo/', $result);
|
2010-08-05 03:08:43 +00:00
|
|
|
|
|
|
|
$filename = CACHE . 'views' . DS . 'cache_test_cache_parsing_1_2_name_mark_ice_cream.php';
|
|
|
|
$this->assertTrue(file_exists($filename));
|
2012-09-04 00:13:30 +00:00
|
|
|
unlink($filename);
|
2010-08-05 03:08:43 +00:00
|
|
|
}
|
|
|
|
|
2011-12-17 17:09:50 +00:00
|
|
|
/**
|
|
|
|
* Test that query string parameters are included in the cache filename.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testCacheWithQueryStringParams() {
|
|
|
|
Router::reload();
|
|
|
|
|
|
|
|
$this->Controller->cache_parsing();
|
|
|
|
$this->Controller->request->addParams(array(
|
|
|
|
'controller' => 'cache_test',
|
|
|
|
'action' => 'cache_parsing',
|
|
|
|
'pass' => array(),
|
|
|
|
'named' => array()
|
|
|
|
));
|
|
|
|
$this->Controller->request->query = array('q' => 'cakephp');
|
|
|
|
$this->Controller->cacheAction = array(
|
|
|
|
'cache_parsing' => 21600
|
|
|
|
);
|
|
|
|
$this->Controller->request->here = '/cache_test/cache_parsing';
|
|
|
|
|
|
|
|
$View = new View($this->Controller);
|
|
|
|
$result = $View->render('index');
|
|
|
|
|
2022-12-30 08:32:45 +00:00
|
|
|
$this->assertDoesNotMatchRegularExpression('/cake:nocache/', $result);
|
|
|
|
$this->assertDoesNotMatchRegularExpression('/php echo/', $result);
|
2011-12-17 17:09:50 +00:00
|
|
|
|
|
|
|
$filename = CACHE . 'views' . DS . 'cache_test_cache_parsing_q_cakephp.php';
|
|
|
|
$this->assertTrue(file_exists($filename), 'Missing cache file ' . $filename);
|
2012-09-04 00:13:30 +00:00
|
|
|
unlink($filename);
|
2011-12-17 17:09:50 +00:00
|
|
|
}
|
|
|
|
|
2009-12-29 02:26:51 +00:00
|
|
|
/**
|
|
|
|
* test that custom routes are respected when generating cache files.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testCacheWithCustomRoutes() {
|
2009-12-29 02:26:51 +00:00
|
|
|
Router::reload();
|
|
|
|
Router::connect('/:lang/:controller/:action/*', array(), array('lang' => '[a-z]{3}'));
|
2011-04-17 10:35:21 +00:00
|
|
|
|
2009-11-02 05:07:02 +00:00
|
|
|
$this->Controller->cache_parsing();
|
2010-05-14 04:12:29 +00:00
|
|
|
$this->Controller->request->addParams(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',
|
|
|
|
'pass' => array(),
|
|
|
|
'named' => array()
|
2010-05-14 04:12:29 +00:00
|
|
|
));
|
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
|
|
|
);
|
2010-05-14 04:12:29 +00:00
|
|
|
$this->Controller->request->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');
|
|
|
|
|
2022-12-30 08:32:45 +00:00
|
|
|
$this->assertDoesNotMatchRegularExpression('/cake:nocache/', $result);
|
|
|
|
$this->assertDoesNotMatchRegularExpression('/php echo/', $result);
|
2009-11-02 05:07:02 +00:00
|
|
|
|
2009-12-29 02:26:51 +00:00
|
|
|
$filename = CACHE . 'views' . DS . 'en_cache_test_cache_parsing.php';
|
|
|
|
$this->assertTrue(file_exists($filename));
|
2012-09-04 00:13:30 +00:00
|
|
|
unlink($filename);
|
2009-12-28 18:38:36 +00:00
|
|
|
}
|
2010-08-17 02:11:25 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* test ControllerName contains AppName
|
|
|
|
*
|
2012-02-23 23:29:53 +00:00
|
|
|
* This test verifies view cache is created correctly when the app name is contained in part of the controller name.
|
2010-08-17 02:11:25 +00:00
|
|
|
* (webapp Name) base name is 'cache' controller is 'cacheTest' action is 'cache_name'
|
2013-10-08 03:17:58 +00:00
|
|
|
* apps URL would look something like http://localhost/cache/cacheTest/cache_name
|
2010-08-17 02:11:25 +00:00
|
|
|
*
|
|
|
|
* @return void
|
2013-01-11 14:06:54 +00:00
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testCacheBaseNameControllerName() {
|
2010-08-17 02:11:25 +00:00
|
|
|
$this->Controller->cache_parsing();
|
|
|
|
$this->Controller->cacheAction = array(
|
|
|
|
'cache_name' => 21600
|
|
|
|
);
|
|
|
|
$this->Controller->params = array(
|
|
|
|
'controller' => 'cacheTest',
|
|
|
|
'action' => 'cache_name',
|
|
|
|
'pass' => array(),
|
|
|
|
'named' => array()
|
|
|
|
);
|
|
|
|
$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');
|
|
|
|
|
2022-12-30 08:32:45 +00:00
|
|
|
$this->assertDoesNotMatchRegularExpression('/cake:nocache/', $result);
|
|
|
|
$this->assertDoesNotMatchRegularExpression('/php echo/', $result);
|
2010-08-17 02:11:25 +00:00
|
|
|
|
|
|
|
$filename = CACHE . 'views' . DS . 'cache_cachetest_cache_name.php';
|
|
|
|
$this->assertTrue(file_exists($filename));
|
2012-09-04 00:13:30 +00:00
|
|
|
unlink($filename);
|
2011-12-16 06:52:07 +00:00
|
|
|
}
|
2010-08-17 02:11:25 +00:00
|
|
|
|
2010-11-06 04:32:20 +00:00
|
|
|
/**
|
|
|
|
* test that afterRender checks the conditions correctly.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testAfterRenderConditions() {
|
2010-11-06 04:32:20 +00:00
|
|
|
Configure::write('Cache.check', true);
|
|
|
|
$View = new View($this->Controller);
|
|
|
|
$View->cacheAction = '+1 day';
|
|
|
|
$View->output = 'test';
|
|
|
|
|
2011-10-09 01:48:16 +00:00
|
|
|
$Cache = $this->getMock('CacheHelper', array('_parseContent'), array($View));
|
|
|
|
$Cache->expects($this->once())
|
|
|
|
->method('_parseContent')
|
2011-10-09 02:04:53 +00:00
|
|
|
->with('posts/index', 'content')
|
2011-10-09 01:20:51 +00:00
|
|
|
->will($this->returnValue(''));
|
|
|
|
|
2011-10-09 02:04:53 +00:00
|
|
|
$Cache->afterRenderFile('posts/index', 'content');
|
2011-04-17 10:35:21 +00:00
|
|
|
|
2010-11-06 04:32:20 +00:00
|
|
|
Configure::write('Cache.check', false);
|
|
|
|
$Cache->afterRender('posts/index');
|
2011-04-17 10:35:21 +00:00
|
|
|
|
2010-11-06 04:32:20 +00:00
|
|
|
Configure::write('Cache.check', true);
|
|
|
|
$View->cacheAction = false;
|
|
|
|
$Cache->afterRender('posts/index');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* test that afterRender checks the conditions correctly.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testAfterLayoutConditions() {
|
2010-11-06 04:32:20 +00:00
|
|
|
Configure::write('Cache.check', true);
|
|
|
|
$View = new View($this->Controller);
|
|
|
|
$View->cacheAction = '+1 day';
|
|
|
|
$View->output = 'test';
|
|
|
|
|
|
|
|
$Cache = $this->getMock('CacheHelper', array('cache'), array($View));
|
2011-10-09 01:48:16 +00:00
|
|
|
$Cache->expects($this->once())
|
|
|
|
->method('cache')
|
|
|
|
->with('posts/index', $View->output)
|
2011-10-09 01:20:51 +00:00
|
|
|
->will($this->returnValue(''));
|
|
|
|
|
2010-11-06 04:32:20 +00:00
|
|
|
$Cache->afterLayout('posts/index');
|
|
|
|
|
|
|
|
Configure::write('Cache.check', false);
|
|
|
|
$Cache->afterLayout('posts/index');
|
|
|
|
|
|
|
|
Configure::write('Cache.check', true);
|
|
|
|
$View->cacheAction = false;
|
|
|
|
$Cache->afterLayout('posts/index');
|
|
|
|
}
|
|
|
|
|
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
|
2011-08-02 02:54:49 +00:00
|
|
|
*/
|
2011-08-14 18:39:49 +00:00
|
|
|
public function testCacheEmptySections() {
|
2008-10-05 18:27:02 +00:00
|
|
|
$this->Controller->cache_parsing();
|
2011-08-02 02:54:49 +00:00
|
|
|
$this->Controller->params = array(
|
|
|
|
'controller' => 'cacheTest',
|
|
|
|
'action' => 'cache_empty_sections',
|
|
|
|
'pass' => array(),
|
|
|
|
'named' => array()
|
|
|
|
);
|
|
|
|
$this->Controller->cacheAction = array('cache_empty_sections' => 21600);
|
2008-10-05 18:27:02 +00:00
|
|
|
$this->Controller->here = '/cacheTest/cache_empty_sections';
|
|
|
|
$this->Controller->action = 'cache_empty_sections';
|
|
|
|
$this->Controller->layout = 'cache_empty_sections';
|
2011-05-16 22:25:16 +00:00
|
|
|
$this->Controller->viewPath = 'Posts';
|
2008-10-05 18:27:02 +00:00
|
|
|
|
|
|
|
$View = new View($this->Controller);
|
|
|
|
$result = $View->render('cache_empty_sections');
|
2022-12-30 08:32:45 +00:00
|
|
|
$this->assertDoesNotMatchRegularExpression('/nocache/', $result);
|
|
|
|
$this->assertDoesNotMatchRegularExpression('/php echo/', $result);
|
2022-12-30 08:28:11 +00:00
|
|
|
$this->assertMatchesRegularExpression(
|
2008-10-05 18:27:02 +00:00
|
|
|
'@</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);
|
2022-12-30 08:32:45 +00:00
|
|
|
$this->assertDoesNotMatchRegularExpression('/nocache/', $contents);
|
2022-12-30 08:28:11 +00:00
|
|
|
$this->assertMatchesRegularExpression(
|
2008-10-05 18:27:02 +00:00
|
|
|
'@<head>\s*<title>Posts</title>\s*' .
|
2011-08-02 02:54:49 +00:00
|
|
|
'<\?php \$x \= 1; \?>\s*' .
|
2008-10-05 18:27:02 +00:00
|
|
|
'</head>\s*' .
|
|
|
|
'<body>\s*' .
|
2011-08-02 02:54:49 +00:00
|
|
|
'<\?php \$x\+\+; \?>\s*' .
|
|
|
|
'<\?php \$x\+\+; \?>\s*' .
|
2008-10-05 18:27:02 +00:00
|
|
|
'View Content\s*' .
|
2011-08-02 02:54:49 +00:00
|
|
|
'<\?php \$y = 1; \?>\s*' .
|
|
|
|
'<\?php echo \'cached count is: \' . \$x; \?>\s*' .
|
2008-10-05 18:27:02 +00:00
|
|
|
'@', $contents);
|
2012-09-04 00:13:30 +00:00
|
|
|
unlink($filename);
|
2008-10-05 18:27:02 +00:00
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|