Update mysql tests

This commit is contained in:
Uwe Tews
2017-11-20 00:55:43 +01:00
parent ccefb46c30
commit b3a64efa14
5 changed files with 66 additions and 23 deletions

View File

@@ -9,10 +9,10 @@
define('individualFolders', true); define('individualFolders', true);
define('MemCacheEnable', false); define('MemCacheEnable', false);
define('ApcCacheEnable', false); define('ApcCacheEnable', false);
define('MysqlCacheEnable', false); define('MysqlCacheEnable', true);
define('PdoCacheEnable', false); define('PdoCacheEnable', false);
define('PdoGzipCacheEnable', false); define('PdoGzipCacheEnable', false);
define('MysqlResourceEnable', false); define('MysqlResourceEnable', true);
define('DB_DSN', "mysql:dbname=test;host=localhost"); define('DB_DSN', "mysql:dbname=test;host=localhost");
define('DB_USER', "travis"); define('DB_USER', "travis");
define('DB_PASSWD', ""); define('DB_PASSWD', "");

View File

@@ -112,6 +112,7 @@ class PHPUnit_Smarty extends PHPUnit_Framework_TestCase
*/ */
public function __construct($name = null, array $data = array(), $dataName = '') public function __construct($name = null, array $data = array(), $dataName = '')
{ {
date_default_timezone_set('Europe/Berlin');
if (!defined('individualFolders')) { if (!defined('individualFolders')) {
define('individualFolders', true); define('individualFolders', true);
} }
@@ -193,7 +194,9 @@ class PHPUnit_Smarty extends PHPUnit_Framework_TestCase
throw new SmartyException('Mysql Resource failed: ' . $e->getMessage()); throw new SmartyException('Mysql Resource failed: ' . $e->getMessage());
} }
$timezone = date_default_timezone_get(); $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, `source` text,
PRIMARY KEY (`name`) PRIMARY KEY (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8"); ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
} }
/** /**
@@ -222,20 +226,34 @@ PRIMARY KEY (`name`)
$this->getConnection(); $this->getConnection();
PHPUnit_Smarty::$pdo->exec("DROP TABLE `output_cache`"); PHPUnit_Smarty::$pdo->exec("DROP TABLE `output_cache`");
PHPUnit_Smarty::$pdo->exec("CREATE TABLE IF NOT EXISTS `output_cache` ( PHPUnit_Smarty::$pdo->exec("CREATE TABLE IF NOT EXISTS `output_cache` (
`id` char(40) NOT NULL COMMENT 'sha1 hash', `name` varchar(256) NOT NULL,
`name` varchar(250) NOT NULL, `id` char(40) NOT NULL,
`cache_id` varchar(250) DEFAULT NULL, `cache_id` varchar(250) DEFAULT NULL,
`compile_id` varchar(250) DEFAULT NULL, `compile_id` varchar(250) DEFAULT NULL,
`modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`expire` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', `content` mediumblob NOT NULL,
`content` mediumblob NOT NULL,
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
KEY `name` (`name`),
KEY `cache_id` (`cache_id`), KEY `cache_id` (`cache_id`),
KEY `compile_id` (`compile_id`), KEY `compile_id` (`compile_id`),
KEY `modified` (`modified`), KEY `modified` (`modified`),
KEY `expire` (`expire`) KEY `name` (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8"); ) 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");
} }
/** /**

View File

@@ -21,6 +21,7 @@ if (MysqlCacheEnable == true) {
public function setUp() public function setUp()
{ {
if (MysqlCacheEnable != true) { if (MysqlCacheEnable != true) {
$this->markTestSkipped('mysql tests are disabled'); $this->markTestSkipped('mysql tests are disabled');
} }

View File

@@ -17,8 +17,8 @@ class CacheResourceTestCommon extends PHPUnit_Smarty
public function setUp() public function setUp()
{ {
$this->smarty->setTemplateDir(dirname(__FILE__) . '/../_shared/templates'); $this->smarty->setTemplateDir(dirname(__FILE__) . '/templates');
$this->smarty->addPluginsDir(dirname(__FILE__) . '/../_shared/PHPunitplugins'); $this->smarty->addPluginsDir(dirname(__FILE__) . '/PHPunitplugins');
$this->smarty->registerFilter('pre', array($this, 'compiledPrefilter')); $this->smarty->registerFilter('pre', array($this, 'compiledPrefilter'));
} }
@@ -90,7 +90,7 @@ class CacheResourceTestCommon extends PHPUnit_Smarty
$tpl->writeCachedContent('hello world'); $tpl->writeCachedContent('hello world');
$this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl)); $this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl));
// Custom CacheResources may return -1 if they can't tell the number of deleted elements // 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->assertNull($tpl->cached->handler->getCachedContent($tpl3));
$this->assertEquals('hello world', $tpl->cached->handler->getCachedContent($tpl4)); $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() public function testClearCacheCacheFileSub()
{ {

View File

@@ -34,8 +34,7 @@ if (MysqlResourceEnable == true) {
{ {
$this->cleanDirs(); $this->cleanDirs();
$this->initMysqlResource(); $this->initMysqlResource();
$time = date('Y-m-d H:i:s'); PHPUnit_Smarty::$pdo->exec("REPLACE INTO templates (name, source) VALUES ('test.tpl', '{\$x = \'hello world\'}{\$x}')");
PHPUnit_Smarty::$pdo->exec("REPLACE INTO templates VALUES ('test.tpl', '{$time}' , '{\$x = \'hello world\'}{\$x}' )");
} }
/** /**
@@ -73,8 +72,7 @@ if (MysqlResourceEnable == true) {
public function testMustCompile2() public function testMustCompile2()
{ {
sleep(2); sleep(2);
$time = date('Y-m-d H:i:s'); PHPUnit_Smarty::$pdo->exec("REPLACE INTO templates (name, source) VALUES ('test.tpl', '{\$x = \'hello smarty\'}{\$x}' )");
PHPUnit_Smarty::$pdo->exec("REPLACE INTO templates VALUES ('test.tpl', '{$time}' , '{\$x = \'hello smarty\'}{\$x}' )");
$tpl = $this->smarty->createTemplate('mysqltest:test.tpl'); $tpl = $this->smarty->createTemplate('mysqltest:test.tpl');
$this->assertTrue($tpl->mustCompile()); $this->assertTrue($tpl->mustCompile());
} }
@@ -128,7 +126,6 @@ if (MysqlResourceEnable == true) {
public function testResourcePluginMysqlCompiledFilepathCache() public function testResourcePluginMysqlCompiledFilepathCache()
{ {
//$this->smarty->addPluginsDir("./PHPunitplugins/");
$this->smarty->caching = true; $this->smarty->caching = true;
$this->smarty->cache_lifetime = 1000; $this->smarty->cache_lifetime = 1000;
$this->smarty->setForceCompile(true); $this->smarty->setForceCompile(true);