2020-04-13 15:30:52 +02:00
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* Smarty PHPunit tests compilation of compiler plugins
|
|
|
|
|
*
|
2023-08-08 00:04:14 +02:00
|
|
|
|
2020-04-13 15:30:52 +02:00
|
|
|
* @author Uwe Tews
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* class for compiler plugin tests
|
|
|
|
|
*
|
2023-08-08 00:04:14 +02:00
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
*
|
2020-04-13 15:30:52 +02:00
|
|
|
*/
|
|
|
|
|
class CompileCompilerPluginTest extends PHPUnit_Smarty
|
|
|
|
|
{
|
2021-10-13 12:15:17 +02:00
|
|
|
public function setUp(): void
|
2020-04-13 15:30:52 +02:00
|
|
|
{
|
2022-09-27 13:03:34 +03:00
|
|
|
$this->setUpSmarty(__DIR__);
|
2020-04-13 15:30:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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');
|
2020-04-13 15:30:52 +02:00
|
|
|
$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');
|
2020-04-13 15:30:52 +02:00
|
|
|
$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');
|
2020-04-13 15:30:52 +02:00
|
|
|
$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\';?>';
|
|
|
|
|
}
|
|
|
|
|
}
|