mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-05 02:44:27 +02:00
update compiler plugin test
This commit is contained in:
@@ -28,11 +28,30 @@ class CompileCompilerPluginTest extends PHPUnit_Smarty
|
|||||||
/**
|
/**
|
||||||
* test compiler plugin tag in template file
|
* test compiler plugin tag in template file
|
||||||
*/
|
*/
|
||||||
public function testCompilerPlugin()
|
public function testCompilerPluginFunction()
|
||||||
{
|
{
|
||||||
$this->smarty->registerPlugin(Smarty::PLUGIN_COMPILER, 'compilerplugin', 'mycompilerplugin');
|
$this->smarty->registerPlugin(Smarty::PLUGIN_COMPILER, 'compilerplugin', 'mycompilerplugin');
|
||||||
$tpl = $this->smarty->createTemplate('compilerplugintest.tpl');
|
$this->smarty->compile_id = 'function';
|
||||||
$this->assertEquals("Hello World", $this->smarty->fetch($tpl));
|
$this->assertEquals("Hello World", $this->smarty->fetch('compilerplugintest.tpl'));
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* test compiler plugin tag in template file
|
||||||
|
*/
|
||||||
|
public function testCompilerPluginClassStatic()
|
||||||
|
{
|
||||||
|
$this->smarty->registerPlugin(Smarty::PLUGIN_COMPILER, 'compilerplugin', array('CompilerPluginClass', 'statCompile'));
|
||||||
|
$this->smarty->compile_id = 'static';
|
||||||
|
$this->assertEquals("Static World", $this->smarty->fetch('compilerplugintest.tpl'));
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* test compiler plugin tag in template file
|
||||||
|
*/
|
||||||
|
public function testCompilerPluginClassObject()
|
||||||
|
{
|
||||||
|
$plugin = new CompilerPluginClass;
|
||||||
|
$this->smarty->registerPlugin(Smarty::PLUGIN_COMPILER, 'compilerplugin', array($plugin, 'compile'));
|
||||||
|
$this->smarty->compile_id = 'object';
|
||||||
|
$this->assertEquals("Public World", $this->smarty->fetch('compilerplugintest.tpl'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -40,3 +59,13 @@ function mycompilerplugin($params, $compiler)
|
|||||||
{
|
{
|
||||||
return '<?php echo \'Hello World\';?>';
|
return '<?php echo \'Hello World\';?>';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class CompilerPluginClass
|
||||||
|
{
|
||||||
|
static function statCompile ($params, $compiler) {
|
||||||
|
return '<?php echo \'Static World\';?>';
|
||||||
|
}
|
||||||
|
public function compile ($params, $compiler) {
|
||||||
|
return '<?php echo \'Public World\';?>';
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user