mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-05 10:54:27 +02:00
Add test for registering compiler plugin with positional params. Fixes #164
This commit is contained in:
@@ -6,6 +6,7 @@
|
|||||||
* @author Uwe Tews
|
* @author Uwe Tews
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
use Smarty\Compiler\Template;
|
||||||
use Smarty\Smarty;
|
use Smarty\Smarty;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -110,6 +111,22 @@ class RegisterBlockTest extends PHPUnit_Smarty
|
|||||||
$this->assertEquals('1 10 100', $this->smarty->fetch('test_register_block.tpl'));
|
$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;
|
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
|
class myblockclass
|
||||||
{
|
{
|
||||||
static function static_method($params, $content, &$smarty_tpl, &$repeat)
|
static function static_method($params, $content, &$smarty_tpl, &$repeat)
|
||||||
|
Reference in New Issue
Block a user