Update msql resource test

This commit is contained in:
Uwe Tews
2017-11-19 19:52:31 +01:00
parent 0d8ddddc1b
commit ccefb46c30
3 changed files with 89 additions and 49 deletions

View File

@@ -24,36 +24,96 @@ if (MysqlResourceEnable == true) {
$this->getConnection(); $this->getConnection();
} }
$this->setUpSmarty(dirname(__FILE__)); $this->setUpSmarty(dirname(__FILE__));
$this->smarty->addPluginsDir("./PHPunitplugins/");
} }
/**
*
*/
public function testInit() public function testInit()
{ {
$this->cleanDirs(); $this->cleanDirs();
$this->initMysqlResource(); $this->initMysqlResource();
PHPUnit_Smarty::$pdo->exec("REPLACE INTO templates VALUES ('test.tpl', '2010-12-25 22:00:00', '{\$x = \'hello world\'}{\$x}' )"); $time = date('Y-m-d H:i:s');
PHPUnit_Smarty::$pdo->exec("REPLACE INTO templates VALUES ('template.tpl', '2010-12-25 22:00:00', 'template = {\$smarty.template}' )"); PHPUnit_Smarty::$pdo->exec("REPLACE INTO templates VALUES ('test.tpl', '{$time}' , '{\$x = \'hello world\'}{\$x}' )");
PHPUnit_Smarty::$pdo->exec("REPLACE INTO templates VALUES ('current_dir.tpl', '2010-12-25 22:00:00', 'current_dir = {\$smarty.current_dir}' )");
} }
/** /**
* test resource plugin rendering of a custom resource * test resource plugin rendering of a custom resource
*
* @runInSeparateProcess
* @preserveGlobalState disabled
*
*/ */
public function testResourcePluginMysql() public function testResourcePluginMysql()
{ {
//$this->smarty->addPluginsDir(SMARTY_DIR . "../demo/plugins/");
$this->smarty->addPluginsDir("./PHPunitplugins/");
$this->assertEquals('hello world', $this->smarty->fetch('mysqltest:test.tpl')); $this->assertEquals('hello world', $this->smarty->fetch('mysqltest:test.tpl'));
} }
/** /**
* test resource plugin timestamp of a custom resource * test must compile
*
* @runInSeparateProcess
* @preserveGlobalState disabled
*
*/ */
public function testResourcePluginMysqlTimestamp() public function testMustCompile()
{ {
// $this->smarty->addPluginsDir(SMARTY_DIR . "../demo/plugins/");
$this->smarty->addPluginsDir("./PHPunitplugins/");
$tpl = $this->smarty->createTemplate('mysqltest:test.tpl'); $tpl = $this->smarty->createTemplate('mysqltest:test.tpl');
$this->assertEquals(strtotime("2010-12-25 22:00:00"), $tpl->source->getTimeStamp()); $this->assertFalse($tpl->mustCompile());
}
/**
* test must compile
*
* @runInSeparateProcess
* @preserveGlobalState disabled
*
*/
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}' )");
$tpl = $this->smarty->createTemplate('mysqltest:test.tpl');
$this->assertTrue($tpl->mustCompile());
}
/**
* test resource plugin rendering of a custom resource
*
* @runInSeparateProcess
* @preserveGlobalState disabled
*
*/
public function testResourcePluginMysql2()
{
$this->assertEquals('hello smarty', $this->smarty->fetch('mysqltest:test.tpl'));
}
/**
* test clear compiled
*
* @runInSeparateProcess
* @preserveGlobalState disabled
*
*/
public function testClearCompiled()
{
$this->assertEquals(1, $this->smarty->clearCompiledTemplate('mysqltest:test.tpl'));
}
/**
* test must compile
*
* @runInSeparateProcess
* @preserveGlobalState disabled
*
*/
public function testMustCompile3()
{
$tpl = $this->smarty->createTemplate('mysqltest:test.tpl');
$this->assertTrue($tpl->mustCompile());
} }
/** /**
@@ -61,16 +121,14 @@ if (MysqlResourceEnable == true) {
*/ */
public function testResourcePluginMysqlCompiledFilepath() public function testResourcePluginMysqlCompiledFilepath()
{ {
// $this->smarty->addPluginsDir(SMARTY_DIR . "../demo/plugins/"); //$this->smarty->addPluginsDir("./PHPunitplugins/");
$this->smarty->addPluginsDir("./PHPunitplugins/");
$tpl = $this->smarty->createTemplate('mysqltest:test.tpl'); $tpl = $this->smarty->createTemplate('mysqltest:test.tpl');
$this->assertEquals($this->buildCompiledPath($tpl, false, false, null, 'test.tpl', 'mysqltest', $this->smarty->getTemplateDir(0)), $tpl->compiled->filepath); $this->assertEquals($this->buildCompiledPath($tpl, false, false, null, 'test.tpl', 'mysqltest', $this->smarty->getTemplateDir(0)), $tpl->compiled->filepath);
} }
public function testResourcePluginMysqlCompiledFilepathCache() public function testResourcePluginMysqlCompiledFilepathCache()
{ {
//$this->smarty->addPluginsDir(SMARTY_DIR . "../demo/plugins/"); //$this->smarty->addPluginsDir("./PHPunitplugins/");
$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);
@@ -81,30 +139,16 @@ if (MysqlResourceEnable == true) {
} }
/** /**
* test resource plugin timestamp of a custom resource with only fetch() implemented * test unknown template
*/ *
public function testResourcePluginMysqlTimestampWithoutFetchTimestamp() * @expectedException SmartyException
{ * @expectedExceptionMessage Unable to load template 'mysqlstest:foo.tpl'
// $this->smarty->addPluginsDir(SMARTY_DIR . "../demo/plugins/"); * @runInSeparateProcess
$this->smarty->addPluginsDir("./PHPunitplugins/"); * @preserveGlobalState disabled
$tpl = $this->smarty->createTemplate('mysqlstest:test.tpl');
$this->assertEquals(strtotime("2010-12-25 22:00:00"), $tpl->source->getTimeStamp());
}
/**
* test {$smarty.template}
* *
*/ */
public function testSmartyTemplate() { public function testUnknownTemplate() {
$this->smarty->addPluginsDir("./PHPunitplugins/"); $this->assertEquals('foo', $this->smarty->fetch('mysqlstest:foo.tpl'));
$this->assertEquals('template = mysqlstest:template.tpl', $this->smarty->fetch('mysqlstest:template.tpl'));
}
/**
* test {$smarty.current_dir}
*
*/
public function testSmartyCurrentDir() {
$this->smarty->addPluginsDir("./PHPunitplugins/");
$this->assertEquals('current_dir = .', $this->smarty->fetch('mysqlstest:current_dir.tpl'));
} }
} }
} }

View File

@@ -1,2 +0,0 @@
{block name="alpha"}templates{/block}
{block name="bravo_2"}templates{/block}

View File

@@ -1,2 +0,0 @@
{block name="alpha"}templates{/block}
{block name="bravo_2"}templates{/block}