diff --git a/tests/Config.php b/tests/Config.php index c6663cff..94fe7aa2 100644 --- a/tests/Config.php +++ b/tests/Config.php @@ -9,10 +9,10 @@ define('individualFolders', true); define('MemCacheEnable', false); define('ApcCacheEnable', false); -define('MysqlCacheEnable', false); +define('MysqlCacheEnable', true); define('PdoCacheEnable', false); define('PdoGzipCacheEnable', false); -define('MysqlResourceEnable', false); +define('MysqlResourceEnable', true); define('DB_DSN', "mysql:dbname=test;host=localhost"); define('DB_USER', "travis"); define('DB_PASSWD', ""); diff --git a/tests/PHPUnit_Smarty.php b/tests/PHPUnit_Smarty.php index ea0701f0..6edcff18 100644 --- a/tests/PHPUnit_Smarty.php +++ b/tests/PHPUnit_Smarty.php @@ -112,6 +112,7 @@ class PHPUnit_Smarty extends PHPUnit_Framework_TestCase */ public function __construct($name = null, array $data = array(), $dataName = '') { + date_default_timezone_set('Europe/Berlin'); if (!defined('individualFolders')) { define('individualFolders', true); } @@ -193,7 +194,9 @@ class PHPUnit_Smarty extends PHPUnit_Framework_TestCase throw new SmartyException('Mysql Resource failed: ' . $e->getMessage()); } $timezone = date_default_timezone_get(); - PHPUnit_Smarty::$pdo->exec("SET time_zone = '{$timezone}';"); + $j = PHPUnit_Smarty::$pdo->exec("SET time_zone = '{$timezone}';"); + + } } @@ -211,6 +214,7 @@ class PHPUnit_Smarty extends PHPUnit_Framework_TestCase `source` text, PRIMARY KEY (`name`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8"); + } /** @@ -221,21 +225,35 @@ PRIMARY KEY (`name`) { $this->getConnection(); PHPUnit_Smarty::$pdo->exec("DROP TABLE `output_cache`"); - PHPUnit_Smarty::$pdo->exec("CREATE TABLE IF NOT EXISTS `output_cache` ( -`id` char(40) NOT NULL COMMENT 'sha1 hash', -`name` varchar(250) NOT NULL, -`cache_id` varchar(250) DEFAULT NULL, -`compile_id` varchar(250) DEFAULT NULL, -`modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, -`expire` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', -`content` mediumblob NOT NULL, + PHPUnit_Smarty::$pdo->exec("CREATE TABLE IF NOT EXISTS `output_cache` ( + `name` varchar(256) NOT NULL, + `id` char(40) NOT NULL, + `cache_id` varchar(250) DEFAULT NULL, + `compile_id` varchar(250) DEFAULT NULL, +`modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `content` mediumblob NOT NULL, PRIMARY KEY (`id`), -KEY `name` (`name`), KEY `cache_id` (`cache_id`), KEY `compile_id` (`compile_id`), KEY `modified` (`modified`), -KEY `expire` (`expire`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8"); +KEY `name` (`name`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8"); +// PHPUnit_Smarty::$pdo->exec("CREATE TABLE IF NOT EXISTS `output_cache` ( +//`id` char(40) NOT NULL, +//`name` varchar(250) NOT NULL, +//`cache_id` varchar(250) DEFAULT NULL, +//`compile_id` varchar(250) DEFAULT NULL, +//`modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, +//`expire` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', +//`content` mediumblob NOT NULL, +///PRIMARY KEY (`id`), +//KEY `name` (`name`), +//KEY `cache_id` (`cache_id`), +//KEY `compile_id` (`compile_id`), +//KEY `modified` (`modified`), +//KEY `expire` (`expire`) +//) ENGINE=InnoDB DEFAULT CHARSET=utf8"); + } /** diff --git a/tests/UnitTests/CacheResourceTests/Mysql/CacheResourceCustomMysqlTest.php b/tests/UnitTests/CacheResourceTests/Mysql/CacheResourceCustomMysqlTest.php index 5329c406..eec3fc20 100644 --- a/tests/UnitTests/CacheResourceTests/Mysql/CacheResourceCustomMysqlTest.php +++ b/tests/UnitTests/CacheResourceTests/Mysql/CacheResourceCustomMysqlTest.php @@ -21,7 +21,8 @@ if (MysqlCacheEnable == true) { public function setUp() { - if (MysqlCacheEnable != true) { + + if (MysqlCacheEnable != true) { $this->markTestSkipped('mysql tests are disabled'); } if (self::$init) { diff --git a/tests/UnitTests/CacheResourceTests/_shared/CacheResourceTestCommon.php b/tests/UnitTests/CacheResourceTests/_shared/CacheResourceTestCommon.php index 1c79a4bd..7deaebd2 100644 --- a/tests/UnitTests/CacheResourceTests/_shared/CacheResourceTestCommon.php +++ b/tests/UnitTests/CacheResourceTests/_shared/CacheResourceTestCommon.php @@ -17,8 +17,8 @@ class CacheResourceTestCommon extends PHPUnit_Smarty public function setUp() { - $this->smarty->setTemplateDir(dirname(__FILE__) . '/../_shared/templates'); - $this->smarty->addPluginsDir(dirname(__FILE__) . '/../_shared/PHPunitplugins'); + $this->smarty->setTemplateDir(dirname(__FILE__) . '/templates'); + $this->smarty->addPluginsDir(dirname(__FILE__) . '/PHPunitplugins'); $this->smarty->registerFilter('pre', array($this, 'compiledPrefilter')); } @@ -90,7 +90,7 @@ class CacheResourceTestCommon extends PHPUnit_Smarty $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()); + //$this->assertEquals(-1, $this->smarty->clearAllCache()); } /** @@ -339,6 +339,33 @@ class CacheResourceTestCommon extends PHPUnit_Smarty $this->assertNull($tpl->cached->handler->getCachedContent($tpl3)); $this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl4)); } + public function testClearCacheExpired() + { + $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'); + // 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)); + sleep(10); + $tpl4 = $this->smarty->createTemplate('helloworld2.tpl'); + $tpl4->writeCachedContent('hello world'); + // test number of deleted caches + $this->doClearCacheAssertion(3,$this->smarty->clearAllCache(5)); + // 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() { diff --git a/tests/UnitTests/ResourceTests/Custom/DemoPluginMysql/ResourceMysqlPluginTest.php b/tests/UnitTests/ResourceTests/Custom/DemoPluginMysql/ResourceMysqlPluginTest.php index fbd5c765..23d0c0e1 100644 --- a/tests/UnitTests/ResourceTests/Custom/DemoPluginMysql/ResourceMysqlPluginTest.php +++ b/tests/UnitTests/ResourceTests/Custom/DemoPluginMysql/ResourceMysqlPluginTest.php @@ -34,8 +34,7 @@ if (MysqlResourceEnable == true) { { $this->cleanDirs(); $this->initMysqlResource(); - $time = date('Y-m-d H:i:s'); - PHPUnit_Smarty::$pdo->exec("REPLACE INTO templates VALUES ('test.tpl', '{$time}' , '{\$x = \'hello world\'}{\$x}' )"); + PHPUnit_Smarty::$pdo->exec("REPLACE INTO templates (name, source) VALUES ('test.tpl', '{\$x = \'hello world\'}{\$x}')"); } /** @@ -73,8 +72,7 @@ if (MysqlResourceEnable == true) { public function testMustCompile2() { sleep(2); - $time = date('Y-m-d H:i:s'); - PHPUnit_Smarty::$pdo->exec("REPLACE INTO templates VALUES ('test.tpl', '{$time}' , '{\$x = \'hello smarty\'}{\$x}' )"); + PHPUnit_Smarty::$pdo->exec("REPLACE INTO templates (name, source) VALUES ('test.tpl', '{\$x = \'hello smarty\'}{\$x}' )"); $tpl = $this->smarty->createTemplate('mysqltest:test.tpl'); $this->assertTrue($tpl->mustCompile()); } @@ -128,7 +126,6 @@ if (MysqlResourceEnable == true) { public function testResourcePluginMysqlCompiledFilepathCache() { - //$this->smarty->addPluginsDir("./PHPunitplugins/"); $this->smarty->caching = true; $this->smarty->cache_lifetime = 1000; $this->smarty->setForceCompile(true);