From 3229f0563bb54fb207cd5a6ee38423eca5b0eddb Mon Sep 17 00:00:00 2001 From: uwetews Date: Tue, 29 Dec 2015 20:51:56 +0100 Subject: [PATCH] Smarty2 wrapper tests --- .../RegisterFunction/RegisterFunctionTest.php | 125 +++++++++++++++--- 1 file changed, 107 insertions(+), 18 deletions(-) diff --git a/tests/UnitTests/SmartyMethodsTests/RegisterFunction/RegisterFunctionTest.php b/tests/UnitTests/SmartyMethodsTests/RegisterFunction/RegisterFunctionTest.php index 0ad025be..9af5898e 100644 --- a/tests/UnitTests/SmartyMethodsTests/RegisterFunction/RegisterFunctionTest.php +++ b/tests/UnitTests/SmartyMethodsTests/RegisterFunction/RegisterFunctionTest.php @@ -16,6 +16,8 @@ */ class RegisterFunctionTest extends PHPUnit_Smarty { + public $loadSmartyBC = true; + public function setUp() { $this->setUpSmarty(__DIR__); @@ -27,13 +29,13 @@ class RegisterFunctionTest extends PHPUnit_Smarty $this->cleanDirs(); } /** - * test register->templateFunction method for function + * test registerPlugin method for function */ public function testRegisterFunction() { $this->smarty->registerPlugin(Smarty::PLUGIN_FUNCTION, 'testfunction', 'myfunction'); $this->assertEquals('myfunction', $this->smarty->registered_plugins[Smarty::PLUGIN_FUNCTION]['testfunction'][0]); - $this->assertEquals('hello world 1', $this->smarty->fetch('eval:{testfunction value=1}')); + $this->assertEquals('hello world 1', $this->smarty->fetch('string:{testfunction value=1}')); } /** @@ -43,33 +45,82 @@ class RegisterFunctionTest extends PHPUnit_Smarty { $this->smarty->register_function('testfunction', 'myfunction'); $this->assertEquals('myfunction', $this->smarty->registered_plugins[Smarty::PLUGIN_FUNCTION]['testfunction'][0]); - $this->assertEquals('hello world 1', $this->smarty->fetch('eval:{testfunction value=1}')); + $this->assertEquals('hello world 12', $this->smarty->fetch('string:{testfunction value=12}')); + } + /** + * test SmartyBC for register_function method + */ + + public function testRegisterFunctionSmartyBC() + { + $this->smartyBC->register_function('testfunction', 'myfunction'); + $this->assertEquals('myfunction', $this->smartyBC->registered_plugins[Smarty::PLUGIN_FUNCTION]['testfunction'][0]); + $this->assertEquals('hello world 13', $this->smartyBC->fetch('string:{testfunction value=13}')); } /** - * test register->templateFunction method for class + * test registerPlugin method for function plugin by class */ public function testRegisterFunctionClass() { $this->smarty->registerPlugin(Smarty::PLUGIN_FUNCTION, 'testfunction', array('myfunctionclass', 'execute')); - $this->assertEquals('hello world 2', $this->smarty->fetch('eval:{testfunction value=2}')); + $this->assertEquals('hello world 2', $this->smarty->fetch('string:{testfunction value=2}')); + } + /** + * test register_function wrapper method for function plugin by class + */ + public function testRegisterFunctionClassWrapper() + { + $this->smarty->register_function('testfunction', array('myfunctionclass', 'execute')); + $this->assertEquals('hello world 12', $this->smarty->fetch('string:{testfunction value=12}')); + } + /** + * test register_function SmartyBC method for function plugin by class + */ + public function testRegisterFunctionClassSmartyBC() + { + $this->smartyBC->register_function('testfunction', array('myfunctionclass', 'execute')); + $this->assertEquals('hello world 22', $this->smartyBC->fetch('string:{testfunction value=22}')); } + /** - * test register->templateFunction method for object + * test registerPlugin method for function plugin by object */ public function testRegisterFunctionObject() { $myfunction_object = new myfunctionclass; $this->smarty->registerPlugin(Smarty::PLUGIN_FUNCTION, 'testfunction', array($myfunction_object, 'execute')); - $this->assertEquals('hello world 3', $this->smarty->fetch('eval:{testfunction value=3}')); + $this->assertEquals('hello world 3', $this->smarty->fetch('string:{testfunction value=3}')); + } + /** + * test register_function wrapper method for function plugin by object + */ + public function testRegisterFunctionObjectWrapper() + { + $myfunction_object = new myfunctionclass; + $this->smarty->register_function('testfunction', array($myfunction_object, 'execute')); + $this->assertEquals('hello world 13', $this->smarty->fetch('string:{testfunction value=13}')); + } + /** + * test register_function SmartyBC method for function plugin by object + */ + public function testRegisterFunctionObjectSmartyBC() + { + $myfunction_object = new myfunctionclass; + $this->smartyBC->register_function('testfunction', array($myfunction_object, 'execute')); + $this->assertEquals('hello world 23', $this->smartyBC->fetch('string:{testfunction value=23}')); } + /** + * @runInSeparateProcess + * @preserveGlobalState disabled + * + */ public function testRegisterFunctionCaching1() { - $this->smarty->caching = 1; - $this->smarty->cache_lifetime = 1000; - $this->smarty->setForceCompile(true); + $this->smarty->setCaching(1);; + $this->smarty->setCacheLifetime(1000);; $this->smarty->assign('x', 0); $this->smarty->assign('y', 10); $this->smarty->registerPlugin(Smarty::PLUGIN_FUNCTION, 'testfunction', 'myfunction'); @@ -83,8 +134,8 @@ class RegisterFunctionTest extends PHPUnit_Smarty */ public function testRegisterFunctionCaching2() { - $this->smarty->caching = 1; - $this->smarty->cache_lifetime = 1000; + $this->smarty->setCaching(1);; + $this->smarty->setCacheLifetime(1000);; $this->smarty->assign('x', 1); $this->smarty->assign('y', 20); $this->smarty->registerPlugin(Smarty::PLUGIN_FUNCTION, 'testfunction', 'myfunction'); @@ -98,14 +149,29 @@ class RegisterFunctionTest extends PHPUnit_Smarty */ public function testRegisterFunctionCaching3() { - $this->smarty->caching = 1; - $this->smarty->cache_lifetime = 1000; - $this->smarty->setForceCompile(true); + $this->smarty->setCaching(1);; + $this->smarty->setCacheLifetime(1000);; + $this->smarty->setCompileId(1); $this->smarty->assign('x', 2); $this->smarty->assign('y', 30); $this->smarty->registerPlugin(Smarty::PLUGIN_FUNCTION, 'testfunction', 'myfunction', false); $this->assertEquals('hello world 2 30', $this->smarty->fetch('test_register_function.tpl')); } + /** + * @runInSeparateProcess + * @preserveGlobalState disabled + * + */ + public function testRegisterFunctionCaching3BC() + { + $this->smartyBC->setCaching(1);; + $this->smartyBC->setCacheLifetime(1000);; + $this->smartyBC->setCompileId(2); + $this->smartyBC->assign('x', 12); + $this->smartyBC->assign('y', 130); + $this->smartyBC->register_function('testfunction', 'myfunction', false); + $this->assertEquals('hello world 12 130', $this->smartyBC->fetch('test_register_function.tpl')); + } /** * @runInSeparateProcess @@ -114,13 +180,29 @@ class RegisterFunctionTest extends PHPUnit_Smarty */ public function testRegisterFunctionCaching4() { - $this->smarty->caching = 1; - $this->smarty->cache_lifetime = 1000; + $this->smarty->setCaching(1);; + $this->smarty->setCacheLifetime(1000);; + $this->smarty->setCompileId(1); $this->smarty->assign('x', 3); $this->smarty->assign('y', 40); $this->smarty->registerPlugin(Smarty::PLUGIN_FUNCTION, 'testfunction', 'myfunction', false); $this->assertEquals('hello world 3 30', $this->smarty->fetch('test_register_function.tpl')); } + /** + * @runInSeparateProcess + * @preserveGlobalState disabled + * + */ + public function testRegisterFunctionCaching4BC() + { + $this->smartyBC->setCaching(1);; + $this->smartyBC->setCacheLifetime(1000);; + $this->smartyBC->setCompileId(2); + $this->smartyBC->assign('x', 13); + $this->smartyBC->assign('y', 140); + $this->smartyBC->register_function('testfunction', 'myfunction', false); + $this->assertEquals('hello world 13 130', $this->smartyBC->fetch('test_register_function.tpl')); + } /** * test unregister->templateFunction method @@ -137,11 +219,18 @@ class RegisterFunctionTest extends PHPUnit_Smarty */ public function testUnregisterFunctionWrapper() { - $this->smarty->registerPlugin(Smarty::PLUGIN_FUNCTION, 'testfunction', 'myfunction'); + $this->smarty->register_function('testfunction', 'myfunction'); $this->smarty->unregister_function('testfunction'); $this->assertFalse(isset($this->smarty->registered_plugins[Smarty::PLUGIN_FUNCTION]['testfunction'])); } + public function testUnregisterFunctionSmartyBC() + { + $this->smartyBC->register_function('testfunction', 'myfunction'); + $this->smartyBC->unregister_function('testfunction'); + $this->assertFalse(isset($this->smartyBC->registered_plugins[Smarty::PLUGIN_FUNCTION]['testfunction'])); + } + /** * test unregister->templateFunction method not registered */