mirror of
https://github.com/smarty-php/smarty.git
synced 2025-10-08 10:20:16 +02:00
* Removed unneeded files and replace dummy.txt with .gitignore files * Synced unit tests with master codebase, noted TODO's, fixed phpunit scripts and travis config * fix php7.4 deprecation and remove php7.4 from travis allow_failures since php7.4 is current stable Co-authored-by: Uwe Tews <uwe.tews@googlemail.com> Co-authored-by: Uwe Tews <uwe.tews@gmail.com> Co-authored-by: AnrDaemon <anrdaemon@yandex.ru>
71 lines
2.0 KiB
PHP
71 lines
2.0 KiB
PHP
<?php
|
|
/**
|
|
* Smarty PHPunit tests compilation of compiler plugins
|
|
*
|
|
* @package PHPunit
|
|
* @author Uwe Tews
|
|
*/
|
|
|
|
/**
|
|
* class for compiler plugin tests
|
|
*
|
|
* @runTestsInSeparateProcess
|
|
* @preserveGlobalState disabled
|
|
* @backupStaticAttributes enabled
|
|
*/
|
|
class CompileCompilerPluginTest extends PHPUnit_Smarty
|
|
{
|
|
public function setUp()
|
|
{
|
|
$this->setUpSmarty(dirname(__FILE__));
|
|
}
|
|
|
|
public function testInit()
|
|
{
|
|
$this->cleanDirs();
|
|
}
|
|
|
|
/**
|
|
* test compiler plugin tag in template file
|
|
*/
|
|
public function testCompilerPluginFunction()
|
|
{
|
|
$this->smarty->registerPlugin(Smarty::PLUGIN_COMPILER, 'compilerplugin', 'mycompilerplugin');
|
|
$this->smarty->compile_id = 'function';
|
|
$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'));
|
|
}
|
|
}
|
|
|
|
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\';?>';
|
|
}
|
|
} |