diff --git a/tests/UnitTests/ResourceTests/Custom/DemoPluginMysql/ResourceMysqlPluginTest.php b/tests/UnitTests/ResourceTests/Custom/DemoPluginMysql/ResourceMysqlPluginTest.php index 3926b261..293f84a5 100644 --- a/tests/UnitTests/ResourceTests/Custom/DemoPluginMysql/ResourceMysqlPluginTest.php +++ b/tests/UnitTests/ResourceTests/Custom/DemoPluginMysql/ResourceMysqlPluginTest.php @@ -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')); + } } } diff --git a/tests/UnitTests/ResourceTests/File/FileResourceTest.php b/tests/UnitTests/ResourceTests/File/FileResourceTest.php index b3b1e4c9..b0c4801a 100644 --- a/tests/UnitTests/ResourceTests/File/FileResourceTest.php +++ b/tests/UnitTests/ResourceTests/File/FileResourceTest.php @@ -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')); + } } diff --git a/tests/UnitTests/ResourceTests/File/templates/001_smarty_current_dir.tpl b/tests/UnitTests/ResourceTests/File/templates/001_smarty_current_dir.tpl new file mode 100644 index 00000000..9dfa5fe8 --- /dev/null +++ b/tests/UnitTests/ResourceTests/File/templates/001_smarty_current_dir.tpl @@ -0,0 +1 @@ +current_dir = {$smarty.current_dir} \ No newline at end of file diff --git a/tests/UnitTests/ResourceTests/File/templates/001_smarty_template.tpl b/tests/UnitTests/ResourceTests/File/templates/001_smarty_template.tpl new file mode 100644 index 00000000..b1c00b29 --- /dev/null +++ b/tests/UnitTests/ResourceTests/File/templates/001_smarty_template.tpl @@ -0,0 +1 @@ +template = {$smarty.template} \ No newline at end of file diff --git a/tests/UnitTests/ResourceTests/Registered/RegisteredResourceTest.php b/tests/UnitTests/ResourceTests/Registered/RegisteredResourceTest.php index a428b3dc..ee78bb1d 100644 --- a/tests/UnitTests/ResourceTests/Registered/RegisteredResourceTest.php +++ b/tests/UnitTests/ResourceTests/Registered/RegisteredResourceTest.php @@ -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) { diff --git a/tests/UnitTests/ResourceTests/ResourcePlugins/ResourcePluginTest.php b/tests/UnitTests/ResourceTests/ResourcePlugins/ResourcePluginTest.php index 8714479c..afc8f474 100644 --- a/tests/UnitTests/ResourceTests/ResourcePlugins/ResourcePluginTest.php +++ b/tests/UnitTests/ResourceTests/ResourcePlugins/ResourcePluginTest.php @@ -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()