2008-05-30 11:40:08 +00:00
|
|
|
<?php
|
|
|
|
/* SVN FILE: $Id$ */
|
|
|
|
/**
|
|
|
|
* Short description for file.
|
|
|
|
*
|
|
|
|
* Long description for file
|
|
|
|
*
|
|
|
|
* PHP versions 4 and 5
|
|
|
|
*
|
|
|
|
* CakePHP(tm) Tests <https://trac.cakephp.org/wiki/Developement/TestSuite>
|
|
|
|
* Copyright 2005-2008, Cake Software Foundation, Inc.
|
|
|
|
* 1785 E. Sahara Avenue, Suite 490-204
|
|
|
|
* Las Vegas, Nevada 89104
|
|
|
|
*
|
|
|
|
* Licensed under The Open Group Test Suite License
|
|
|
|
* Redistributions of files must retain the above copyright notice.
|
|
|
|
*
|
|
|
|
* @filesource
|
|
|
|
* @copyright Copyright 2005-2008, Cake Software Foundation, Inc.
|
|
|
|
* @link https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests
|
|
|
|
* @package cake.tests
|
|
|
|
* @subpackage cake.tests.cases.libs.view.helpers
|
|
|
|
* @since CakePHP(tm) v 1.2.0.4206
|
|
|
|
* @version $Revision$
|
|
|
|
* @modifiedby $LastChangedBy$
|
|
|
|
* @lastmodified $Date$
|
|
|
|
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
|
|
|
|
*/
|
|
|
|
if (!defined('CAKEPHP_UNIT_TEST_EXECUTION')) {
|
|
|
|
define('CAKEPHP_UNIT_TEST_EXECUTION', 1);
|
|
|
|
}
|
2008-07-21 02:40:58 +00:00
|
|
|
App::import('Core', array('Controller', 'Model', 'View'));
|
|
|
|
App::import('Helper', 'Cache');
|
2008-09-05 21:41:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test Cache Helper
|
|
|
|
*
|
|
|
|
* @package cake.tests
|
|
|
|
* @subpackage cake.tests.cases.libs.view.helpers
|
|
|
|
*/
|
|
|
|
class TestCacheHelper extends CacheHelper {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2008-09-05 21:41:07 +00:00
|
|
|
* 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
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
|
|
|
* @package cake.tests
|
|
|
|
* @subpackage cake.tests.cases.libs.view.helpers
|
|
|
|
*/
|
2008-07-21 02:40:58 +00:00
|
|
|
class CacheHelperTest extends CakeTestCase {
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
2008-09-05 21:41:07 +00:00
|
|
|
* setUp method
|
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();
|
|
|
|
$this->Cache = new TestCacheHelper();
|
|
|
|
Configure::write('Cache.check', true);
|
|
|
|
Configure::write('Cache.disable', false);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2008-09-05 21:41:07 +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-05 21:41:07 +00:00
|
|
|
*/
|
|
|
|
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.
|
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
*/
|
2008-09-05 21:41:07 +00:00
|
|
|
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);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
|
|
|
* tearDown method
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function tearDown() {
|
|
|
|
unset($this->Cache);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-06-27 08:17:02 +00:00
|
|
|
?>
|