add {$smarty.template} and {$smarty.current_dir} tests

This commit is contained in:
uwetews
2015-12-30 21:24:31 +01:00
parent b887f18acf
commit d0f29ae730
6 changed files with 78 additions and 14 deletions

View File

@@ -5,7 +5,7 @@
* @package PHPunit
* @author Uwe Tews
*/
if (defined(MysqlResourceEnable) && MysqlResourceEnable == 'true') {
if (MysqlResourceEnable == true) {
/**
* class for resource plugins tests
*
@@ -17,7 +17,10 @@ if (defined(MysqlResourceEnable) && MysqlResourceEnable == 'true') {
{
public function setUp()
{
if (self::$init) {
if (MysqlResourceEnable != true) {
$this->markTestSkipped('Msqlresource tests are disabled');
}
if (self::$init) {
$this->getConnection();
}
$this->setUpSmarty(__DIR__);
@@ -28,6 +31,8 @@ if (defined(MysqlResourceEnable) && MysqlResourceEnable == 'true') {
$this->cleanDirs();
$this->initMysqlResource();
PHPUnit_Smarty::$pdo->exec("REPLACE INTO templates VALUES ('test.tpl', '2010-12-25 22:00:00', '{\$x = \'hello world\'}{\$x}' )");
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 ('current_dir.tpl', '2010-12-25 22:00:00', 'current_dir = {\$smarty.current_dir}' )");
}
/**
@@ -85,5 +90,21 @@ if (defined(MysqlResourceEnable) && MysqlResourceEnable == 'true') {
$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() {
$this->smarty->addPluginsDir("./PHPunitplugins/");
$this->assertEquals('template = 001_smarty_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

@@ -200,7 +200,7 @@ class FileResourceTest extends PHPUnit_Smarty
/**
*
* @run InSeparateProcess
* @runInSeparateProcess
* @preserveGlobalState disabled
*
*/
@@ -239,7 +239,7 @@ class FileResourceTest extends PHPUnit_Smarty
/**
*
* @run InSeparateProcess
* @runInSeparateProcess
* @preserveGlobalState disabled
*
*/
@@ -255,7 +255,7 @@ class FileResourceTest extends PHPUnit_Smarty
/**
*
* @run InSeparateProcess
* @runInSeparateProcess
* @preserveGlobalState disabled
*
*/
@@ -271,7 +271,7 @@ class FileResourceTest extends PHPUnit_Smarty
/**
*
* @run InSeparateProcess
* @runInSeparateProcess
* @preserveGlobalState disabled
*
*/
@@ -292,7 +292,7 @@ class FileResourceTest extends PHPUnit_Smarty
/**
*
* @run InSeparateProcess
* @runInSeparateProcess
* @preserveGlobalState disabled
*
*/
@@ -564,4 +564,20 @@ class FileResourceTest extends PHPUnit_Smarty
));
$this->_relativeMap($map, $cwd);
}
/**
* test {$smarty.template}
*
*/
public function testSmartyTemplate() {
$this->assertEquals('template = 001_smarty_template.tpl', $this->smarty->fetch('001_smarty_template.tpl'));
}
/**
* test {$smarty.current_dir}
*
*/
public function testSmartyCurrentDir() {
$dirname = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'templates';
$this->assertEquals('current_dir = ' . $dirname, $this->smarty->fetch('001_smarty_current_dir.tpl'));
}
}

View File

@@ -0,0 +1 @@
current_dir = {$smarty.current_dir}

View File

@@ -0,0 +1 @@
template = {$smarty.template}

View File

@@ -67,8 +67,25 @@ class RegisteredResourceTest extends PHPUnit_Smarty
$this->assertEquals('this is template 2', $this->smarty->fetch('myresource:some'));
$this->assertEquals('this is template 2', $this->smarty->fetch('myresource:some'));
}
/**
* test {$smarty.template}
*
*/
public function testSmartyTemplate() {
$this->smarty->registerResource('mytpl', array('getTemplate', 'getTimestamp', 'getSecure', 'getTrusted'));
$this->assertEquals('template = mytpl:foo', $this->smarty->fetch('mytpl:foo'));
}
/**
* test {$smarty.current_dir}
*
*/
public function testSmartyCurrentDir() {
$this->smarty->registerResource('mytpl', array('getCurrentDir', 'getTimestamp', 'getSecure', 'getTrusted'));
$this->assertEquals('current_dir = .', $this->smarty->fetch('mytpl:bar'));
}
}
/**
* resource functions
*/
@@ -121,6 +138,20 @@ function getSource($name, &$source, $smarty)
return true;
}
function getTemplate($name, &$source, $smarty)
{
// construct a new source
$source = 'template = {$smarty.template}';
return true;
}
function getCurrentDir($name, &$source, $smarty)
{
// construct a new source
$source = 'current_dir = {$smarty.current_dir}';
return true;
}
function getTimestamp($name, &$timestamp, $smarty)
{

View File

@@ -17,13 +17,7 @@ class ResourcePluginTest extends PHPUnit_Smarty
{
public function setUp()
{
if (MysqlResourceEnable != true) {
$this->markTestSkipped('mysql tests are disabled');
}
if (self::$init) {
$this->getConnection();
}
$this->setUpSmarty(__DIR__);
$this->setUpSmarty(__DIR__);
}
public function testInit()