Add test for registering compiler plugin with positional params. Fixes #164

This commit is contained in:
Simon Wisselink
2023-01-31 10:41:09 +01:00
parent 0962a34670
commit b4019b6023

View File

@@ -6,6 +6,7 @@
* @author Uwe Tews
*/
use Smarty\Compiler\Template;
use Smarty\Smarty;
/**
@@ -110,6 +111,22 @@ class RegisterBlockTest extends PHPUnit_Smarty
$this->assertEquals('1 10 100', $this->smarty->fetch('test_register_block.tpl'));
}
/**
* test register block with handler that supports positional params
*/
public function testRegisterBlockWithPositionalParams()
{
$this->cleanDirs();
$this->smarty->registerPlugin(Smarty::PLUGIN_COMPILER, 'testblock', blockparamsCompiler::class);
$this->smarty->registerPlugin(Smarty::PLUGIN_COMPILER, 'testblockclose', blockparamsCompiler::class);
$result = $this->smarty->fetch('string:{testblock "foo" "bar"} block
contents
{/testblock}');
$this->assertStringContainsString('first', $result);
$this->assertStringContainsString('second', $result);
}
/**
*
*
@@ -283,6 +300,28 @@ function myblockcache($params, $content, &$smarty_tpl, &$repeat)
return $content;
}
class blockparamsCompiler extends \Smarty\Compile\Base {
protected $shorttag_order = ["first", "second"];
protected $optional_attributes = ["first", "second"];
public function compile($args, Template $compiler, $parameter = [], $tag = null, $function = null) {
$_attr = $this->getAttributes($compiler, $args);
$output = '';
if (isset($_attr['first'])) {
$output .= 'first';
}
if (isset($_attr['second'])) {
$output .= 'second';
}
return $output;
}
}
class myblockclass
{
static function static_method($params, $content, &$smarty_tpl, &$repeat)