2015-05-04 03:00:52 +02:00
<? php
/**
* Smarty PHPunit tests for cache resource file
*
* @package PHPunit
* @author Uwe Tews
*/
/**
* class for cache resource file tests
*
* @backupStaticAttributes enabled
*/
class CacheResourceTestCommon extends PHPUnit_Smarty
{
public static $touchResource = null ;
public function setUp ()
{
$this -> smarty -> setTemplateDir ( __DIR__ . '/../_shared/templates' );
$this -> smarty -> addPluginsDir ( __DIR__ . '/../_shared/PHPunitplugins' );
$this -> smarty -> registerFilter ( 'pre' , array ( $this , 'compiledPrefilter' ));
}
protected function doClearCacheAssertion ( $a , $b )
{
$this -> assertEquals ( $a , $b );
}
public function compiledPrefilter ( $text , Smarty_Internal_Template $tpl )
{
2015-08-23 15:04:21 +02:00
return str_replace ( '#' , $tpl -> _getVariable ( 'test' ), $text );
2015-05-04 03:00:52 +02:00
}
/**
* test getCachedFilepath with configuration['useSubDirs'] enabled
*/
public function testGetCachedFilepathSubDirs ()
{
$this -> smarty -> caching = true ;
$this -> smarty -> cache_lifetime = 1000 ;
$this -> smarty -> setUseSubDirs ( true );
$tpl = $this -> smarty -> createTemplate ( 'helloworld.tpl' );
$this -> assertEquals ( $this -> buildCachedPath ( $tpl ), $tpl -> cached -> filepath );
}
/**
* test getCachedFilepath with cache_id
*/
public function testGetCachedFilepathCacheId ()
{
$this -> smarty -> caching = true ;
$this -> smarty -> cache_lifetime = 1000 ;
$tpl = $this -> smarty -> createTemplate ( 'helloworld.tpl' , 'foo|bar' );
$this -> assertEquals ( $this -> buildCachedPath ( $tpl , true , 'foo|bar' ), $tpl -> cached -> filepath );
}
/**
* test getCachedFilepath with compile_id
*/
public function testGetCachedFilepathCompileId ()
{
$this -> smarty -> caching = true ;
$this -> smarty -> cache_lifetime = 1000 ;
$tpl = $this -> smarty -> createTemplate ( 'helloworld.tpl' , null , 'blar' );
$this -> assertEquals ( $this -> buildCachedPath ( $tpl , true , null , 'blar' ), $tpl -> cached -> filepath );
}
/**
* test getCachedFilepath with cache_id and compile_id
*/
public function testGetCachedFilepathCacheIdCompileId ()
{
$this -> smarty -> caching = true ;
$this -> smarty -> cache_lifetime = 1000 ;
$tpl = $this -> smarty -> createTemplate ( 'helloworld.tpl' , 'foo|bar' , 'blar' );
$this -> assertEquals ( $this -> buildCachedPath ( $tpl , true , 'foo|bar' , 'blar' ), $tpl -> cached -> filepath );
}
/**
* test cache->clear_all with cache_id and compile_id
*/
public function testClearCacheAllCacheIdCompileId ()
{
$this -> smarty -> clearAllCache ();
$this -> smarty -> caching = true ;
$this -> smarty -> cache_lifetime = 1000 ;
$tpl = $this -> smarty -> createTemplate ( 'helloworld.tpl' , 'foo|bar' , 'blar' );
$tpl -> writeCachedContent ( 'hello world' );
$this -> assertEquals ( 'hello world' , $tpl -> cached -> handler -> getCachedContent ( $tpl ));
// Custom CacheResources may return -1 if they can't tell the number of deleted elements
$this -> assertEquals ( - 1 , $this -> smarty -> clearAllCache ());
}
/**
* test cache->clear with cache_id and compile_id
*/
public function testClearCacheCacheIdCompileId ()
{
$this -> smarty -> caching = true ;
$this -> smarty -> cache_lifetime = 1000 ;
$this -> smarty -> clearAllCache ();
// create and cache templates
$tpl = $this -> smarty -> createTemplate ( 'helloworld.tpl' , 'foo|bar' , 'blar' );
$tpl -> writeCachedContent ( 'hello world 1' );
$tpl2 = $this -> smarty -> createTemplate ( 'helloworld.tpl' , 'foo|bar2' , 'blar' );
$tpl2 -> writeCachedContent ( 'hello world 2' );
$tpl3 = $this -> smarty -> createTemplate ( 'helloworld2.tpl' , 'foo|bar' , 'blar' );
$tpl3 -> writeCachedContent ( 'hello world 3' );
// test cached content
$this -> assertEquals ( 'hello world 1' , $tpl -> cached -> handler -> getCachedContent ( $tpl ));
$this -> assertEquals ( 'hello world 2' , $tpl -> cached -> handler -> getCachedContent ( $tpl2 ));
$this -> assertEquals ( 'hello world 3' , $tpl -> cached -> handler -> getCachedContent ( $tpl3 ));
// test number of deleted caches
$this -> doClearCacheAssertion ( 2 , $this -> smarty -> clearCache ( null , 'foo|bar' ));
// test that caches are deleted properly
$this -> assertNull ( $tpl -> cached -> handler -> getCachedContent ( $tpl ));
$this -> assertEquals ( 'hello world 2' , $tpl -> cached -> handler -> getCachedContent ( $tpl2 ));
$this -> assertNull ( $tpl -> cached -> handler -> getCachedContent ( $tpl3 ));
}
public function testClearCacheCacheIdCompileId2 ()
{
$this -> smarty -> caching = true ;
$this -> smarty -> cache_lifetime = 1000 ;
$this -> smarty -> clearAllCache ();
// create and cache templates
$tpl = $this -> smarty -> createTemplate ( 'helloworld.tpl' , 'foo|bar' , 'blar' );
$tpl -> writeCachedContent ( 'hello world' );
$tpl2 = $this -> smarty -> createTemplate ( 'helloworld.tpl' , 'foo|bar2' , 'blar' );
$tpl2 -> writeCachedContent ( 'hello world' );
$tpl3 = $this -> smarty -> createTemplate ( 'helloworld2.tpl' , 'foo|bar' , 'blar' );
$tpl3 -> writeCachedContent ( 'hello world' );
// test cached content
$this -> assertEquals ( 'hello world' , $tpl -> cached -> handler -> getCachedContent ( $tpl ));
$this -> assertEquals ( 'hello world' , $tpl -> cached -> handler -> getCachedContent ( $tpl2 ));
$this -> assertEquals ( 'hello world' , $tpl -> cached -> handler -> getCachedContent ( $tpl3 ));
// test number of deleted caches
$this -> doClearCacheAssertion ( 2 , $this -> smarty -> clearCache ( 'helloworld.tpl' ));
// test that caches are deleted properly
$this -> assertNull ( $tpl -> cached -> handler -> getCachedContent ( $tpl ));
$this -> assertNull ( $tpl -> cached -> handler -> getCachedContent ( $tpl2 ));
$this -> assertEquals ( 'hello world' , $tpl -> cached -> handler -> getCachedContent ( $tpl3 ));
}
public function testClearCacheCacheIdCompileId2Sub ()
{
$this -> smarty -> caching = true ;
$this -> smarty -> cache_lifetime = 1000 ;
$this -> smarty -> clearAllCache ();
// create and cache templates
$tpl = $this -> smarty -> createTemplate ( 'helloworld.tpl' , 'foo|bar' , 'blar' );
$tpl -> writeCachedContent ( 'hello world' );
$tpl2 = $this -> smarty -> createTemplate ( 'helloworld.tpl' , 'foo|bar2' , 'blar' );
$tpl2 -> writeCachedContent ( 'hello world' );
$tpl3 = $this -> smarty -> createTemplate ( 'helloworld2.tpl' , 'foo|bar' , 'blar' );
$tpl3 -> writeCachedContent ( 'hello world' );
// test cached content
$this -> assertEquals ( 'hello world' , $tpl -> cached -> handler -> getCachedContent ( $tpl ));
$this -> assertEquals ( 'hello world' , $tpl -> cached -> handler -> getCachedContent ( $tpl2 ));
$this -> assertEquals ( 'hello world' , $tpl -> cached -> handler -> getCachedContent ( $tpl3 ));
// test number of deleted caches
$this -> doClearCacheAssertion ( 2 , $this -> smarty -> clearCache ( 'helloworld.tpl' ));
// test that caches are deleted properly
$this -> assertNull ( $tpl -> cached -> handler -> getCachedContent ( $tpl ));
$this -> assertNull ( $tpl -> cached -> handler -> getCachedContent ( $tpl2 ));
$this -> assertEquals ( 'hello world' , $tpl -> cached -> handler -> getCachedContent ( $tpl3 ));
}
public function testClearCacheCacheIdCompileId3 ()
{
$this -> smarty -> caching = true ;
$this -> smarty -> cache_lifetime = 1000 ;
$this -> smarty -> clearAllCache ();
// create and cache templates
$tpl = $this -> smarty -> createTemplate ( 'helloworld.tpl' , 'foo|bar' , 'blar' );
$tpl -> writeCachedContent ( 'hello world' );
$tpl2 = $this -> smarty -> createTemplate ( 'helloworld.tpl' , 'foo|bar' , 'blar2' );
$tpl2 -> writeCachedContent ( 'hello world' );
$tpl3 = $this -> smarty -> createTemplate ( 'helloworld2.tpl' , 'foo|bar' , 'blar' );
$tpl3 -> writeCachedContent ( 'hello world' );
// test cached content
$this -> assertEquals ( 'hello world' , $tpl -> cached -> handler -> getCachedContent ( $tpl ));
$this -> assertEquals ( 'hello world' , $tpl -> cached -> handler -> getCachedContent ( $tpl2 ));
$this -> assertEquals ( 'hello world' , $tpl -> cached -> handler -> getCachedContent ( $tpl3 ));
// test number of deleted caches
$this -> doClearCacheAssertion ( 1 , $this -> smarty -> clearCache ( 'helloworld.tpl' , null , 'blar2' ));
// test that caches are deleted properly
$this -> assertEquals ( 'hello world' , $tpl -> cached -> handler -> getCachedContent ( $tpl ));
$this -> assertNull ( $tpl -> cached -> handler -> getCachedContent ( $tpl2 ));
$this -> assertEquals ( 'hello world' , $tpl -> cached -> handler -> getCachedContent ( $tpl3 ));
}
public function testClearCacheCacheIdCompileId3Sub ()
{
$this -> smarty -> caching = true ;
$this -> smarty -> cache_lifetime = 1000 ;
$this -> smarty -> clearAllCache ();
// create and cache templates
$tpl = $this -> smarty -> createTemplate ( 'helloworld.tpl' , 'foo|bar' , 'blar' );
$tpl -> writeCachedContent ( 'hello world' );
$tpl2 = $this -> smarty -> createTemplate ( 'helloworld.tpl' , 'foo|bar' , 'blar2' );
$tpl2 -> writeCachedContent ( 'hello world' );
$tpl3 = $this -> smarty -> createTemplate ( 'helloworld2.tpl' , 'foo|bar' , 'blar' );
$tpl3 -> writeCachedContent ( 'hello world' );
// test cached content
$this -> assertEquals ( 'hello world' , $tpl -> cached -> handler -> getCachedContent ( $tpl ));
$this -> assertEquals ( 'hello world' , $tpl -> cached -> handler -> getCachedContent ( $tpl2 ));
$this -> assertEquals ( 'hello world' , $tpl -> cached -> handler -> getCachedContent ( $tpl3 ));
// test number of deleted caches
$this -> doClearCacheAssertion ( 1 , $this -> smarty -> clearCache ( 'helloworld.tpl' , null , 'blar2' ));
// test that caches are deleted properly
$this -> assertEquals ( 'hello world' , $tpl -> cached -> handler -> getCachedContent ( $tpl ));
$this -> assertNull ( $tpl -> cached -> handler -> getCachedContent ( $tpl2 ));
$this -> assertEquals ( 'hello world' , $tpl -> cached -> handler -> getCachedContent ( $tpl3 ));
}
public function testClearCacheCacheIdCompileId4 ()
{
$this -> smarty -> caching = true ;
$this -> smarty -> cache_lifetime = 1000 ;
$this -> smarty -> clearAllCache ();
// create and cache templates
$tpl = $this -> smarty -> createTemplate ( 'helloworld.tpl' , 'foo|bar' , 'blar' );
$tpl -> writeCachedContent ( 'hello world' );
$tpl2 = $this -> smarty -> createTemplate ( 'helloworld.tpl' , 'foo|bar' , 'blar2' );
$tpl2 -> writeCachedContent ( 'hello world' );
$tpl3 = $this -> smarty -> createTemplate ( 'helloworld2.tpl' , 'foo|bar' , 'blar' );
$tpl3 -> writeCachedContent ( 'hello world' );
// test cached content
$this -> assertEquals ( 'hello world' , $tpl -> cached -> handler -> getCachedContent ( $tpl ));
$this -> assertEquals ( 'hello world' , $tpl -> cached -> handler -> getCachedContent ( $tpl2 ));
$this -> assertEquals ( 'hello world' , $tpl -> cached -> handler -> getCachedContent ( $tpl3 ));
// test number of deleted caches
$this -> doClearCacheAssertion ( 1 , $this -> smarty -> clearCache ( 'helloworld.tpl' , null , 'blar2' ));
// test that caches are deleted properly
$this -> assertEquals ( 'hello world' , $tpl -> cached -> handler -> getCachedContent ( $tpl ));
$this -> assertNull ( $tpl -> cached -> handler -> getCachedContent ( $tpl2 ));
$this -> assertEquals ( 'hello world' , $tpl -> cached -> handler -> getCachedContent ( $tpl3 ));
}
public function testClearCacheCacheIdCompileId4Sub ()
{
$this -> smarty -> caching = true ;
$this -> smarty -> cache_lifetime = 1000 ;
$this -> smarty -> clearAllCache ();
// create and cache templates
$tpl = $this -> smarty -> createTemplate ( 'helloworld.tpl' , 'foo|bar' , 'blar' );
$tpl -> writeCachedContent ( 'hello world' );
$tpl2 = $this -> smarty -> createTemplate ( 'helloworld.tpl' , 'foo|bar' , 'blar2' );
$tpl2 -> writeCachedContent ( 'hello world' );
$tpl3 = $this -> smarty -> createTemplate ( 'helloworld2.tpl' , 'foo|bar' , 'blar' );
$tpl3 -> writeCachedContent ( 'hello world' );
// test cached content
$this -> assertEquals ( 'hello world' , $tpl -> cached -> handler -> getCachedContent ( $tpl ));
$this -> assertEquals ( 'hello world' , $tpl -> cached -> handler -> getCachedContent ( $tpl2 ));
$this -> assertEquals ( 'hello world' , $tpl -> cached -> handler -> getCachedContent ( $tpl3 ));
// test number of deleted caches
$this -> doClearCacheAssertion ( 1 , $this -> smarty -> clearCache ( 'helloworld.tpl' , null , 'blar2' ));
// test that caches are deleted properly
$this -> assertEquals ( 'hello world' , $tpl -> cached -> handler -> getCachedContent ( $tpl ));
$this -> assertNull ( $tpl -> cached -> handler -> getCachedContent ( $tpl2 ));
$this -> assertEquals ( 'hello world' , $tpl -> cached -> handler -> getCachedContent ( $tpl3 ));
}
public function testClearCacheCacheIdCompileId5 ()
{
$this -> smarty -> caching = true ;
$this -> smarty -> cache_lifetime = 1000 ;
$this -> smarty -> clearAllCache ();
// create and cache templates
$tpl = $this -> smarty -> createTemplate ( 'helloworld.tpl' , 'foo|bar' , 'blar' );
$tpl -> writeCachedContent ( 'hello world' );
$tpl2 = $this -> smarty -> createTemplate ( 'helloworld.tpl' , 'foo|bar' , 'blar2' );
$tpl2 -> writeCachedContent ( 'hello world' );
$tpl3 = $this -> smarty -> createTemplate ( 'helloworld2.tpl' , 'foo|bar' , 'blar' );
$tpl3 -> writeCachedContent ( 'hello world' );
// test cached content
$this -> assertEquals ( 'hello world' , $tpl -> cached -> handler -> getCachedContent ( $tpl ));
$this -> assertEquals ( 'hello world' , $tpl -> cached -> handler -> getCachedContent ( $tpl2 ));
$this -> assertEquals ( 'hello world' , $tpl -> cached -> handler -> getCachedContent ( $tpl3 ));
// test number of deleted caches
$this -> doClearCacheAssertion ( 2 , $this -> smarty -> clearCache ( null , null , 'blar' ));
// test that caches are deleted properly
$this -> assertNull ( $tpl -> cached -> handler -> getCachedContent ( $tpl ));
$this -> assertEquals ( 'hello world' , $tpl -> cached -> handler -> getCachedContent ( $tpl2 ));
$this -> assertNull ( $tpl -> cached -> handler -> getCachedContent ( $tpl3 ));
}
public function testClearCacheCacheIdCompileId5Sub ()
{
$this -> smarty -> caching = true ;
$this -> smarty -> cache_lifetime = 1000 ;
$this -> smarty -> clearAllCache ();
// create and cache templates
$tpl = $this -> smarty -> createTemplate ( 'helloworld.tpl' , 'foo|bar' , 'blar' );
$tpl -> writeCachedContent ( 'hello world' );
$tpl2 = $this -> smarty -> createTemplate ( 'helloworld.tpl' , 'foo|bar' , 'blar2' );
$tpl2 -> writeCachedContent ( 'hello world' );
$tpl3 = $this -> smarty -> createTemplate ( 'helloworld2.tpl' , 'foo|bar' , 'blar' );
$tpl3 -> writeCachedContent ( 'hello world' );
// test cached content
$this -> assertEquals ( 'hello world' , $tpl -> cached -> handler -> getCachedContent ( $tpl ));
$this -> assertEquals ( 'hello world' , $tpl -> cached -> handler -> getCachedContent ( $tpl2 ));
$this -> assertEquals ( 'hello world' , $tpl -> cached -> handler -> getCachedContent ( $tpl3 ));
// test number of deleted caches
$this -> doClearCacheAssertion ( 2 , $this -> smarty -> clearCache ( null , null , 'blar' ));
// test that caches are deleted properly
$this -> assertNull ( $tpl -> cached -> handler -> getCachedContent ( $tpl ));
$this -> assertEquals ( 'hello world' , $tpl -> cached -> handler -> getCachedContent ( $tpl2 ));
$this -> assertNull ( $tpl -> cached -> handler -> getCachedContent ( $tpl3 ));
}
public function testClearCacheCacheFile ()
{
$this -> smarty -> caching = true ;
$this -> smarty -> cache_lifetime = 1000 ;
$this -> smarty -> clearAllCache ();
// create and cache templates
$tpl = $this -> smarty -> createTemplate ( 'helloworld.tpl' );
$tpl -> writeCachedContent ( 'hello world' );
$tpl2 = $this -> smarty -> createTemplate ( 'helloworld.tpl' , null , 'bar' );
$tpl2 -> writeCachedContent ( 'hello world' );
$tpl3 = $this -> smarty -> createTemplate ( 'helloworld.tpl' , 'buh|blar' );
$tpl3 -> writeCachedContent ( 'hello world' );
$tpl4 = $this -> smarty -> createTemplate ( 'helloworld2.tpl' );
$tpl4 -> writeCachedContent ( 'hello world' );
// test cached content
$this -> assertEquals ( 'hello world' , $tpl -> cached -> handler -> getCachedContent ( $tpl ));
$this -> assertEquals ( 'hello world' , $tpl -> cached -> handler -> getCachedContent ( $tpl2 ));
$this -> assertEquals ( 'hello world' , $tpl -> cached -> handler -> getCachedContent ( $tpl3 ));
$this -> assertEquals ( 'hello world' , $tpl -> cached -> handler -> getCachedContent ( $tpl4 ));
// test number of deleted caches
$this -> doClearCacheAssertion ( 3 , $this -> smarty -> clearCache ( 'helloworld.tpl' ));
// test that caches are deleted properly
$this -> assertNull ( $tpl -> cached -> handler -> getCachedContent ( $tpl ));
$this -> assertNull ( $tpl -> cached -> handler -> getCachedContent ( $tpl2 ));
$this -> assertNull ( $tpl -> cached -> handler -> getCachedContent ( $tpl3 ));
$this -> assertEquals ( 'hello world' , $tpl -> cached -> handler -> getCachedContent ( $tpl4 ));
}
public function testClearCacheCacheFileSub ()
{
$this -> smarty -> caching = true ;
$this -> smarty -> cache_lifetime = 1000 ;
$this -> smarty -> clearAllCache ();
// create and cache templates
$tpl = $this -> smarty -> createTemplate ( 'helloworld.tpl' );
$tpl -> writeCachedContent ( 'hello world' );
$tpl2 = $this -> smarty -> createTemplate ( 'helloworld.tpl' , null , 'bar' );
$tpl2 -> writeCachedContent ( 'hello world' );
$tpl3 = $this -> smarty -> createTemplate ( 'helloworld.tpl' , 'buh|blar' );
$tpl3 -> writeCachedContent ( 'hello world' );
$tpl4 = $this -> smarty -> createTemplate ( 'helloworld2.tpl' );
$tpl4 -> writeCachedContent ( 'hello world' );
// test cached content
$this -> assertEquals ( 'hello world' , $tpl -> cached -> handler -> getCachedContent ( $tpl ));
$this -> assertEquals ( 'hello world' , $tpl -> cached -> handler -> getCachedContent ( $tpl2 ));
$this -> assertEquals ( 'hello world' , $tpl -> cached -> handler -> getCachedContent ( $tpl3 ));
$this -> assertEquals ( 'hello world' , $tpl -> cached -> handler -> getCachedContent ( $tpl4 ));
// test number of deleted caches
$this -> doClearCacheAssertion ( 3 , $this -> smarty -> clearCache ( 'helloworld.tpl' ));
// test that caches are deleted properly
$this -> assertNull ( $tpl -> cached -> handler -> getCachedContent ( $tpl ));
$this -> assertNull ( $tpl -> cached -> handler -> getCachedContent ( $tpl2 ));
$this -> assertNull ( $tpl -> cached -> handler -> getCachedContent ( $tpl3 ));
$this -> assertEquals ( 'hello world' , $tpl -> cached -> handler -> getCachedContent ( $tpl4 ));
}
2015-05-06 22:54:41 +02:00
/**
* Test
2015-05-10 12:52:00 +02:00
* @run inSeparateProcess
2015-05-06 22:54:41 +02:00
* @preserveGlobalState disabled
2015-05-10 12:52:00 +02:00
* @dataProvider data
2015-05-06 22:54:41 +02:00
*
*/
2015-05-10 12:52:00 +02:00
public function testCache ( $lockTime , $lockTimeout , $compile_id , $cache_id , $isCached , $tmin , $tmax , $forceCompile , $forceCache , $update , $testNumber , $compileTestNumber , $renderTestNumber , $testName )
2015-05-06 22:54:41 +02:00
{
2015-08-23 15:04:21 +02:00
if ( $testNumber == 13 ) {
2015-05-10 12:52:00 +02:00
$i = 0 ;
2015-05-06 22:54:41 +02:00
}
$this -> smarty -> caching = true ;
$this -> smarty -> cache_lifetime = 1000 ;
2015-05-10 12:52:00 +02:00
$this -> smarty -> assign ( 'test' , $testNumber );
if ( $lockTimeout ) {
$this -> smarty -> cache_locking = true ;
$this -> smarty -> locking_timeout = $lockTimeout ;
}
$this -> smarty -> compile_id = $compile_id ;
$this -> smarty -> cache_id = $cache_id ;
$this -> smarty -> force_compile = $forceCompile ;
$this -> smarty -> force_cache = $forceCache ;
if ( $update ) {
sleep ( 1 );
$filepath = $this -> buildSourcePath ( null , 'cacheresource.tpl' , 'file' );
touch ( $filepath , $t = time ());
clearstatcache ();
}
2015-05-06 22:54:41 +02:00
$tpl = $this -> smarty -> createTemplate ( 'cacheresource.tpl' , $this -> smarty );
2015-05-10 12:52:00 +02:00
if ( $update ) {
2015-07-01 03:13:32 +02:00
$this -> assertEquals ( $t , $tpl -> source -> getTimeStamp (), $testName . ' - source touch' );
2015-05-10 12:52:00 +02:00
}
if ( $lockTime ) {
$tpl -> cached -> handler -> acquireLock ( $this -> smarty , $tpl -> cached );
$tpl -> cached -> handler -> lockTime = $lockTime ;
$tpl -> cached -> is_locked = false ;
}
2015-05-06 22:54:41 +02:00
$start = time ();
2015-05-10 12:52:00 +02:00
if ( isset ( $isCached )) {
$this -> assertEquals ( $isCached , $tpl -> isCached (), $testName . ' - isCached()' );
if ( $lockTimeout ) {
$time = time () - $start ;
$this -> assertTrue ( $time >= $tmin && $time <= $tmax , $testName . ' - isCached() - lock time' );
$this -> assertEquals ( ! $isCached , $tpl -> cached -> handler -> hasLock ( $this -> smarty , $tpl -> cached ), $testName . ' - isCached() - lock status' );
} else {
$this -> assertFalse ( $tpl -> cached -> handler -> hasLock ( $this -> smarty , $tpl -> cached ), $testName . ' - isCached() - unexpected lock' );
}
}
$this -> assertEquals ( "cache resource test: { $testNumber } compiled: { $compileTestNumber } rendered: { $renderTestNumber } " , $this -> smarty -> fetch ( $tpl ), $testName . ' - fetch() failure' );
if ( $lockTime ) {
$time = time () - $start ;
$this -> assertTrue ( $time >= $tmin && $time <= $tmax , $testName . ' - fetch() - lock time' );
}
$this -> assertFalse ( $tpl -> cached -> handler -> hasLock ( $this -> smarty , $tpl -> cached , $testName . ' - lock not removed' ));
}
public function data (){
return array (
/*
* lock time
* locking_timeout 0 = no cache_locking
* compile_id
* cache_id
* isCached() expected result (null = no isCached test)
* min elapsed time
* max elapsed time
* force compile
* force cache
* source update
* test nr
* result compile nr
* result render nr
* text
*/
array ( 0 , 0 , null , null , false , 0 , 0 , false , false , false , 1 , 1 , 1 , 'locking off - create cache' ),
array ( 0 , 0 , 1 , null , false , 0 , 0 , false , false , false , 2 , 2 , 2 , 'locking off - create cache compile_id' ),
array ( 0 , 0 , null , 2 , false , 0 , 0 , false , false , false , 3 , 1 , 3 , 'locking off - create cache cache_id' ),
array ( 0 , 0 , 3 , 4 , false , 0 , 0 , false , false , false , 4 , 4 , 4 , 'locking off - create cache cache_id & compile_id' ),
array ( 0 , 0 , null , null , null , 0 , 0 , false , false , false , 5 , 1 , 1 , 'locking off - fetch' ),
array ( 0 , 0 , 1 , null , null , 0 , 0 , false , false , false , 6 , 2 , 2 , 'locking off - fetch compile_id' ),
array ( 0 , 0 , null , 2 , null , 0 , 0 , false , false , false , 7 , 1 , 3 , 'locking off - fetch cache_id' ),
array ( 0 , 0 , 3 , 4 , null , 0 , 0 , false , false , false , 8 , 4 , 4 , 'locking off - fetch cache_id & compile_id' ),
array ( 0 , 0 , null , null , true , 0 , 0 , false , false , false , 9 , 1 , 1 , 'locking off - isCached & fetch' ),
array ( 0 , 0 , 1 , null , true , 0 , 0 , false , false , false , 10 , 2 , 2 , 'locking off - isCached & fetch compile_id' ),
array ( 0 , 0 , null , 2 , true , 0 , 0 , false , false , false , 11 , 1 , 3 , 'locking off - isCached & fetch cache_id' ),
array ( 0 , 0 , 3 , 4 , true , 0 , 0 , false , false , false , 12 , 4 , 4 , 'locking off - isCached & fetch cache_id & compile_id' ),
array ( 0 , 0 , null , null , false , 0 , 0 , true , false , false , 13 , 13 , 13 , 'locking off - force compile' ),
array ( 0 , 0 , null , null , true , 0 , 0 , false , false , false , 14 , 13 , 13 , 'locking off - after force compile' ),
2015-07-28 00:50:27 +02:00
array ( 0 , 0 , null , null , false , 0 , 0 , false , true , false , 15 , ( $this instanceof CacheResourceFileTest && strpos ( phpversion (), 'hhvm' ) !== false ) ? 1 : 13 , 15 , 'locking off - force cache' ),
array ( 0 , 0 , null , null , true , 0 , 0 , false , false , false , 16 , ( $this instanceof CacheResourceFileTest && strpos ( phpversion (), 'hhvm' ) !== false ) ? 1 : 13 , 15 , 'locking off - after force cache' ),
2015-05-10 12:52:00 +02:00
array ( 0 , 0 , null , null , false , 0 , 0 , false , false , true , 17 , 17 , 17 , 'locking off - new source' ),
array ( 0 , 0 , null , null , true , 0 , 0 , false , false , false , 18 , 17 , 17 , 'locking off - after new source' ),
array ( 0 , 5 , null , null , null , 0 , 1 , false , false , false , 19 , 17 , 17 , 'not locked - fetch' ),
array ( 0 , 5 , null , null , true , 0 , 1 , false , false , false , 20 , 17 , 17 , 'not locked - isCached & fetch' ),
array ( 0 , 5 , null , null , false , 0 , 1 , false , false , true , 21 , 21 , 21 , 'not locked - new source' ),
array ( 0 , 5 , null , null , true , 0 , 1 , false , false , false , 22 , 21 , 21 , 'not locked - after new source' ),
array ( 4 , 10 , null , null , null , 2 , 6 , false , false , false , 23 , 21 , 21 , 'locked - fetch' ),
array ( 4 , 10 , null , null , true , 2 , 6 , false , false , false , 24 , 21 , 21 , 'locked - isCached & fetch' ),
array ( 4 , 10 , null , null , false , 2 , 6 , false , false , true , 25 , 25 , 25 , 'locked - new source' ),
array ( 4 , 10 , null , null , true , 2 , 6 , false , false , false , 26 , 25 , 25 , 'locked - after new source' ),
array ( 10 , 4 , null , null , null , 2 , 6 , false , false , false , 27 , 25 , 25 , 'lock timeout - fetch' ),
array ( 10 , 4 , null , null , true , 2 , 6 , false , false , false , 28 , 25 , 25 , 'lock timeout - isCached & fetch' ),
array ( 10 , 4 , null , null , false , 2 , 6 , false , false , true , 29 , 29 , 29 , 'lock timeout - new source' ),
array ( 10 , 4 , null , null , true , 2 , 6 , false , false , false , 30 , 29 , 29 , 'lock timeout - after new source' ),
array ( 4 , 10 , 5 , null , false , 2 , 6 , false , false , false , 31 , 31 , 31 , 'locked - new compiled' ),
array ( 10 , 4 , 6 , null , false , 2 , 6 , false , false , false , 32 , 32 , 32 , 'lock timeout - new compiled' ),
);
2015-05-06 22:54:41 +02:00
}
/**
2015-05-10 12:52:00 +02:00
*
2015-05-06 22:54:41 +02:00
* @run InSeparateProcess
* @preserveGlobalState disabled
*
*/
2015-05-10 12:52:00 +02:00
public function testCachingDisabled1 ()
2015-05-06 22:54:41 +02:00
{
2015-05-10 12:52:00 +02:00
$this -> smarty -> assign ( 'test' , 50 );
2015-05-06 22:54:41 +02:00
$tpl = $this -> smarty -> createTemplate ( 'cacheresource.tpl' , $this -> smarty );
2015-05-10 12:52:00 +02:00
$this -> assertFalse ( $tpl -> isCached (), 'isCached() status' );
$this -> assertEquals ( 'cache resource test:50 compiled:50 rendered:50' , $this -> smarty -> fetch ( $tpl ), 'fetch()' );
2015-05-06 22:54:41 +02:00
}
/**
2015-05-10 12:52:00 +02:00
*
2015-05-06 22:54:41 +02:00
* @run InSeparateProcess
* @preserveGlobalState disabled
*
*/
2015-05-10 12:52:00 +02:00
public function testCachingDisabled2 ()
2015-05-06 22:54:41 +02:00
{
2015-05-10 12:52:00 +02:00
$this -> smarty -> assign ( 'test' , 51 );
2015-05-06 22:54:41 +02:00
$tpl = $this -> smarty -> createTemplate ( 'cacheresource.tpl' , $this -> smarty );
2015-05-10 12:52:00 +02:00
$this -> assertFalse ( $tpl -> isCached (), 'isCached() status' );
$this -> assertEquals ( 'cache resource test:51 compiled:50 rendered:51' , $this -> smarty -> fetch ( $tpl ), 'fetch()' );
2015-05-06 22:54:41 +02:00
}
2015-05-10 12:52:00 +02:00
2015-05-04 03:00:52 +02:00
}