mirror of
https://github.com/smarty-php/smarty.git
synced 2026-07-11 02:40:49 +02:00
7408c18cdc
Removed $smarty->_current_file and $smarty->allow_ambiguous_resources properties, both unused. Removed public Source::filepath property.
Cached an Compiled files (and Exceptions) no longer rely on the filepath being set. Removed explicit tests for cached and compiled filenames. The exact implementation is not important. Added tests for compile_check property, fixing a file_exists check that would always be done on source template files, even when compile_check was true. Remove code duplication between Source en Config classes. Added a local $_smarty_current_dir to the generated code files for backwards compatability for {$smarty.current_dir}.
71 lines
1.9 KiB
PHP
71 lines
1.9 KiB
PHP
<?php
|
|
/**
|
|
* Smarty PHPunit tests compilation of compiler plugins
|
|
*
|
|
|
|
* @author Uwe Tews
|
|
*/
|
|
|
|
/**
|
|
* class for compiler plugin tests
|
|
*
|
|
*
|
|
*
|
|
*
|
|
*/
|
|
class CompileCompilerPluginTest extends PHPUnit_Smarty
|
|
{
|
|
public function setUp(): void
|
|
{
|
|
$this->setUpSmarty(__DIR__);
|
|
}
|
|
|
|
public function testInit()
|
|
{
|
|
$this->cleanDirs();
|
|
}
|
|
|
|
/**
|
|
* test compiler plugin tag in template file
|
|
*/
|
|
public function testCompilerPluginFunction()
|
|
{
|
|
$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()
|
|
{
|
|
$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;
|
|
$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\';?>';
|
|
}
|
|
} |