mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-04 18:34:27 +02:00
Smarty2 wrapper tests
This commit is contained in:
@@ -16,6 +16,8 @@
|
|||||||
*/
|
*/
|
||||||
class RegisterFunctionTest extends PHPUnit_Smarty
|
class RegisterFunctionTest extends PHPUnit_Smarty
|
||||||
{
|
{
|
||||||
|
public $loadSmartyBC = true;
|
||||||
|
|
||||||
public function setUp()
|
public function setUp()
|
||||||
{
|
{
|
||||||
$this->setUpSmarty(__DIR__);
|
$this->setUpSmarty(__DIR__);
|
||||||
@@ -27,13 +29,13 @@ class RegisterFunctionTest extends PHPUnit_Smarty
|
|||||||
$this->cleanDirs();
|
$this->cleanDirs();
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* test register->templateFunction method for function
|
* test registerPlugin method for function
|
||||||
*/
|
*/
|
||||||
public function testRegisterFunction()
|
public function testRegisterFunction()
|
||||||
{
|
{
|
||||||
$this->smarty->registerPlugin(Smarty::PLUGIN_FUNCTION, 'testfunction', 'myfunction');
|
$this->smarty->registerPlugin(Smarty::PLUGIN_FUNCTION, 'testfunction', 'myfunction');
|
||||||
$this->assertEquals('myfunction', $this->smarty->registered_plugins[Smarty::PLUGIN_FUNCTION]['testfunction'][0]);
|
$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->smarty->register_function('testfunction', 'myfunction');
|
||||||
$this->assertEquals('myfunction', $this->smarty->registered_plugins[Smarty::PLUGIN_FUNCTION]['testfunction'][0]);
|
$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()
|
public function testRegisterFunctionClass()
|
||||||
{
|
{
|
||||||
$this->smarty->registerPlugin(Smarty::PLUGIN_FUNCTION, 'testfunction', array('myfunctionclass', 'execute'));
|
$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()
|
public function testRegisterFunctionObject()
|
||||||
{
|
{
|
||||||
$myfunction_object = new myfunctionclass;
|
$myfunction_object = new myfunctionclass;
|
||||||
$this->smarty->registerPlugin(Smarty::PLUGIN_FUNCTION, 'testfunction', array($myfunction_object, 'execute'));
|
$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()
|
public function testRegisterFunctionCaching1()
|
||||||
{
|
{
|
||||||
$this->smarty->caching = 1;
|
$this->smarty->setCaching(1);;
|
||||||
$this->smarty->cache_lifetime = 1000;
|
$this->smarty->setCacheLifetime(1000);;
|
||||||
$this->smarty->setForceCompile(true);
|
|
||||||
$this->smarty->assign('x', 0);
|
$this->smarty->assign('x', 0);
|
||||||
$this->smarty->assign('y', 10);
|
$this->smarty->assign('y', 10);
|
||||||
$this->smarty->registerPlugin(Smarty::PLUGIN_FUNCTION, 'testfunction', 'myfunction');
|
$this->smarty->registerPlugin(Smarty::PLUGIN_FUNCTION, 'testfunction', 'myfunction');
|
||||||
@@ -83,8 +134,8 @@ class RegisterFunctionTest extends PHPUnit_Smarty
|
|||||||
*/
|
*/
|
||||||
public function testRegisterFunctionCaching2()
|
public function testRegisterFunctionCaching2()
|
||||||
{
|
{
|
||||||
$this->smarty->caching = 1;
|
$this->smarty->setCaching(1);;
|
||||||
$this->smarty->cache_lifetime = 1000;
|
$this->smarty->setCacheLifetime(1000);;
|
||||||
$this->smarty->assign('x', 1);
|
$this->smarty->assign('x', 1);
|
||||||
$this->smarty->assign('y', 20);
|
$this->smarty->assign('y', 20);
|
||||||
$this->smarty->registerPlugin(Smarty::PLUGIN_FUNCTION, 'testfunction', 'myfunction');
|
$this->smarty->registerPlugin(Smarty::PLUGIN_FUNCTION, 'testfunction', 'myfunction');
|
||||||
@@ -98,14 +149,29 @@ class RegisterFunctionTest extends PHPUnit_Smarty
|
|||||||
*/
|
*/
|
||||||
public function testRegisterFunctionCaching3()
|
public function testRegisterFunctionCaching3()
|
||||||
{
|
{
|
||||||
$this->smarty->caching = 1;
|
$this->smarty->setCaching(1);;
|
||||||
$this->smarty->cache_lifetime = 1000;
|
$this->smarty->setCacheLifetime(1000);;
|
||||||
$this->smarty->setForceCompile(true);
|
$this->smarty->setCompileId(1);
|
||||||
$this->smarty->assign('x', 2);
|
$this->smarty->assign('x', 2);
|
||||||
$this->smarty->assign('y', 30);
|
$this->smarty->assign('y', 30);
|
||||||
$this->smarty->registerPlugin(Smarty::PLUGIN_FUNCTION, 'testfunction', 'myfunction', false);
|
$this->smarty->registerPlugin(Smarty::PLUGIN_FUNCTION, 'testfunction', 'myfunction', false);
|
||||||
$this->assertEquals('hello world 2 30', $this->smarty->fetch('test_register_function.tpl'));
|
$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
|
* @runInSeparateProcess
|
||||||
@@ -114,13 +180,29 @@ class RegisterFunctionTest extends PHPUnit_Smarty
|
|||||||
*/
|
*/
|
||||||
public function testRegisterFunctionCaching4()
|
public function testRegisterFunctionCaching4()
|
||||||
{
|
{
|
||||||
$this->smarty->caching = 1;
|
$this->smarty->setCaching(1);;
|
||||||
$this->smarty->cache_lifetime = 1000;
|
$this->smarty->setCacheLifetime(1000);;
|
||||||
|
$this->smarty->setCompileId(1);
|
||||||
$this->smarty->assign('x', 3);
|
$this->smarty->assign('x', 3);
|
||||||
$this->smarty->assign('y', 40);
|
$this->smarty->assign('y', 40);
|
||||||
$this->smarty->registerPlugin(Smarty::PLUGIN_FUNCTION, 'testfunction', 'myfunction', false);
|
$this->smarty->registerPlugin(Smarty::PLUGIN_FUNCTION, 'testfunction', 'myfunction', false);
|
||||||
$this->assertEquals('hello world 3 30', $this->smarty->fetch('test_register_function.tpl'));
|
$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
|
* test unregister->templateFunction method
|
||||||
@@ -137,11 +219,18 @@ class RegisterFunctionTest extends PHPUnit_Smarty
|
|||||||
*/
|
*/
|
||||||
public function testUnregisterFunctionWrapper()
|
public function testUnregisterFunctionWrapper()
|
||||||
{
|
{
|
||||||
$this->smarty->registerPlugin(Smarty::PLUGIN_FUNCTION, 'testfunction', 'myfunction');
|
$this->smarty->register_function('testfunction', 'myfunction');
|
||||||
$this->smarty->unregister_function('testfunction');
|
$this->smarty->unregister_function('testfunction');
|
||||||
$this->assertFalse(isset($this->smarty->registered_plugins[Smarty::PLUGIN_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
|
* test unregister->templateFunction method not registered
|
||||||
*/
|
*/
|
||||||
|
Reference in New Issue
Block a user