mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-04 18:34:27 +02:00
update block plugin tests
This commit is contained in:
@@ -10,7 +10,7 @@
|
|||||||
* class for block plugin tests
|
* class for block plugin tests
|
||||||
*
|
*
|
||||||
* @runTestsInSeparateProcess
|
* @runTestsInSeparateProcess
|
||||||
* @preserveGlobalState disabled
|
* @preserveGlobalState disabled
|
||||||
* @backupStaticAttributes enabled
|
* @backupStaticAttributes enabled
|
||||||
*/
|
*/
|
||||||
class CompileBlockPluginTest extends PHPUnit_Smarty
|
class CompileBlockPluginTest extends PHPUnit_Smarty
|
||||||
@@ -22,18 +22,18 @@ class CompileBlockPluginTest extends PHPUnit_Smarty
|
|||||||
$this->smarty->disableSecurity();
|
$this->smarty->disableSecurity();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function testInit()
|
public function testInit()
|
||||||
{
|
{
|
||||||
$this->cleanDirs();
|
$this->cleanDirs();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* test block plugin tag
|
* test block plugin tag
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function testBlockPluginNoAssign()
|
public function testBlockPluginNoAssign()
|
||||||
{
|
{
|
||||||
$this->assertEquals("hello world", $this->smarty->fetch('no_assign.tpl'));
|
$this->assertEquals("hello world", $this->smarty->fetch('no_assign.tpl'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -45,6 +45,18 @@ class CompileBlockPluginTest extends PHPUnit_Smarty
|
|||||||
$this->assertEquals("hello world", $this->smarty->fetch('assign.tpl'));
|
$this->assertEquals("hello world", $this->smarty->fetch('assign.tpl'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test unknown block plugin tag
|
||||||
|
*
|
||||||
|
* @expectedException SmartyCompilerException
|
||||||
|
* @expectedExceptionMessage unknown tag "bar"
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function testBlockPluginUnknown()
|
||||||
|
{
|
||||||
|
$this->assertEquals("hello world", $this->smarty->fetch('unknown.tpl'));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* test block plugin function definition in script
|
* test block plugin function definition in script
|
||||||
*
|
*
|
||||||
@@ -58,6 +70,20 @@ class CompileBlockPluginTest extends PHPUnit_Smarty
|
|||||||
$this->assertEquals('block test', $this->smarty->fetch('registered.tpl'));
|
$this->assertEquals('block test', $this->smarty->fetch('registered.tpl'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test block plugin function definition in script
|
||||||
|
*
|
||||||
|
* @runInSeparateProcess
|
||||||
|
* @preserveGlobalState disabled
|
||||||
|
* @expectedException SmartyException
|
||||||
|
* @expectedExceptionMessage block tag 'blockplugintest' not callable
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function testBlockPluginRegisteredFunction2()
|
||||||
|
{
|
||||||
|
$this->assertEquals('block test', $this->smarty->fetch('registered.tpl'));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* test block plugin static method
|
* test block plugin static method
|
||||||
*
|
*
|
||||||
@@ -71,6 +97,20 @@ class CompileBlockPluginTest extends PHPUnit_Smarty
|
|||||||
$this->assertEquals('static block test', $this->smarty->fetch('registered_static.tpl'));
|
$this->assertEquals('static block test', $this->smarty->fetch('registered_static.tpl'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test block plugin static method failure
|
||||||
|
*
|
||||||
|
* @runInSeparateProcess
|
||||||
|
* @preserveGlobalState disabled
|
||||||
|
* @expectedException SmartyException
|
||||||
|
* @expectedExceptionMessage block tag 'blockpluginstatic' not callable
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function testBlockPluginRegisteredStatic2()
|
||||||
|
{
|
||||||
|
$this->assertEquals('static block test', $this->smarty->fetch('registered_static.tpl'));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* test block plugin object method
|
* test block plugin object method
|
||||||
*
|
*
|
||||||
@@ -84,6 +124,21 @@ class CompileBlockPluginTest extends PHPUnit_Smarty
|
|||||||
$this->smarty->registerPlugin(Smarty::PLUGIN_BLOCK, 'blockpluginmethod', array($object, 'methodfunc'));
|
$this->smarty->registerPlugin(Smarty::PLUGIN_BLOCK, 'blockpluginmethod', array($object, 'methodfunc'));
|
||||||
$this->assertEquals('method block test', $this->smarty->fetch('registered_method.tpl'));
|
$this->assertEquals('method block test', $this->smarty->fetch('registered_method.tpl'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test block plugin object method failure
|
||||||
|
*
|
||||||
|
* @runInSeparateProcess
|
||||||
|
* @preserveGlobalState disabled
|
||||||
|
* @expectedException SmartyException
|
||||||
|
* @expectedExceptionMessage block tag 'blockpluginmethod' not callable
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function testBlockPluginRegisteredMethod2()
|
||||||
|
{
|
||||||
|
$this->assertEquals('method block test', $this->smarty->fetch('registered_method.tpl'));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* test block plugin registered object
|
* test block plugin registered object
|
||||||
*
|
*
|
||||||
@@ -98,8 +153,23 @@ class CompileBlockPluginTest extends PHPUnit_Smarty
|
|||||||
$this->assertEquals('object block test', $this->smarty->fetch('registered_object.tpl'));
|
$this->assertEquals('object block test', $this->smarty->fetch('registered_object.tpl'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test block plugin registered object failure
|
||||||
|
*
|
||||||
|
* @runInSeparateProcess
|
||||||
|
* @preserveGlobalState disabled
|
||||||
|
* @expectedException SmartyException
|
||||||
|
* @expectedExceptionMessage block tag 'myobject' not callable
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function testBlockPluginRegisteredObject2()
|
||||||
|
{
|
||||||
|
$this->assertEquals('object block test', $this->smarty->fetch('registered_object.tpl'));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* test block plugin repeat function
|
* test block plugin repeat function
|
||||||
|
*
|
||||||
* @runInSeparateProcess
|
* @runInSeparateProcess
|
||||||
* @preserveGlobalState disabled
|
* @preserveGlobalState disabled
|
||||||
*
|
*
|
||||||
@@ -111,6 +181,7 @@ class CompileBlockPluginTest extends PHPUnit_Smarty
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* test block plugin repeat function with modifier
|
* test block plugin repeat function with modifier
|
||||||
|
*
|
||||||
* @runInSeparateProcess
|
* @runInSeparateProcess
|
||||||
* @preserveGlobalState disabled
|
* @preserveGlobalState disabled
|
||||||
*
|
*
|
||||||
@@ -122,6 +193,7 @@ class CompileBlockPluginTest extends PHPUnit_Smarty
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* test block plugin repeat function with modifier list
|
* test block plugin repeat function with modifier list
|
||||||
|
*
|
||||||
* @runInSeparateProcess
|
* @runInSeparateProcess
|
||||||
* @preserveGlobalState disabled
|
* @preserveGlobalState disabled
|
||||||
*
|
*
|
||||||
@@ -130,8 +202,10 @@ class CompileBlockPluginTest extends PHPUnit_Smarty
|
|||||||
{
|
{
|
||||||
$this->assertEquals('11111', $this->smarty->fetch('repeat_modifier_2.tpl'));
|
$this->assertEquals('11111', $this->smarty->fetch('repeat_modifier_2.tpl'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* test block plugin with no output
|
* test block plugin with no output
|
||||||
|
*
|
||||||
* @runInSeparateProcess
|
* @runInSeparateProcess
|
||||||
* @preserveGlobalState disabled
|
* @preserveGlobalState disabled
|
||||||
*
|
*
|
||||||
@@ -140,8 +214,10 @@ class CompileBlockPluginTest extends PHPUnit_Smarty
|
|||||||
{
|
{
|
||||||
$this->assertEquals('default', $this->smarty->fetch('nooutput.tpl'));
|
$this->assertEquals('default', $this->smarty->fetch('nooutput.tpl'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* test nested block plugin
|
* test nested block plugin
|
||||||
|
*
|
||||||
* @runInSeparateProcess
|
* @runInSeparateProcess
|
||||||
* @preserveGlobalState disabled
|
* @preserveGlobalState disabled
|
||||||
*
|
*
|
||||||
@@ -150,8 +226,10 @@ class CompileBlockPluginTest extends PHPUnit_Smarty
|
|||||||
{
|
{
|
||||||
$this->assertEquals('hello world12345', $this->smarty->fetch('nested.tpl'));
|
$this->assertEquals('hello world12345', $this->smarty->fetch('nested.tpl'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* test default block plugin
|
* test default block plugin
|
||||||
|
*
|
||||||
* @runInSeparateProcess
|
* @runInSeparateProcess
|
||||||
* @preserveGlobalState disabled
|
* @preserveGlobalState disabled
|
||||||
*
|
*
|
||||||
@@ -161,8 +239,10 @@ class CompileBlockPluginTest extends PHPUnit_Smarty
|
|||||||
$this->smarty->registerDefaultPluginHandler('my_block_plugin_handler');
|
$this->smarty->registerDefaultPluginHandler('my_block_plugin_handler');
|
||||||
$this->assertEquals('scriptblock hello world', $this->smarty->fetch('default1.tpl'));
|
$this->assertEquals('scriptblock hello world', $this->smarty->fetch('default1.tpl'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* test default block plugin
|
* test default block plugin
|
||||||
|
*
|
||||||
* @runInSeparateProcess
|
* @runInSeparateProcess
|
||||||
* @preserveGlobalState disabled
|
* @preserveGlobalState disabled
|
||||||
*
|
*
|
||||||
@@ -192,6 +272,7 @@ class myblockclass1
|
|||||||
return $output;
|
return $output;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function methodfunc($params, $content, &$smarty_tpl, &$repeat)
|
public function methodfunc($params, $content, &$smarty_tpl, &$repeat)
|
||||||
{
|
{
|
||||||
if (!$repeat) {
|
if (!$repeat) {
|
||||||
@@ -199,6 +280,7 @@ class myblockclass1
|
|||||||
return $output;
|
return $output;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function objectfunc($params, $content, &$smarty_tpl, &$repeat)
|
public function objectfunc($params, $content, &$smarty_tpl, &$repeat)
|
||||||
{
|
{
|
||||||
if (!$repeat) {
|
if (!$repeat) {
|
||||||
@@ -207,6 +289,7 @@ class myblockclass1
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function my_block_plugin_handler($tag, $type, $template, &$callback, &$script, &$cachable)
|
function my_block_plugin_handler($tag, $type, $template, &$callback, &$script, &$cachable)
|
||||||
{
|
{
|
||||||
switch ($type) {
|
switch ($type) {
|
||||||
@@ -222,7 +305,7 @@ function my_block_plugin_handler($tag, $type, $template, &$callback, &$script, &
|
|||||||
$callback = 'default_block_tag';
|
$callback = 'default_block_tag';
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1 @@
|
|||||||
|
{bar}hello world{/bar}
|
Reference in New Issue
Block a user