Files

71 lines
1.9 KiB
PHP
Raw Permalink Normal View History

<?php
/**
* Smarty PHPunit tests compilation of compiler plugins
*
2023-08-08 00:04:14 +02:00
* @author Uwe Tews
*/
/**
* class for compiler plugin tests
*
2023-08-08 00:04:14 +02:00
*
*
*
*/
class CompileCompilerPluginTest extends PHPUnit_Smarty
{
2021-10-13 12:15:17 +02:00
public function setUp(): void
{
$this->setUpSmarty(__DIR__);
}
public function testInit()
{
$this->cleanDirs();
}
/**
* test compiler plugin tag in template file
*/
public function testCompilerPluginFunction()
{
2023-08-08 00:04:14 +02:00
$this->smarty->registerPlugin(\Smarty\Smarty::PLUGIN_COMPILER, 'compilerplugin', 'mycompilerplugin');
$this->smarty->setCompileId('function');
$this->assertEquals("Hello World", $this->smarty->fetch('compilerplugintest.tpl'));
}
/**
* test compiler plugin tag in template file
*/
public function testCompilerPluginClassStatic()
{
2023-08-08 00:04:14 +02:00
$this->smarty->registerPlugin(\Smarty\Smarty::PLUGIN_COMPILER, 'compilerplugin', array('CompilerPluginClass', 'statCompile'));
$this->smarty->setCompileId('static');
$this->assertEquals("Static World", $this->smarty->fetch('compilerplugintest.tpl'));
}
/**
* test compiler plugin tag in template file
*/
public function testCompilerPluginClassObject()
{
$plugin = new CompilerPluginClass;
2023-08-08 00:04:14 +02:00
$this->smarty->registerPlugin(\Smarty\Smarty::PLUGIN_COMPILER, 'compilerplugin', array($plugin, 'compile'));
$this->smarty->setCompileId('object');
$this->assertEquals("Public World", $this->smarty->fetch('compilerplugintest.tpl'));
}
}
function mycompilerplugin($params, $compiler)
{
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\';?>';
}
}