mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-03 18:04:26 +02:00
Removed BC code. WIP
This commit is contained in:
14
CHANGELOG.md
14
CHANGELOG.md
@@ -6,13 +6,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
## [3.1.38] - 2021-01-08
|
||||
|
||||
### Fixed
|
||||
- Smarty::SMARTY_VERSION wasn't updated https://github.com/smarty-php/smarty/issues/628
|
||||
|
||||
## [3.1.37] - 2021-01-07
|
||||
|
||||
### Changed
|
||||
- Switch CI from Travis to Github CI
|
||||
- Updated unit tests to avoid skipped and risky test warnings
|
||||
@@ -20,8 +13,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
### Removed
|
||||
- Dropped support for PHP7.0 and below, so Smarty now requires PHP >=7.1
|
||||
- Dropped support for php asp tags in templates (removed from php since php7.0)
|
||||
- Dropped deprecated API calls that where only accessible through SmartyBC
|
||||
- Dropped support for {php} and {include_php} tags
|
||||
- Removed all PHP_VERSION_ID and compare_version checks and conditional code blocks that are now no longer required
|
||||
|
||||
## [3.1.38] - 2021-01-08
|
||||
|
||||
### Fixed
|
||||
- Smarty::SMARTY_VERSION wasn't updated https://github.com/smarty-php/smarty/issues/628
|
||||
|
||||
## [3.1.37] - 2021-01-07
|
||||
|
||||
### Changed
|
||||
|
@@ -289,8 +289,6 @@ class Smarty_Internal_Templatelexer
|
||||
textdoublequoted = ~([^"\\]*?)((?:\\.[^"\\]*?)*?)(?=((SMARTYldel)SMARTYal|\$|`\$|"SMARTYliteral))~
|
||||
namespace = ~([0-9]*[a-zA-Z_]\w*)?(\\[0-9]*[a-zA-Z_]\w*)+~
|
||||
emptyjava = ~[{][}]~
|
||||
phptag = ~(SMARTYldel)SMARTYalphp([ ].*?)?SMARTYrdel|(SMARTYldel)SMARTYal[/]phpSMARTYrdel~
|
||||
phpstart = ~[<][?]((php\s+|=)|\s+)|[<][%]|[<][?]xml\s+|[<]script\s+language\s*=\s*["']?\s*php\s*["']?\s*[>]|[?][>]|[%][>]~
|
||||
slash = ~[/]~
|
||||
ldel = ~(SMARTYldel)SMARTYal~
|
||||
rdel = ~\s*SMARTYrdel~
|
||||
@@ -362,9 +360,6 @@ class Smarty_Internal_Templatelexer
|
||||
$this->value = substr($this->data,$this->counter,$to-$this->counter);
|
||||
return false;
|
||||
}
|
||||
phptag {
|
||||
$this->compiler->getTagCompiler('private_php')->parsePhp($this);
|
||||
}
|
||||
userliteral {
|
||||
$this->token = Smarty_Internal_Templateparser::TP_TEXT;
|
||||
}
|
||||
@@ -380,12 +375,9 @@ class Smarty_Internal_Templatelexer
|
||||
$this->yypushstate(self::TAG);
|
||||
return true;
|
||||
}
|
||||
phpstart {
|
||||
$this->compiler->getTagCompiler('private_php')->parsePhp($this);
|
||||
}
|
||||
char {
|
||||
if (!isset($this->yy_global_text)) {
|
||||
$this->yy_global_text = $this->replace('/(SMARTYldel)SMARTYal|[<][?]((php\s+|=)|\s+)|[<][%]|[<][?]xml\s+|[<]script\s+language\s*=\s*["\']?\s*php\s*["\']?\s*[>]|[?][>]|[%][>]SMARTYliteral/isS');
|
||||
$this->yy_global_text = $this->replace('/(SMARTYldel)SMARTYal/isS');
|
||||
}
|
||||
$to = $this->dataLength;
|
||||
preg_match($this->yy_global_text, $this->data,$match,PREG_OFFSET_CAPTURE,$this->counter);
|
||||
|
@@ -23,7 +23,6 @@ class Smarty_Internal_Templateparser
|
||||
{
|
||||
const ERR1 = 'Security error: Call to private object member not allowed';
|
||||
const ERR2 = 'Security error: Call to dynamic object member not allowed';
|
||||
const ERR3 = 'PHP in template not allowed. Use SmartyBC to enable it';
|
||||
|
||||
/**
|
||||
* result status
|
||||
@@ -237,16 +236,6 @@ start(res) ::= template. {
|
||||
res = $this->root_buffer->to_smarty_php($this);
|
||||
}
|
||||
|
||||
|
||||
// php tags
|
||||
template ::= template PHP(B). {
|
||||
$code = $this->compiler->compileTag('private_php',array(array('code' => B), array('type' => $this->lex->phpType )),array());
|
||||
if ($this->compiler->has_code && !empty($code)) {
|
||||
$tmp =''; foreach ($this->compiler->prefix_code as $code) {$tmp.=$code;} $this->compiler->prefix_code=array();
|
||||
$this->current_buffer->append_subtree($this, new Smarty_Internal_ParseTree_Tag($this, $this->compiler->processNocacheCode($tmp.$code,true)));
|
||||
}
|
||||
}
|
||||
|
||||
// template text
|
||||
template ::= template TEXT(B). {
|
||||
$text = $this->yystack[ $this->yyidx + 0 ]->minor;
|
||||
|
@@ -39,7 +39,7 @@ class Smarty_Autoloader
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $rootClasses = array('smarty' => 'Smarty.class.php', 'smartybc' => 'SmartyBC.class.php',);
|
||||
public static $rootClasses = array('smarty' => 'Smarty.class.php');
|
||||
|
||||
/**
|
||||
* Registers Smarty_Autoloader backward compatible to older installations.
|
||||
|
@@ -143,13 +143,7 @@ class Smarty extends Smarty_Internal_TemplateBase
|
||||
const DEBUG_OFF = 0;
|
||||
const DEBUG_ON = 1;
|
||||
const DEBUG_INDIVIDUAL = 2;
|
||||
/**
|
||||
* modes for handling of "<?php ... ?>" tags in templates.
|
||||
*/
|
||||
const PHP_PASSTHRU = 0; //-> print tags as plain text
|
||||
const PHP_QUOTE = 1; //-> escape tags as entities
|
||||
const PHP_REMOVE = 2; //-> escape tags as entities
|
||||
const PHP_ALLOW = 3; //-> escape tags as entities
|
||||
|
||||
/**
|
||||
* filter types
|
||||
*/
|
||||
@@ -369,13 +363,6 @@ class Smarty extends Smarty_Internal_TemplateBase
|
||||
*/
|
||||
public $security_policy = null;
|
||||
|
||||
/**
|
||||
* controls handling of PHP-blocks
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
public $php_handling = self::PHP_PASSTHRU;
|
||||
|
||||
/**
|
||||
* controls if the php template file resource is allowed
|
||||
*
|
||||
|
@@ -1,477 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Project: Smarty: the PHP compiling template engine
|
||||
* File: SmartyBC.class.php
|
||||
* SVN: $Id: $
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3.0 of the License, or (at your option) any later version.
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
* For questions, help, comments, discussion, etc., please join the
|
||||
* Smarty mailing list. Send a blank e-mail to
|
||||
* smarty-discussion-subscribe@googlegroups.com
|
||||
*
|
||||
* @link http://www.smarty.net/
|
||||
* @copyright 2008 New Digital Group, Inc.
|
||||
* @author Monte Ohrt <monte at ohrt dot com>
|
||||
* @author Uwe Tews
|
||||
* @author Rodney Rehm
|
||||
* @package Smarty
|
||||
*/
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
require_once dirname(__FILE__) . '/Smarty.class.php';
|
||||
|
||||
/**
|
||||
* Smarty Backward Compatibility Wrapper Class
|
||||
*
|
||||
* @package Smarty
|
||||
*/
|
||||
class SmartyBC extends Smarty
|
||||
{
|
||||
/**
|
||||
* Smarty 2 BC
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $_version = self::SMARTY_VERSION;
|
||||
|
||||
/**
|
||||
* This is an array of directories where trusted php scripts reside.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $trusted_dir = array();
|
||||
|
||||
/**
|
||||
* Initialize new SmartyBC object
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* wrapper for assign_by_ref
|
||||
*
|
||||
* @param string $tpl_var the template variable name
|
||||
* @param mixed &$value the referenced value to assign
|
||||
*/
|
||||
public function assign_by_ref($tpl_var, &$value)
|
||||
{
|
||||
$this->assignByRef($tpl_var, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* wrapper for append_by_ref
|
||||
*
|
||||
* @param string $tpl_var the template variable name
|
||||
* @param mixed &$value the referenced value to append
|
||||
* @param boolean $merge flag if array elements shall be merged
|
||||
*/
|
||||
public function append_by_ref($tpl_var, &$value, $merge = false)
|
||||
{
|
||||
$this->appendByRef($tpl_var, $value, $merge);
|
||||
}
|
||||
|
||||
/**
|
||||
* clear the given assigned template variable.
|
||||
*
|
||||
* @param string $tpl_var the template variable to clear
|
||||
*/
|
||||
public function clear_assign($tpl_var)
|
||||
{
|
||||
$this->clearAssign($tpl_var);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers custom function to be used in templates
|
||||
*
|
||||
* @param string $function the name of the template function
|
||||
* @param string $function_impl the name of the PHP function to register
|
||||
* @param bool $cacheable
|
||||
* @param mixed $cache_attrs
|
||||
*
|
||||
* @throws \SmartyException
|
||||
*/
|
||||
public function register_function($function, $function_impl, $cacheable = true, $cache_attrs = null)
|
||||
{
|
||||
$this->registerPlugin('function', $function, $function_impl, $cacheable, $cache_attrs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregister custom function
|
||||
*
|
||||
* @param string $function name of template function
|
||||
*/
|
||||
public function unregister_function($function)
|
||||
{
|
||||
$this->unregisterPlugin('function', $function);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers object to be used in templates
|
||||
*
|
||||
* @param string $object name of template object
|
||||
* @param object $object_impl the referenced PHP object to register
|
||||
* @param array $allowed list of allowed methods (empty = all)
|
||||
* @param boolean $smarty_args smarty argument format, else traditional
|
||||
* @param array $block_methods list of methods that are block format
|
||||
*
|
||||
* @throws SmartyException
|
||||
* @internal param array $block_functs list of methods that are block format
|
||||
*/
|
||||
public function register_object(
|
||||
$object,
|
||||
$object_impl,
|
||||
$allowed = array(),
|
||||
$smarty_args = true,
|
||||
$block_methods = array()
|
||||
) {
|
||||
settype($allowed, 'array');
|
||||
settype($smarty_args, 'boolean');
|
||||
$this->registerObject($object, $object_impl, $allowed, $smarty_args, $block_methods);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregister object
|
||||
*
|
||||
* @param string $object name of template object
|
||||
*/
|
||||
public function unregister_object($object)
|
||||
{
|
||||
$this->unregisterObject($object);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers block function to be used in templates
|
||||
*
|
||||
* @param string $block name of template block
|
||||
* @param string $block_impl PHP function to register
|
||||
* @param bool $cacheable
|
||||
* @param mixed $cache_attrs
|
||||
*
|
||||
* @throws \SmartyException
|
||||
*/
|
||||
public function register_block($block, $block_impl, $cacheable = true, $cache_attrs = null)
|
||||
{
|
||||
$this->registerPlugin('block', $block, $block_impl, $cacheable, $cache_attrs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregister block function
|
||||
*
|
||||
* @param string $block name of template function
|
||||
*/
|
||||
public function unregister_block($block)
|
||||
{
|
||||
$this->unregisterPlugin('block', $block);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers compiler function
|
||||
*
|
||||
* @param string $function name of template function
|
||||
* @param string $function_impl name of PHP function to register
|
||||
* @param bool $cacheable
|
||||
*
|
||||
* @throws \SmartyException
|
||||
*/
|
||||
public function register_compiler_function($function, $function_impl, $cacheable = true)
|
||||
{
|
||||
$this->registerPlugin('compiler', $function, $function_impl, $cacheable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregister compiler function
|
||||
*
|
||||
* @param string $function name of template function
|
||||
*/
|
||||
public function unregister_compiler_function($function)
|
||||
{
|
||||
$this->unregisterPlugin('compiler', $function);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers modifier to be used in templates
|
||||
*
|
||||
* @param string $modifier name of template modifier
|
||||
* @param string $modifier_impl name of PHP function to register
|
||||
*
|
||||
* @throws \SmartyException
|
||||
*/
|
||||
public function register_modifier($modifier, $modifier_impl)
|
||||
{
|
||||
$this->registerPlugin('modifier', $modifier, $modifier_impl);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregister modifier
|
||||
*
|
||||
* @param string $modifier name of template modifier
|
||||
*/
|
||||
public function unregister_modifier($modifier)
|
||||
{
|
||||
$this->unregisterPlugin('modifier', $modifier);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a resource to fetch a template
|
||||
*
|
||||
* @param string $type name of resource
|
||||
* @param array $functions array of functions to handle resource
|
||||
*/
|
||||
public function register_resource($type, $functions)
|
||||
{
|
||||
$this->registerResource($type, $functions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregister a resource
|
||||
*
|
||||
* @param string $type name of resource
|
||||
*/
|
||||
public function unregister_resource($type)
|
||||
{
|
||||
$this->unregisterResource($type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a prefilter function to apply
|
||||
* to a template before compiling
|
||||
*
|
||||
* @param callable $function
|
||||
*
|
||||
* @throws \SmartyException
|
||||
*/
|
||||
public function register_prefilter($function)
|
||||
{
|
||||
$this->registerFilter('pre', $function);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregister a prefilter function
|
||||
*
|
||||
* @param callable $function
|
||||
*/
|
||||
public function unregister_prefilter($function)
|
||||
{
|
||||
$this->unregisterFilter('pre', $function);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a postfilter function to apply
|
||||
* to a compiled template after compilation
|
||||
*
|
||||
* @param callable $function
|
||||
*
|
||||
* @throws \SmartyException
|
||||
*/
|
||||
public function register_postfilter($function)
|
||||
{
|
||||
$this->registerFilter('post', $function);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregister a postfilter function
|
||||
*
|
||||
* @param callable $function
|
||||
*/
|
||||
public function unregister_postfilter($function)
|
||||
{
|
||||
$this->unregisterFilter('post', $function);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers an output filter function to apply
|
||||
* to a template output
|
||||
*
|
||||
* @param callable $function
|
||||
*
|
||||
* @throws \SmartyException
|
||||
*/
|
||||
public function register_outputfilter($function)
|
||||
{
|
||||
$this->registerFilter('output', $function);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregister an outputfilter function
|
||||
*
|
||||
* @param callable $function
|
||||
*/
|
||||
public function unregister_outputfilter($function)
|
||||
{
|
||||
$this->unregisterFilter('output', $function);
|
||||
}
|
||||
|
||||
/**
|
||||
* load a filter of specified type and name
|
||||
*
|
||||
* @param string $type filter type
|
||||
* @param string $name filter name
|
||||
*
|
||||
* @throws \SmartyException
|
||||
*/
|
||||
public function load_filter($type, $name)
|
||||
{
|
||||
$this->loadFilter($type, $name);
|
||||
}
|
||||
|
||||
/**
|
||||
* clear cached content for the given template and cache id
|
||||
*
|
||||
* @param string $tpl_file name of template file
|
||||
* @param string $cache_id name of cache_id
|
||||
* @param string $compile_id name of compile_id
|
||||
* @param string $exp_time expiration time
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function clear_cache($tpl_file = null, $cache_id = null, $compile_id = null, $exp_time = null)
|
||||
{
|
||||
return $this->clearCache($tpl_file, $cache_id, $compile_id, $exp_time);
|
||||
}
|
||||
|
||||
/**
|
||||
* clear the entire contents of cache (all templates)
|
||||
*
|
||||
* @param string $exp_time expire time
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function clear_all_cache($exp_time = null)
|
||||
{
|
||||
return $this->clearCache(null, null, null, $exp_time);
|
||||
}
|
||||
|
||||
/**
|
||||
* test to see if valid cache exists for this template
|
||||
*
|
||||
* @param string $tpl_file name of template file
|
||||
* @param string $cache_id
|
||||
* @param string $compile_id
|
||||
*
|
||||
* @return bool
|
||||
* @throws \Exception
|
||||
* @throws \SmartyException
|
||||
*/
|
||||
public function is_cached($tpl_file, $cache_id = null, $compile_id = null)
|
||||
{
|
||||
return $this->isCached($tpl_file, $cache_id, $compile_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* clear all the assigned template variables.
|
||||
*/
|
||||
public function clear_all_assign()
|
||||
{
|
||||
$this->clearAllAssign();
|
||||
}
|
||||
|
||||
/**
|
||||
* clears compiled version of specified template resource,
|
||||
* or all compiled template files if one is not specified.
|
||||
* This function is for advanced use only, not normally needed.
|
||||
*
|
||||
* @param string $tpl_file
|
||||
* @param string $compile_id
|
||||
* @param string $exp_time
|
||||
*
|
||||
* @return boolean results of {@link smarty_core_rm_auto()}
|
||||
*/
|
||||
public function clear_compiled_tpl($tpl_file = null, $compile_id = null, $exp_time = null)
|
||||
{
|
||||
return $this->clearCompiledTemplate($tpl_file, $compile_id, $exp_time);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether requested template exists.
|
||||
*
|
||||
* @param string $tpl_file
|
||||
*
|
||||
* @return bool
|
||||
* @throws \SmartyException
|
||||
*/
|
||||
public function template_exists($tpl_file)
|
||||
{
|
||||
return $this->templateExists($tpl_file);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array containing template variables
|
||||
*
|
||||
* @param string $name
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_template_vars($name = null)
|
||||
{
|
||||
return $this->getTemplateVars($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array containing config variables
|
||||
*
|
||||
* @param string $name
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_config_vars($name = null)
|
||||
{
|
||||
return $this->getConfigVars($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* load configuration values
|
||||
*
|
||||
* @param string $file
|
||||
* @param string $section
|
||||
* @param string $scope
|
||||
*/
|
||||
public function config_load($file, $section = null, $scope = 'global')
|
||||
{
|
||||
$this->ConfigLoad($file, $section, $scope);
|
||||
}
|
||||
|
||||
/**
|
||||
* return a reference to a registered object
|
||||
*
|
||||
* @param string $name
|
||||
*
|
||||
* @return object
|
||||
*/
|
||||
public function get_registered_object($name)
|
||||
{
|
||||
return $this->getRegisteredObject($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* clear configuration values
|
||||
*
|
||||
* @param string $var
|
||||
*/
|
||||
public function clear_config($var = null)
|
||||
{
|
||||
$this->clearConfig($var);
|
||||
}
|
||||
|
||||
/**
|
||||
* trigger Smarty error
|
||||
*
|
||||
* @param string $error_msg
|
||||
* @param integer $error_type
|
||||
*/
|
||||
public function trigger_error($error_msg, $error_type = E_USER_WARNING)
|
||||
{
|
||||
trigger_error("Smarty error: $error_msg", $error_type);
|
||||
}
|
||||
}
|
@@ -1,110 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Smarty Internal Plugin Compile Include PHP
|
||||
* Compiles the {include_php} tag
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
* @author Uwe Tews
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smarty Internal Plugin Compile Insert Class
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
*/
|
||||
class Smarty_Internal_Compile_Include_Php extends Smarty_Internal_CompileBase
|
||||
{
|
||||
/**
|
||||
* Attribute definition: Overwrites base class.
|
||||
*
|
||||
* @var array
|
||||
* @see Smarty_Internal_CompileBase
|
||||
*/
|
||||
public $required_attributes = array('file');
|
||||
|
||||
/**
|
||||
* Attribute definition: Overwrites base class.
|
||||
*
|
||||
* @var array
|
||||
* @see Smarty_Internal_CompileBase
|
||||
*/
|
||||
public $shorttag_order = array('file');
|
||||
|
||||
/**
|
||||
* Attribute definition: Overwrites base class.
|
||||
*
|
||||
* @var array
|
||||
* @see Smarty_Internal_CompileBase
|
||||
*/
|
||||
public $optional_attributes = array('once', 'assign');
|
||||
|
||||
/**
|
||||
* Compiles code for the {include_php} tag
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
|
||||
*
|
||||
* @return string
|
||||
* @throws \SmartyCompilerException
|
||||
* @throws \SmartyException
|
||||
*/
|
||||
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
|
||||
{
|
||||
if (!($compiler->smarty instanceof SmartyBC)) {
|
||||
throw new SmartyException("{include_php} is deprecated, use SmartyBC class to enable");
|
||||
}
|
||||
// check and get attributes
|
||||
$_attr = $this->getAttributes($compiler, $args);
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @var Smarty_Internal_Template $_smarty_tpl
|
||||
* used in evaluated code
|
||||
*/
|
||||
$_smarty_tpl = $compiler->template;
|
||||
$_filepath = false;
|
||||
$_file = null;
|
||||
eval('$_file = @' . $_attr[ 'file' ] . ';');
|
||||
if (!isset($compiler->smarty->security_policy) && file_exists($_file)) {
|
||||
$_filepath = $compiler->smarty->_realpath($_file, true);
|
||||
} else {
|
||||
if (isset($compiler->smarty->security_policy)) {
|
||||
$_dir = $compiler->smarty->security_policy->trusted_dir;
|
||||
} else {
|
||||
$_dir = $compiler->smarty->trusted_dir;
|
||||
}
|
||||
if (!empty($_dir)) {
|
||||
foreach ((array)$_dir as $_script_dir) {
|
||||
$_path = $compiler->smarty->_realpath($_script_dir . DIRECTORY_SEPARATOR . $_file, true);
|
||||
if (file_exists($_path)) {
|
||||
$_filepath = $_path;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($_filepath === false) {
|
||||
$compiler->trigger_template_error("{include_php} file '{$_file}' is not readable", null, true);
|
||||
}
|
||||
if (isset($compiler->smarty->security_policy)) {
|
||||
$compiler->smarty->security_policy->isTrustedPHPDir($_filepath);
|
||||
}
|
||||
if (isset($_attr[ 'assign' ])) {
|
||||
// output will be stored in a smarty variable instead of being displayed
|
||||
$_assign = $_attr[ 'assign' ];
|
||||
}
|
||||
$_once = '_once';
|
||||
if (isset($_attr[ 'once' ])) {
|
||||
if ($_attr[ 'once' ] === 'false') {
|
||||
$_once = '';
|
||||
}
|
||||
}
|
||||
if (isset($_assign)) {
|
||||
return "<?php ob_start();\ninclude{$_once} ('{$_filepath}');\n\$_smarty_tpl->assign({$_assign},ob_get_clean());\n?>";
|
||||
} else {
|
||||
return "<?php include{$_once} ('{$_filepath}');?>\n";
|
||||
}
|
||||
}
|
||||
}
|
@@ -89,7 +89,7 @@ class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase
|
||||
if (isset($compiler->smarty->security_policy)) {
|
||||
$_dir = $compiler->smarty->security_policy->trusted_dir;
|
||||
} else {
|
||||
$_dir = $compiler->smarty instanceof SmartyBC ? $compiler->smarty->trusted_dir : null;
|
||||
$_dir = null;
|
||||
}
|
||||
if (!empty($_dir)) {
|
||||
foreach ((array)$_dir as $_script_dir) {
|
||||
|
@@ -1,250 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Smarty Internal Plugin Compile PHP Expression
|
||||
* Compiles any tag which will output an expression or variable
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
* @author Uwe Tews
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smarty Internal Plugin Compile PHP Expression Class
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
*/
|
||||
class Smarty_Internal_Compile_Private_Php extends Smarty_Internal_CompileBase
|
||||
{
|
||||
/**
|
||||
* Attribute definition: Overwrites base class.
|
||||
*
|
||||
* @var array
|
||||
* @see Smarty_Internal_CompileBase
|
||||
*/
|
||||
public $required_attributes = array('code', 'type');
|
||||
|
||||
/**
|
||||
* Compiles code for generating output from any expression
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
|
||||
* @param array $parameter array with compilation parameter
|
||||
*
|
||||
* @return string
|
||||
* @throws \SmartyException
|
||||
*/
|
||||
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
|
||||
{
|
||||
// check and get attributes
|
||||
$_attr = $this->getAttributes($compiler, $args);
|
||||
$compiler->has_code = false;
|
||||
if ($_attr[ 'type' ] === 'xml') {
|
||||
$compiler->tag_nocache = true;
|
||||
$output = addcslashes($_attr[ 'code' ], "'\\");
|
||||
$compiler->parser->current_buffer->append_subtree(
|
||||
$compiler->parser,
|
||||
new Smarty_Internal_ParseTree_Tag(
|
||||
$compiler->parser,
|
||||
$compiler->processNocacheCode(
|
||||
"<?php echo '{$output}';?>\n",
|
||||
true
|
||||
)
|
||||
)
|
||||
);
|
||||
return '';
|
||||
}
|
||||
if ($_attr[ 'type' ] !== 'tag') {
|
||||
if ($compiler->php_handling === Smarty::PHP_REMOVE) {
|
||||
return '';
|
||||
} elseif ($compiler->php_handling === Smarty::PHP_QUOTE) {
|
||||
$output =
|
||||
preg_replace_callback(
|
||||
'#(<\?(?:php|=)?)|(<%)|(<script\s+language\s*=\s*["\']?\s*php\s*["\']?\s*>)|(\?>)|(%>)|(<\/script>)#i',
|
||||
array($this, 'quote'),
|
||||
$_attr[ 'code' ]
|
||||
);
|
||||
$compiler->parser->current_buffer->append_subtree(
|
||||
$compiler->parser,
|
||||
new Smarty_Internal_ParseTree_Text($output)
|
||||
);
|
||||
return '';
|
||||
} elseif ($compiler->php_handling === Smarty::PHP_PASSTHRU || $_attr[ 'type' ] === 'unmatched') {
|
||||
$compiler->tag_nocache = true;
|
||||
$output = addcslashes($_attr[ 'code' ], "'\\");
|
||||
$compiler->parser->current_buffer->append_subtree(
|
||||
$compiler->parser,
|
||||
new Smarty_Internal_ParseTree_Tag(
|
||||
$compiler->parser,
|
||||
$compiler->processNocacheCode(
|
||||
"<?php echo '{$output}';?>\n",
|
||||
true
|
||||
)
|
||||
)
|
||||
);
|
||||
return '';
|
||||
} elseif ($compiler->php_handling === Smarty::PHP_ALLOW) {
|
||||
if (!($compiler->smarty instanceof SmartyBC)) {
|
||||
$compiler->trigger_template_error(
|
||||
'$smarty->php_handling PHP_ALLOW not allowed. Use SmartyBC to enable it',
|
||||
null,
|
||||
true
|
||||
);
|
||||
}
|
||||
$compiler->has_code = true;
|
||||
return $_attr[ 'code' ];
|
||||
} else {
|
||||
$compiler->trigger_template_error('Illegal $smarty->php_handling value', null, true);
|
||||
}
|
||||
} else {
|
||||
$compiler->has_code = true;
|
||||
if (!($compiler->smarty instanceof SmartyBC)) {
|
||||
$compiler->trigger_template_error(
|
||||
'{php}{/php} tags not allowed. Use SmartyBC to enable them',
|
||||
null,
|
||||
true
|
||||
);
|
||||
}
|
||||
$ldel = preg_quote($compiler->smarty->left_delimiter, '#');
|
||||
$rdel = preg_quote($compiler->smarty->right_delimiter, '#');
|
||||
preg_match("#^({$ldel}php\\s*)((.)*?)({$rdel})#", $_attr[ 'code' ], $match);
|
||||
if (!empty($match[ 2 ])) {
|
||||
if ('nocache' === trim($match[ 2 ])) {
|
||||
$compiler->tag_nocache = true;
|
||||
} else {
|
||||
$compiler->trigger_template_error("illegal value of option flag '{$match[2]}'", null, true);
|
||||
}
|
||||
}
|
||||
return preg_replace(
|
||||
array("#^{$ldel}\\s*php\\s*(.)*?{$rdel}#", "#{$ldel}\\s*/\\s*php\\s*{$rdel}$#"),
|
||||
array('<?php ', '?>'),
|
||||
$_attr[ 'code' ]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Lexer code for PHP tags
|
||||
*
|
||||
* This code has been moved from lexer here fo easier debugging and maintenance
|
||||
*
|
||||
* @param Smarty_Internal_Templatelexer $lex
|
||||
*
|
||||
* @throws \SmartyCompilerException
|
||||
*/
|
||||
public function parsePhp(Smarty_Internal_Templatelexer $lex)
|
||||
{
|
||||
$lex->token = Smarty_Internal_Templateparser::TP_PHP;
|
||||
$close = 0;
|
||||
$lex->taglineno = $lex->line;
|
||||
$closeTag = '?>';
|
||||
if (strpos($lex->value, '<?xml') === 0) {
|
||||
$lex->is_xml = true;
|
||||
$lex->phpType = 'xml';
|
||||
return;
|
||||
} elseif (strpos($lex->value, '<?') === 0) {
|
||||
$lex->phpType = 'php';
|
||||
} elseif (strpos($lex->value, '%>') === 0) {
|
||||
$lex->phpType = 'unmatched';
|
||||
} elseif (strpos($lex->value, '?>') === 0) {
|
||||
if ($lex->is_xml) {
|
||||
$lex->is_xml = false;
|
||||
$lex->phpType = 'xml';
|
||||
return;
|
||||
}
|
||||
$lex->phpType = 'unmatched';
|
||||
} elseif (strpos($lex->value, '<s') === 0) {
|
||||
$lex->phpType = 'script';
|
||||
$closeTag = '</script>';
|
||||
} elseif (strpos($lex->value, $lex->smarty->left_delimiter) === 0) {
|
||||
if ($lex->isAutoLiteral()) {
|
||||
$lex->token = Smarty_Internal_Templateparser::TP_TEXT;
|
||||
return;
|
||||
}
|
||||
$closeTag = "{$lex->smarty->left_delimiter}/php{$lex->smarty->right_delimiter}";
|
||||
if ($lex->value === $closeTag) {
|
||||
$lex->compiler->trigger_template_error("unexpected closing tag '{$closeTag}'");
|
||||
}
|
||||
$lex->phpType = 'tag';
|
||||
}
|
||||
if ($lex->phpType === 'unmatched') {
|
||||
return;
|
||||
}
|
||||
if (($lex->phpType === 'php')
|
||||
&&
|
||||
($lex->compiler->php_handling === Smarty::PHP_PASSTHRU ||
|
||||
$lex->compiler->php_handling === Smarty::PHP_QUOTE)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
$start = $lex->counter + strlen($lex->value);
|
||||
$body = true;
|
||||
if (preg_match('~' . preg_quote($closeTag, '~') . '~i', $lex->data, $match, PREG_OFFSET_CAPTURE, $start)) {
|
||||
$close = $match[ 0 ][ 1 ];
|
||||
} else {
|
||||
$lex->compiler->trigger_template_error("missing closing tag '{$closeTag}'");
|
||||
}
|
||||
while ($body) {
|
||||
if (preg_match(
|
||||
'~([/][*])|([/][/][^\n]*)|(\'[^\'\\\\]*(?:\\.[^\'\\\\]*)*\')|("[^"\\\\]*(?:\\.[^"\\\\]*)*")~',
|
||||
$lex->data,
|
||||
$match,
|
||||
PREG_OFFSET_CAPTURE,
|
||||
$start
|
||||
)
|
||||
) {
|
||||
$value = $match[ 0 ][ 0 ];
|
||||
$from = $pos = $match[ 0 ][ 1 ];
|
||||
if ($pos > $close) {
|
||||
$body = false;
|
||||
} else {
|
||||
$start = $pos + strlen($value);
|
||||
$phpCommentStart = $value === '/*';
|
||||
if ($phpCommentStart) {
|
||||
$phpCommentEnd = preg_match('~([*][/])~', $lex->data, $match, PREG_OFFSET_CAPTURE, $start);
|
||||
if ($phpCommentEnd) {
|
||||
$pos2 = $match[ 0 ][ 1 ];
|
||||
$start = $pos2 + strlen($match[ 0 ][ 0 ]);
|
||||
}
|
||||
}
|
||||
while ($close > $pos && $close < $start) {
|
||||
if (preg_match(
|
||||
'~' . preg_quote($closeTag, '~') . '~i',
|
||||
$lex->data,
|
||||
$match,
|
||||
PREG_OFFSET_CAPTURE,
|
||||
$from
|
||||
)
|
||||
) {
|
||||
$close = $match[ 0 ][ 1 ];
|
||||
$from = $close + strlen($match[ 0 ][ 0 ]);
|
||||
} else {
|
||||
$lex->compiler->trigger_template_error("missing closing tag '{$closeTag}'");
|
||||
}
|
||||
}
|
||||
if ($phpCommentStart && (!$phpCommentEnd || $pos2 > $close)) {
|
||||
$lex->taglineno = $lex->line + substr_count(substr($lex->data, $lex->counter, $start), "\n");
|
||||
$lex->compiler->trigger_template_error("missing PHP comment closing tag '*/'");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$body = false;
|
||||
}
|
||||
}
|
||||
$lex->value = substr($lex->data, $lex->counter, $close + strlen($closeTag) - $lex->counter);
|
||||
}
|
||||
|
||||
/*
|
||||
* Call back function for $php_handling = PHP_QUOTE
|
||||
*
|
||||
*/
|
||||
/**
|
||||
* @param $match
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function quote($match)
|
||||
{
|
||||
return htmlspecialchars($match[ 0 ], ENT_QUOTES);
|
||||
}
|
||||
}
|
@@ -203,13 +203,6 @@ abstract class Smarty_Internal_TemplateCompilerBase
|
||||
*/
|
||||
public $blockOrFunctionCode = '';
|
||||
|
||||
/**
|
||||
* php_handling setting either from Smarty or security
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $php_handling = 0;
|
||||
|
||||
/**
|
||||
* flags for used modifier plugins
|
||||
*
|
||||
@@ -438,11 +431,6 @@ abstract class Smarty_Internal_TemplateCompilerBase
|
||||
}
|
||||
$this->smarty->_debug->start_compile($this->template);
|
||||
}
|
||||
if (isset($this->template->smarty->security_policy)) {
|
||||
$this->php_handling = $this->template->smarty->security_policy->php_handling;
|
||||
} else {
|
||||
$this->php_handling = $this->template->smarty->php_handling;
|
||||
}
|
||||
$this->parent_compiler = $parent_compiler ? $parent_compiler : $this;
|
||||
$nocache = isset($nocache) ? $nocache : false;
|
||||
if (empty($template->compiled->nocache_hash)) {
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -362,7 +362,6 @@ class Smarty_Internal_TestInstall
|
||||
'smarty_internal_compile_function.php' => true,
|
||||
'smarty_internal_compile_if.php' => true,
|
||||
'smarty_internal_compile_include.php' => true,
|
||||
'smarty_internal_compile_include_php.php' => true,
|
||||
'smarty_internal_compile_insert.php' => true,
|
||||
'smarty_internal_compile_ldelim.php' => true,
|
||||
'smarty_internal_compile_make_nocache.php' => true,
|
||||
@@ -373,7 +372,6 @@ class Smarty_Internal_TestInstall
|
||||
'smarty_internal_compile_private_modifier.php' => true,
|
||||
'smarty_internal_compile_private_object_block_function.php' => true,
|
||||
'smarty_internal_compile_private_object_function.php' => true,
|
||||
'smarty_internal_compile_private_php.php' => true,
|
||||
'smarty_internal_compile_private_print_expression.php' => true,
|
||||
'smarty_internal_compile_private_registered_block.php' => true,
|
||||
'smarty_internal_compile_private_registered_function.php' => true,
|
||||
|
@@ -21,19 +21,6 @@
|
||||
*/
|
||||
class Smarty_Security
|
||||
{
|
||||
/**
|
||||
* This determines how Smarty handles "<?php ... ?>" tags in templates.
|
||||
* possible values:
|
||||
* <ul>
|
||||
* <li>Smarty::PHP_PASSTHRU -> echo PHP tags as they are</li>
|
||||
* <li>Smarty::PHP_QUOTE -> escape tags as entities</li>
|
||||
* <li>Smarty::PHP_REMOVE -> remove php tags</li>
|
||||
* <li>Smarty::PHP_ALLOW -> execute php tags</li>
|
||||
* </ul>
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
public $php_handling = Smarty::PHP_PASSTHRU;
|
||||
|
||||
/**
|
||||
* This is the list of template directories that are considered secure.
|
||||
|
@@ -9,34 +9,14 @@
|
||||
*/
|
||||
class PHPUnit_Smarty extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* Smarty object
|
||||
*
|
||||
* @var SmartyBC
|
||||
*/
|
||||
public $smartyBC = null;
|
||||
|
||||
/**
|
||||
* SmartyBC object
|
||||
* Smarty object
|
||||
*
|
||||
* @var Smarty
|
||||
*/
|
||||
public $smarty = null;
|
||||
|
||||
/**
|
||||
* Flag if test is using the Smarty object
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $loadSmarty = true;
|
||||
|
||||
/**
|
||||
* Flag if test is using the SmartyBC object
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $loadSmartyBC = false;
|
||||
|
||||
/**
|
||||
* Flag for initialization at first test
|
||||
*
|
||||
@@ -161,23 +141,15 @@ class PHPUnit_Smarty extends PHPUnit_Framework_TestCase
|
||||
self::$init = false;
|
||||
}
|
||||
clearstatcache();
|
||||
|
||||
// instance Smarty class
|
||||
if ($this->loadSmarty) {
|
||||
$this->smarty = new Smarty;
|
||||
if (individualFolders != 'true') {
|
||||
$this->smarty->setCompileDir(dirname(__FILE__) . '/templates_c');
|
||||
$this->smarty->setCacheDir(dirname(__FILE__) . '/cache');
|
||||
}
|
||||
$this->smarty = new Smarty;
|
||||
if (individualFolders != 'true') {
|
||||
$this->smarty->setCompileDir(dirname(__FILE__) . '/templates_c');
|
||||
$this->smarty->setCacheDir(dirname(__FILE__) . '/cache');
|
||||
}
|
||||
// instance SmartyBC class
|
||||
if ($this->loadSmartyBC) {
|
||||
$this->smartyBC = new SmartyBC;
|
||||
if (individualFolders != 'true') {
|
||||
$this->smartyBC->setCompileDir(dirname(__FILE__) . '/templates_c');
|
||||
$this->smartyBC->setCacheDir(dirname(__FILE__) . '/cache');
|
||||
}
|
||||
}
|
||||
$smarty = $this->getSmartyObj();
|
||||
|
||||
$this->getSmartyObj();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -658,10 +630,10 @@ KEY `name` (`name`)
|
||||
|
||||
/**
|
||||
* Gat Smarty object
|
||||
* @return null|\Smarty|\SmartyBC
|
||||
* @return null|\Smarty
|
||||
*/
|
||||
public function getSmartyObj(){
|
||||
return isset($this->smarty) ? $this->smarty : (isset($this->smartyBC) ? $this->smartyBC : null);
|
||||
return $this->smarty;
|
||||
}
|
||||
|
||||
public static function getSmartyPluginsDir(){
|
||||
@@ -689,11 +661,5 @@ KEY `name` (`name`)
|
||||
if (isset($this->smarty)) {
|
||||
$this->smarty = null;
|
||||
}
|
||||
if (isset($this->smartyBC->smarty)) {
|
||||
$this->smartyBC->smarty = null;
|
||||
}
|
||||
if (isset($this->smartyBC)) {
|
||||
$this->smartyBC = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
class FilterTest extends PHPUnit_Smarty
|
||||
{
|
||||
public $loadSmartyBC = true;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
@@ -57,13 +56,6 @@ class FilterTest extends PHPUnit_Smarty
|
||||
$this->assertEquals("<br>hello world", $this->smarty->fetch($tpl));
|
||||
}
|
||||
|
||||
public function testLoadedOutputFilterWrapper()
|
||||
{
|
||||
$this->smartyBC->load_filter(Smarty::FILTER_OUTPUT, 'trimwhitespace');
|
||||
$tpl = $this->smartyBC->createTemplate('eval:{" <br>hello world"}');
|
||||
$this->assertEquals("<br>hello world", $this->smartyBC->fetch($tpl));
|
||||
}
|
||||
|
||||
/**
|
||||
* test registered output filter
|
||||
*/
|
||||
@@ -164,9 +156,9 @@ class FilterTest extends PHPUnit_Smarty
|
||||
|
||||
public function testRegisteredOutputFilterWrapper()
|
||||
{
|
||||
$this->smartyBC->register_outputfilter('myoutputfilter');
|
||||
$tpl = $this->smartyBC->createTemplate('eval:{"hello world"}');
|
||||
$this->assertEquals("hello world", $this->smartyBC->fetch($tpl));
|
||||
$this->smarty->registerFilter('output', 'myoutputfilter');
|
||||
$tpl = $this->smarty->createTemplate('eval:{"hello world"}');
|
||||
$this->assertEquals("hello world", $this->smarty->fetch($tpl));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -1,37 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Smarty PHPunit tests SmartyBC code
|
||||
*
|
||||
* @package PHPunit
|
||||
* @author Uwe Tews
|
||||
*/
|
||||
|
||||
/**
|
||||
* class SmartyBC class tests
|
||||
*
|
||||
* @runTestsInSeparateProcess
|
||||
* @preserveGlobalState disabled
|
||||
* @backupStaticAttributes enabled
|
||||
*/
|
||||
class SmartyBcTest extends PHPUnit_Smarty
|
||||
{
|
||||
public $loadSmartyBC = true;
|
||||
public $loadSmarty = false;
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->setUpSmarty(dirname(__FILE__));
|
||||
}
|
||||
|
||||
|
||||
public function testInit()
|
||||
{
|
||||
$this->cleanDirs();
|
||||
}
|
||||
/**
|
||||
* test {php} tag
|
||||
*/
|
||||
public function testSmartyPhpTag()
|
||||
{
|
||||
$this->assertEquals('hello world', $this->smartyBC->fetch('string:{php} echo "hello world"; {/php}'));
|
||||
}
|
||||
}
|
@@ -1,2 +0,0 @@
|
||||
# Ignore anything in here, but keep this directory
|
||||
*
|
@@ -1,2 +0,0 @@
|
||||
# Ignore anything in here, but keep this directory
|
||||
*
|
@@ -15,15 +15,12 @@
|
||||
*/
|
||||
class SecurityTest extends PHPUnit_Smarty
|
||||
{
|
||||
public $loadSmartyBC = true;
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->setUpSmarty(dirname(__FILE__));
|
||||
|
||||
$this->smarty->setForceCompile(true);
|
||||
$this->smarty->enableSecurity();
|
||||
$this->smartyBC->setForceCompile(true);
|
||||
$this->smartyBC->enableSecurity();
|
||||
}
|
||||
public function testInit()
|
||||
{
|
||||
@@ -190,33 +187,25 @@ class SecurityTest extends PHPUnit_Smarty
|
||||
$this->smarty->fetch('string:{"hello"|upper}{"world"|lower}');
|
||||
}
|
||||
|
||||
/**
|
||||
* test Smarty::PHP_QUOTE
|
||||
*/
|
||||
public function testSmartyPhpQuote()
|
||||
{
|
||||
$this->smarty->security_policy->php_handling = Smarty::PHP_QUOTE;
|
||||
$this->assertEquals('<?php echo "hello world"; ?>', $this->smarty->fetch('string:<?php echo "hello world"; ?>'));
|
||||
}
|
||||
|
||||
/**
|
||||
* test Smarty::PHP_REMOVE
|
||||
*/
|
||||
public function testSmartyPhpRemove()
|
||||
{
|
||||
$this->smarty->security_policy->php_handling = Smarty::PHP_REMOVE;
|
||||
$this->assertEquals('', $this->smarty->fetch('string:<?php echo "hello world"; ?>'));
|
||||
}
|
||||
|
||||
/**
|
||||
* test Smarty::PHP_ALLOW
|
||||
* test Smarty no longer handles embedded PHP
|
||||
*/
|
||||
public function testSmartyPhpAllow()
|
||||
{
|
||||
$this->smartyBC->security_policy->php_handling = Smarty::PHP_ALLOW;
|
||||
$this->assertEquals('hello world', $this->smartyBC->fetch('string:<?php echo "hello world"; ?>'));
|
||||
$this->assertEquals('<?php echo "hello world"; ?>', $this->smarty->fetch('string:<?php echo "hello world"; ?>'));
|
||||
}
|
||||
|
||||
public function testSmartyPhpAllow2()
|
||||
{
|
||||
$this->assertEquals('<? echo "hello world"; ?>', $this->smarty->fetch('string:<? echo "hello world"; ?>'));
|
||||
}
|
||||
|
||||
public function testSmartyPhpAllow3()
|
||||
{
|
||||
$this->assertEquals('<% echo "hello world"; %>', $this->smarty->fetch('string:<% echo "hello world"; %>'));
|
||||
}
|
||||
|
||||
/**
|
||||
* test standard directory
|
||||
*/
|
||||
|
@@ -1,48 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Smarty PHPunit tests appendByRef method
|
||||
*
|
||||
* @package PHPunit
|
||||
* @author Uwe Tews
|
||||
*/
|
||||
|
||||
/**
|
||||
* class for appendByRef tests
|
||||
*
|
||||
* @runTestsInSeparateProcess
|
||||
* @preserveGlobalState disabled
|
||||
* @backupStaticAttributes enabled
|
||||
*/
|
||||
class AppendByRefBCTest extends PHPUnit_Smarty
|
||||
{
|
||||
public $loadSmartyBC = true;
|
||||
public $loadSmarty = false;
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->setUpSmarty(dirname(__FILE__));
|
||||
}
|
||||
|
||||
public function testInit()
|
||||
{
|
||||
$this->cleanDirs();
|
||||
}
|
||||
|
||||
public function testSmarty2AppendByRef()
|
||||
{
|
||||
$bar = 'bar';
|
||||
$bar2 = 'bar2';
|
||||
$this->smartyBC->append_by_ref('foo', $bar);
|
||||
$this->smartyBC->append_by_ref('foo', $bar2);
|
||||
$bar = 'newbar';
|
||||
$bar2 = 'newbar2';
|
||||
$this->assertEquals('newbar newbar2', $this->smartyBC->fetch('eval:{$foo[0]} {$foo[1]}'));
|
||||
}
|
||||
|
||||
public function testSmarty2AppendByRefUnassigned()
|
||||
{
|
||||
$bar2 = 'bar2';
|
||||
$this->smartyBC->append_by_ref('foo', $bar2);
|
||||
$bar2 = 'newbar2';
|
||||
$this->assertEquals('newbar2', $this->smartyBC->fetch('eval:{$foo[0]}'));
|
||||
}
|
||||
}
|
@@ -1,51 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Smarty PHPunit tests assignByRef method
|
||||
*
|
||||
* @package PHPunit
|
||||
* @author Uwe Tews
|
||||
*/
|
||||
|
||||
/**
|
||||
* class for assignByRef tests
|
||||
*
|
||||
* @runTestsInSeparateProcess
|
||||
* @preserveGlobalState disabled
|
||||
* @backupStaticAttributes enabled
|
||||
*/
|
||||
class AssignByRefBCTest extends PHPUnit_Smarty
|
||||
{
|
||||
public $loadSmartyBC = true;
|
||||
public $loadSmarty = false;
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->setUpSmarty(dirname(__FILE__));
|
||||
}
|
||||
|
||||
|
||||
public function testInit()
|
||||
{
|
||||
$this->cleanDirs();
|
||||
}
|
||||
/**
|
||||
* test Smarty2 assign_By_Ref
|
||||
*/
|
||||
public function testSmarty2AssignByRef()
|
||||
{
|
||||
$bar = 'bar';
|
||||
$this->smartyBC->assign_by_ref('foo', $bar);
|
||||
$bar = 'newbar';
|
||||
$this->assertEquals('newbar', $this->smartyBC->fetch('eval:{$foo}'));
|
||||
}
|
||||
|
||||
/**
|
||||
* test Smarty2's behaviour of assign_By_Ref (Issue 88)
|
||||
*/
|
||||
public function testSmarty2AssignByRef2()
|
||||
{
|
||||
$bar = 'bar';
|
||||
$this->smartyBC->assign_by_ref('foo', $bar);
|
||||
$this->smartyBC->fetch('eval:{$foo = "newbar"}');
|
||||
$this->assertEquals('newbar', $bar);
|
||||
}
|
||||
}
|
@@ -1,40 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Smarty PHPunit tests clearing all assigned variables
|
||||
*
|
||||
* @package PHPunit
|
||||
* @author Uwe Tews
|
||||
*/
|
||||
|
||||
/**
|
||||
* class for clearing all assigned variables tests
|
||||
*
|
||||
* @runTestsInSeparateProcess
|
||||
* @preserveGlobalState disabled
|
||||
* @backupStaticAttributes enabled
|
||||
*/
|
||||
class ClearAllAssignBCTest extends PHPUnit_Smarty
|
||||
{
|
||||
public $loadSmartyBC = true;
|
||||
public $loadSmarty = false;
|
||||
protected $_dataBC = null;
|
||||
protected $_tplBC = null;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->setUpSmarty(dirname(__FILE__));
|
||||
|
||||
$this->smartyBC->assign('foo', 'foo');
|
||||
$this->_dataBC = $this->smartyBC->createData($this->smartyBC);
|
||||
$this->_dataBC->assign('bar', 'bar');
|
||||
$this->_tplBC = $this->smartyBC->createTemplate('eval:{$foo}{$bar}{$blar}', null, null, $this->_dataBC);
|
||||
$this->_tplBC->assign('blar', 'blar');
|
||||
}
|
||||
|
||||
public function testSmarty2ClearAllAssignInSmarty()
|
||||
{
|
||||
error_reporting((error_reporting() & ~(E_NOTICE | E_WARNING | E_USER_NOTICE)));
|
||||
$this->smartyBC->clear_all_assign();
|
||||
$this->assertEquals('barblar', $this->smartyBC->fetch($this->_tplBC));
|
||||
}
|
||||
}
|
@@ -1,47 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Smarty PHPunit tests clearing assigned variables
|
||||
*
|
||||
* @package PHPunit
|
||||
* @author Uwe Tews
|
||||
*/
|
||||
|
||||
/**
|
||||
* class for clearing assigned variables tests
|
||||
*
|
||||
* @runTestsInSeparateProcess
|
||||
* @preserveGlobalState disabled
|
||||
* @backupStaticAttributes enabled
|
||||
*/
|
||||
class ClearAssignBCTest extends PHPUnit_Smarty
|
||||
{
|
||||
public $loadSmartyBC = true;
|
||||
public $loadSmarty = false;
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->setUpSmarty(dirname(__FILE__));
|
||||
|
||||
$this->smartyBC->assign('foo', 'foo');
|
||||
$this->smartyBC->assign('bar', 'bar');
|
||||
$this->smartyBC->assign('blar', 'blar');
|
||||
}
|
||||
|
||||
|
||||
public function testInit()
|
||||
{
|
||||
$this->cleanDirs();
|
||||
}
|
||||
public function testSmarty2ClearAssign()
|
||||
{
|
||||
$this->smartyBC->setErrorReporting(error_reporting() & ~(E_NOTICE | E_USER_NOTICE | E_WARNING));
|
||||
$this->smartyBC->clear_assign('blar');
|
||||
$this->assertEquals('foobar', $this->smartyBC->fetch('eval:{$foo}{$bar}{$blar}'));
|
||||
}
|
||||
|
||||
public function testSmarty2ArrayClearAssign()
|
||||
{
|
||||
$this->smartyBC->setErrorReporting(error_reporting() & ~(E_NOTICE | E_USER_NOTICE | E_WARNING));
|
||||
$this->smartyBC->clear_assign(array('blar', 'foo'));
|
||||
$this->assertEquals('bar', $this->smartyBC->fetch('eval:{$foo}{$bar}{$blar}'));
|
||||
}
|
||||
}
|
@@ -1,29 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Smarty PHPunit tests for deleting compiled templates
|
||||
*
|
||||
* @package PHPunit
|
||||
* @author Uwe Tews
|
||||
* @author Rodney Rehm
|
||||
*/
|
||||
include_once dirname(__FILE__) . '/ClearCompiledTest.php';
|
||||
|
||||
/**
|
||||
* class for delete compiled template tests
|
||||
*
|
||||
* @runTestsInSeparateProcess
|
||||
* @preserveGlobalState disabled
|
||||
* @backupStaticAttributes enabled
|
||||
*/
|
||||
class ClearCompiledBCTest extends ClearCompiledTest
|
||||
{
|
||||
public $loadSmartyBC = true;
|
||||
public $loadSmarty = false;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->setUpSmarty(dirname(__FILE__));
|
||||
$this->smartyBC->addTemplateDir('./templates_2/');
|
||||
$this->methodName = 'clear_compiled_tpl';
|
||||
}
|
||||
}
|
@@ -1,54 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Smarty PHPunit tests get_template_vars method
|
||||
*
|
||||
* @package PHPunit
|
||||
* @author Uwe Tews
|
||||
*/
|
||||
|
||||
/**
|
||||
* class for get_template_vars method test
|
||||
*
|
||||
* @runTestsInSeparateProcess
|
||||
* @preserveGlobalState disabled
|
||||
* @backupStaticAttributes enabled
|
||||
*/
|
||||
class get_template_varsBCTest extends PHPUnit_Smarty
|
||||
{
|
||||
public $loadSmartyBC = true;
|
||||
public $loadSmarty = false;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->setUpSmarty(dirname(__FILE__));
|
||||
}
|
||||
|
||||
|
||||
public function testInit()
|
||||
{
|
||||
$this->cleanDirs();
|
||||
}
|
||||
/**
|
||||
* test root get_template_vars single value
|
||||
*/
|
||||
public function testGetSingleTemplateVarScopeRoot()
|
||||
{
|
||||
$this->smartyBC->assign('foo', 'bar');
|
||||
$this->smartyBC->assign('blar', 'buh');
|
||||
$this->assertEquals("bar", $this->smartyBC->get_template_vars('foo'));
|
||||
}
|
||||
|
||||
/**
|
||||
* test root get_template_vars all values
|
||||
*/
|
||||
public function testGetAllTemplateVarsScopeRoot()
|
||||
{
|
||||
$this->smartyBC->assign('foo', 'bar');
|
||||
$this->smartyBC->assign('blar', 'buh');
|
||||
$vars = $this->smartyBC->get_template_vars();
|
||||
$this->assertTrue(is_array($vars));
|
||||
$this->assertEquals("bar", $vars['foo']);
|
||||
$this->assertEquals("buh", $vars['blar']);
|
||||
}
|
||||
|
||||
}
|
@@ -15,12 +15,10 @@
|
||||
*/
|
||||
class RegisterBlockTest extends PHPUnit_Smarty
|
||||
{
|
||||
public $loadSmartyBC = true;
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->setUpSmarty(dirname(__FILE__));
|
||||
$this->smarty->disableSecurity();
|
||||
$this->smartyBC->disableSecurity();
|
||||
}
|
||||
|
||||
|
||||
@@ -54,9 +52,9 @@ class RegisterBlockTest extends PHPUnit_Smarty
|
||||
|
||||
public function testRegisterBlockFunctionWrapper()
|
||||
{
|
||||
$this->smartyBC->register_block('testblock', 'myblock');
|
||||
$this->smartyBC->assign('value', 1);
|
||||
$this->assertEquals('function hello world 1 1 function hello world 1 2 function hello world 1 3 ', $this->smartyBC->fetch('eval:{testblock}hello world {$value}{/testblock}'));
|
||||
$this->smarty->registerPlugin('block', 'testblock', 'myblock');
|
||||
$this->smarty->assign('value', 1);
|
||||
$this->assertEquals('function hello world 1 1 function hello world 1 2 function hello world 1 3 ', $this->smarty->fetch('eval:{testblock}hello world {$value}{/testblock}'));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -71,9 +69,9 @@ class RegisterBlockTest extends PHPUnit_Smarty
|
||||
|
||||
public function testRegisterBlockClassWrapper()
|
||||
{
|
||||
$this->smartyBC->register_block('testblock', array('myblockclass', 'static_method'));
|
||||
$this->smartyBC->assign('value', 2);
|
||||
$this->assertEquals('static hello world 2 1 static hello world 2 2 static hello world 2 3 ', $this->smartyBC->fetch('eval:{testblock}hello world {$value}{/testblock}'));
|
||||
$this->smarty->registerPlugin('block', 'testblock', array('myblockclass', 'static_method'));
|
||||
$this->smarty->assign('value', 2);
|
||||
$this->assertEquals('static hello world 2 1 static hello world 2 2 static hello world 2 3 ', $this->smarty->fetch('eval:{testblock}hello world {$value}{/testblock}'));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -90,9 +88,9 @@ class RegisterBlockTest extends PHPUnit_Smarty
|
||||
public function testRegisterBlockObjectWrapper()
|
||||
{
|
||||
$myblock_object = new myblockclass;
|
||||
$this->smartyBC->register_block('testblock', array($myblock_object, 'object_method'));
|
||||
$this->smartyBC->assign('value', 3);
|
||||
$this->assertEquals('object hello world 3 1 object hello world 3 2 object hello world 3 3 ', $this->smartyBC->fetch('eval:{testblock}hello world {$value}{/testblock}'));
|
||||
$this->smarty->registerPlugin('block', 'testblock', array($myblock_object, 'object_method'));
|
||||
$this->smarty->assign('value', 3);
|
||||
$this->assertEquals('object hello world 3 1 object hello world 3 2 object hello world 3 3 ', $this->smarty->fetch('eval:{testblock}hello world {$value}{/testblock}'));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -166,14 +164,14 @@ class RegisterBlockTest extends PHPUnit_Smarty
|
||||
*/
|
||||
public function testRegisterBlockCaching1Wrapper()
|
||||
{
|
||||
$this->smartyBC->caching = 1;
|
||||
$this->smartyBC->cache_lifetime = 1000;
|
||||
$this->smartyBC->setForceCompile(true);
|
||||
$this->smartyBC->assign('x', 1);
|
||||
$this->smartyBC->assign('y', 10);
|
||||
$this->smartyBC->assign('z', 100);
|
||||
$this->smartyBC->register_block('testblock', 'myblockcache');
|
||||
$this->assertEquals('1 10 100', $this->smartyBC->fetch('test_register_block.tpl'));
|
||||
$this->smarty->caching = 1;
|
||||
$this->smarty->cache_lifetime = 1000;
|
||||
$this->smarty->setForceCompile(true);
|
||||
$this->smarty->assign('x', 1);
|
||||
$this->smarty->assign('y', 10);
|
||||
$this->smarty->assign('z', 100);
|
||||
$this->smarty->registerPlugin('block', 'testblock', 'myblockcache');
|
||||
$this->assertEquals('1 10 100', $this->smarty->fetch('test_register_block.tpl'));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -183,13 +181,13 @@ class RegisterBlockTest extends PHPUnit_Smarty
|
||||
*/
|
||||
public function testRegisterBlockCaching2Wrapper()
|
||||
{
|
||||
$this->smartyBC->caching = 1;
|
||||
$this->smartyBC->cache_lifetime = 1000;
|
||||
$this->smartyBC->assign('x', 2);
|
||||
$this->smartyBC->assign('y', 20);
|
||||
$this->smartyBC->assign('z', 200);
|
||||
$this->smartyBC->register_block('testblock', 'myblockcache');
|
||||
$this->assertEquals('1 10 100', $this->smartyBC->fetch('test_register_block.tpl'));
|
||||
$this->smarty->caching = 1;
|
||||
$this->smarty->cache_lifetime = 1000;
|
||||
$this->smarty->assign('x', 2);
|
||||
$this->smarty->assign('y', 20);
|
||||
$this->smarty->assign('z', 200);
|
||||
$this->smarty->registerPlugin('block', 'testblock', 'myblockcache');
|
||||
$this->assertEquals('1 10 100', $this->smarty->fetch('test_register_block.tpl'));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -199,14 +197,14 @@ class RegisterBlockTest extends PHPUnit_Smarty
|
||||
*/
|
||||
public function testRegisterBlockCaching3Wrapper()
|
||||
{
|
||||
$this->smartyBC->caching = 1;
|
||||
$this->smartyBC->cache_lifetime = 1000;
|
||||
$this->smartyBC->setForceCompile(true);
|
||||
$this->smartyBC->assign('x', 3);
|
||||
$this->smartyBC->assign('y', 30);
|
||||
$this->smartyBC->assign('z', 300);
|
||||
$this->smartyBC->register_block('testblock', 'myblockcache', false);
|
||||
$this->assertEquals('3 30 300', $this->smartyBC->fetch('test_register_block.tpl'));
|
||||
$this->smarty->caching = 1;
|
||||
$this->smarty->cache_lifetime = 1000;
|
||||
$this->smarty->setForceCompile(true);
|
||||
$this->smarty->assign('x', 3);
|
||||
$this->smarty->assign('y', 30);
|
||||
$this->smarty->assign('z', 300);
|
||||
$this->smarty->registerPlugin('block', 'testblock', 'myblockcache', false);
|
||||
$this->assertEquals('3 30 300', $this->smarty->fetch('test_register_block.tpl'));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -216,13 +214,13 @@ class RegisterBlockTest extends PHPUnit_Smarty
|
||||
*/
|
||||
public function testRegisterBlockCaching4Wrapper()
|
||||
{
|
||||
$this->smartyBC->caching = 1;
|
||||
$this->smartyBC->cache_lifetime = 1000;
|
||||
$this->smartyBC->assign('x', 4);
|
||||
$this->smartyBC->assign('y', 40);
|
||||
$this->smartyBC->assign('z', 400);
|
||||
$this->smartyBC->register_block('testblock', 'myblockcache', false);
|
||||
$this->assertEquals('3 40 300', $this->smartyBC->fetch('test_register_block.tpl'));
|
||||
$this->smarty->caching = 1;
|
||||
$this->smarty->cache_lifetime = 1000;
|
||||
$this->smarty->assign('x', 4);
|
||||
$this->smarty->assign('y', 40);
|
||||
$this->smarty->assign('z', 400);
|
||||
$this->smarty->registerPlugin('block', 'testblock', 'myblockcache', false);
|
||||
$this->assertEquals('3 40 300', $this->smarty->fetch('test_register_block.tpl'));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -237,9 +235,9 @@ class RegisterBlockTest extends PHPUnit_Smarty
|
||||
|
||||
public function testUnregisterBlockWrapper()
|
||||
{
|
||||
$this->smartyBC->register_block('testblock', 'myblock');
|
||||
$this->smartyBC->unregister_block('testblock');
|
||||
$this->assertFalse(isset($this->smartyBC->registered_plugins[Smarty::PLUGIN_BLOCK]['testblock']));
|
||||
$this->smarty->registerPlugin('block', 'testblock', 'myblock');
|
||||
$this->smarty->unregisterPlugin('block', 'testblock');
|
||||
$this->assertFalse(isset($this->smarty->registered_plugins[Smarty::PLUGIN_BLOCK]['testblock']));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -1,127 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Smarty PHPunit tests register->compilerFunction / unregister->compilerFunction methods
|
||||
*
|
||||
* @package PHPunit
|
||||
* @author Uwe Tews
|
||||
*/
|
||||
|
||||
/**
|
||||
* class for register->compilerFunction / unregister->compilerFunction methods tests
|
||||
*
|
||||
* @runTestsInSeparateProcess
|
||||
* @preserveGlobalState disabled
|
||||
* @backupStaticAttributes enabled
|
||||
*/
|
||||
class RegisterCompilerFunctionBCTest extends PHPUnit_Smarty
|
||||
{
|
||||
public $loadSmartyBC = true;
|
||||
public $loadSmarty = false;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->setUpSmarty(dirname(__FILE__));
|
||||
}
|
||||
|
||||
|
||||
public function testInit()
|
||||
{
|
||||
$this->cleanDirs();
|
||||
}
|
||||
/**
|
||||
* test register->compilerFunction method for function
|
||||
*/
|
||||
public function testRegisterCompilerFunction()
|
||||
{
|
||||
$this->smartyBC->register_compiler_function('testcompilerfunction', 'mycompilerfunctionBC');
|
||||
$this->assertEquals('mycompilerfunctionBC', $this->smartyBC->registered_plugins['compiler']['testcompilerfunction'][0]);
|
||||
$this->assertEquals('hello world 1', $this->smartyBC->fetch('eval:{testcompilerfunction var=1}'));
|
||||
}
|
||||
|
||||
/**
|
||||
* test register->compilerFunction method for blocks
|
||||
*/
|
||||
public function testRegisterCompilerFunctionBlock()
|
||||
{
|
||||
$this->smartyBC->register_compiler_function('foo', 'mycompilerfunctionBCopen');
|
||||
$this->smartyBC->register_compiler_function('fooclose', 'mycompilerfunctionBCclose');
|
||||
$result = $this->smartyBC->fetch('eval:{foo} hallo {/foo}');
|
||||
$this->assertEquals('open tag hallo close tag', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* test register->compilerFunction method for static class
|
||||
*/
|
||||
public function testRegisterCompilerFunctionClass()
|
||||
{
|
||||
$this->smartyBC->register_compiler_function('testcompilerfunction', array('mycompilerfunctionBCclass', 'execute'));
|
||||
$this->assertEquals('hello world 2', $this->smartyBC->fetch('eval:{testcompilerfunction var1=2}'));
|
||||
}
|
||||
|
||||
/**
|
||||
* test register->compilerFunction method for objects
|
||||
*/
|
||||
public function testRegisterCompilerFunctionObject()
|
||||
{
|
||||
$obj = new mycompilerfunctionBCclass;
|
||||
$this->smartyBC->register_compiler_function('testcompilerfunction', array($obj, 'compile'));
|
||||
$this->assertEquals('hello world 3', $this->smartyBC->fetch('eval:{testcompilerfunction var2=3}'));
|
||||
}
|
||||
|
||||
/**
|
||||
* test unregister->compilerFunction method
|
||||
*/
|
||||
public function testUnregisterCompilerFunction()
|
||||
{
|
||||
$this->smartyBC->register_compiler_function('testcompilerfunction', 'mycompilerfunctionBC');
|
||||
$this->smartyBC->unregister_compiler_function('testcompilerfunction');
|
||||
$this->assertFalse(isset($this->smartyBC->registered_plugins[Smarty::PLUGIN_COMPILER]['testcompilerfunction']));
|
||||
}
|
||||
|
||||
/**
|
||||
* test unregister->compilerFunction method not registered
|
||||
*/
|
||||
public function testUnregisterCompilerFunctionNotRegistered()
|
||||
{
|
||||
$this->smartyBC->unregister_compiler_function('testcompilerfunction');
|
||||
$this->assertFalse(isset($this->smartyBC->registered_plugins[Smarty::PLUGIN_COMPILER]['testcompilerfunction']));
|
||||
}
|
||||
|
||||
/**
|
||||
* test unregister->compilerFunction method other registered
|
||||
*/
|
||||
public function testUnregisterCompilerFunctionOtherRegistered()
|
||||
{
|
||||
$this->smartyBC->register_block('testcompilerfunction', 'mycompilerfunctionBC');
|
||||
$this->smartyBC->unregister_compiler_function('testcompilerfunction');
|
||||
$this->assertTrue(isset($this->smartyBC->registered_plugins[Smarty::PLUGIN_BLOCK]['testcompilerfunction']));
|
||||
}
|
||||
}
|
||||
|
||||
function mycompilerfunctionBC($params, $smarty)
|
||||
{
|
||||
return "<?php echo 'hello world {$params['var']}';?>";
|
||||
}
|
||||
|
||||
function mycompilerfunctionBCopen($params, $smarty)
|
||||
{
|
||||
return "<?php echo 'open tag';?>";
|
||||
}
|
||||
|
||||
function mycompilerfunctionBCclose($params, $smarty)
|
||||
{
|
||||
return "<?php echo 'close tag';?>";
|
||||
}
|
||||
|
||||
class mycompilerfunctionBCclass
|
||||
{
|
||||
static function execute($params, $smarty)
|
||||
{
|
||||
return "<?php echo 'hello world {$params['var1']}';?>";
|
||||
}
|
||||
|
||||
public function compile($params, $smarty)
|
||||
{
|
||||
return "<?php echo 'hello world {$params['var2']}';?>";
|
||||
}
|
||||
}
|
@@ -1,173 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Smarty PHPunit tests register/unregister function plugins
|
||||
*
|
||||
* @package PHPunit
|
||||
* @author Uwe Tews
|
||||
*/
|
||||
|
||||
/**
|
||||
* class for register/unregister function plugins methods tests
|
||||
*
|
||||
* @runTestsInSeparateProcess
|
||||
* @preserveGlobalState disabled
|
||||
* @backupStaticAttributes enabled
|
||||
*
|
||||
*/
|
||||
class RegisterFunctionBCTest extends PHPUnit_Smarty
|
||||
{
|
||||
public $loadSmartyBC = true;
|
||||
|
||||
public $loadSmarty = false;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->setUpSmarty(dirname(__FILE__));
|
||||
}
|
||||
|
||||
public function testInit()
|
||||
{
|
||||
$this->cleanDirs();
|
||||
}
|
||||
|
||||
/**
|
||||
* test registerPlugin method for function
|
||||
*/
|
||||
public function testRegisterFunction()
|
||||
{
|
||||
$this->smartyBC->register_function('testfunction', 'myfunctionBC');
|
||||
$this->assertEquals('myfunctionBC',
|
||||
$this->smartyBC->registered_plugins[ Smarty::PLUGIN_FUNCTION ][ 'testfunction' ][ 0 ]);
|
||||
$this->assertEquals('hello world 1', $this->smartyBC->fetch('eval:{testfunction value=1}'));
|
||||
}
|
||||
|
||||
/**
|
||||
* test registerPlugin method for function class
|
||||
*/
|
||||
public function testRegisterFunctionClass()
|
||||
{
|
||||
$this->smartyBC->register_function('testfunction', array('myfunctionBCclass', 'execute'));
|
||||
$this->assertEquals('hello world 2', $this->smartyBC->fetch('eval:{testfunction value=2}'));
|
||||
}
|
||||
|
||||
/**
|
||||
* test registerPlugin method for function object
|
||||
*/
|
||||
public function testRegisterFunctionObject()
|
||||
{
|
||||
$myfunctionBC_object = new myfunctionBCclass;
|
||||
$this->smartyBC->register_function('testfunction', array($myfunctionBC_object, 'execute'));
|
||||
$this->assertEquals('hello world 3', $this->smartyBC->fetch('eval:{testfunction value=3}'));
|
||||
}
|
||||
|
||||
/**
|
||||
* test registerPlugin method for function cached
|
||||
*
|
||||
* @runInSeparateProcess
|
||||
* @preserveGlobalState disabled
|
||||
*/
|
||||
public function testRegisterFunctionCaching1()
|
||||
{
|
||||
$this->smartyBC->caching = 1;
|
||||
$this->smartyBC->cache_lifetime = 1000;
|
||||
$this->smartyBC->setForceCompile(true);
|
||||
$this->smartyBC->assign('x', 0);
|
||||
$this->smartyBC->assign('y', 10);
|
||||
$this->smartyBC->register_function('testfunction', 'myfunctionBC');
|
||||
$this->assertEquals('hello world 0 10', $this->smartyBC->fetch('test_register_function.tpl'));
|
||||
}
|
||||
|
||||
/**
|
||||
* test registerPlugin method for function cached
|
||||
*
|
||||
* @runInSeparateProcess
|
||||
* @preserveGlobalState disabled
|
||||
*
|
||||
*/
|
||||
public function testRegisterFunctionCaching2()
|
||||
{
|
||||
$this->smartyBC->caching = 1;
|
||||
$this->smartyBC->cache_lifetime = 1000;
|
||||
$this->smartyBC->assign('x', 1);
|
||||
$this->smartyBC->assign('y', 20);
|
||||
$this->smartyBC->register_function('testfunction', 'myfunctionBC');
|
||||
$this->assertEquals('hello world 0 10', $this->smartyBC->fetch('test_register_function.tpl'));
|
||||
}
|
||||
|
||||
/**
|
||||
* test registerPlugin method for function not cached
|
||||
*
|
||||
* @runInSeparateProcess
|
||||
* @preserveGlobalState disabled
|
||||
*
|
||||
*/
|
||||
public function testRegisterFunctionCaching3()
|
||||
{
|
||||
$this->smartyBC->caching = 1;
|
||||
$this->smartyBC->cache_lifetime = 1000;
|
||||
$this->smartyBC->setForceCompile(true);
|
||||
$this->smartyBC->assign('x', 2);
|
||||
$this->smartyBC->assign('y', 30);
|
||||
$this->smartyBC->register_function('testfunction', 'myfunctionBC', false);
|
||||
$this->assertEquals('hello world 2 30', $this->smartyBC->fetch('test_register_function.tpl'));
|
||||
}
|
||||
|
||||
/**
|
||||
* test registerPlugin method for function not cached
|
||||
*
|
||||
* @runInSeparateProcess
|
||||
* @preserveGlobalState disabled
|
||||
*
|
||||
*/
|
||||
public function testRegisterFunctionCaching4()
|
||||
{
|
||||
$this->smartyBC->caching = 1;
|
||||
$this->smartyBC->cache_lifetime = 1000;
|
||||
$this->smartyBC->assign('x', 3);
|
||||
$this->smartyBC->assign('y', 40);
|
||||
$this->smartyBC->register_function('testfunction', 'myfunctionBC', false);
|
||||
$this->assertEquals('hello world 3 30', $this->smartyBC->fetch('test_register_function.tpl'));
|
||||
}
|
||||
|
||||
/**
|
||||
* test unregisterPlugin method for function
|
||||
*/
|
||||
public function testUnregisterFunction()
|
||||
{
|
||||
$this->smartyBC->register_function('testfunction', 'myfunctionBC');
|
||||
$this->smartyBC->unregister_function('testfunction');
|
||||
$this->assertFalse(isset($this->smartyBC->registered_plugins[ Smarty::PLUGIN_FUNCTION ][ 'testfunction' ]));
|
||||
}
|
||||
|
||||
/**
|
||||
* test test unregisterPlugin method for function not registered
|
||||
*/
|
||||
public function testUnregisterfunctionotRegistered()
|
||||
{
|
||||
$this->smartyBC->unregister_function('testfunction');
|
||||
$this->assertFalse(isset($this->smartyBC->registered_plugins[ Smarty::PLUGIN_FUNCTION ][ 'testfunction' ]));
|
||||
}
|
||||
|
||||
/**
|
||||
* test test unregisterPlugin method for function other registered
|
||||
*/
|
||||
public function testUnregisterFunctionOtherRegistered()
|
||||
{
|
||||
$this->smartyBC->register_block('testfunction', 'myfunctionBC');
|
||||
$this->smartyBC->unregister_function('testfunction');
|
||||
$this->assertTrue(isset($this->smartyBC->registered_plugins[ Smarty::PLUGIN_BLOCK ][ 'testfunction' ]));
|
||||
}
|
||||
}
|
||||
|
||||
function myfunctionBC($params, $smarty)
|
||||
{
|
||||
return "hello world $params[value]";
|
||||
}
|
||||
|
||||
class myfunctionBCclass
|
||||
{
|
||||
static function execute($params, $smarty)
|
||||
{
|
||||
return "hello world $params[value]";
|
||||
}
|
||||
}
|
@@ -1,74 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Smarty PHPunit tests compilation of the {include_php} tag
|
||||
*
|
||||
* @package PHPunit
|
||||
* @author Uwe Tews
|
||||
*/
|
||||
|
||||
/**
|
||||
* class for {include_php} tests
|
||||
*
|
||||
* @runTestsInSeparateProcess
|
||||
* @preserveGlobalState disabled
|
||||
* @backupStaticAttributes enabled
|
||||
*/
|
||||
class CompileIncludePhpTest extends PHPUnit_Smarty
|
||||
{
|
||||
public $loadSmartyBC = true;
|
||||
public $loadSmarty = false;
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->setUpSmarty(dirname(__FILE__));
|
||||
$this->smartyBC->setForceCompile(true);
|
||||
}
|
||||
|
||||
|
||||
public function testInit()
|
||||
{
|
||||
$this->cleanDirs();
|
||||
}
|
||||
/**
|
||||
* test include_php string file_name function
|
||||
*/
|
||||
public function testIncludePhpStringFileName()
|
||||
{
|
||||
$this->smartyBC->disableSecurity();
|
||||
$tpl = $this->smartyBC->createTemplate('include_php.tpl');
|
||||
$result = $this->smartyBC->fetch($tpl);
|
||||
$this->assertStringContainsString("test include php", $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* test include_php from trusted dir
|
||||
*/
|
||||
public function testIncludePhpTrusted()
|
||||
{
|
||||
$this->smartyBC->enableSecurity();
|
||||
$this->smartyBC->security_policy->trusted_dir = '.\\scripts\\';
|
||||
$tpl = $this->smartyBC->createTemplate('include_php_trusted.tpl');
|
||||
$result = $this->smartyBC->fetch($tpl);
|
||||
$this->assertStringContainsString("test include php", $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* test include_php string file_name function
|
||||
*/
|
||||
public function testIncludePhpVariableFileName()
|
||||
{
|
||||
$this->smartyBC->disableSecurity();
|
||||
$tpl = $this->smartyBC->createTemplate('string:start {include_php file=$filename once=false} end');
|
||||
$tpl->assign('filename', 'scripts/test_include_php.php');
|
||||
$result = $this->smartyBC->fetch($tpl);
|
||||
$this->assertStringContainsString("test include php", $result);
|
||||
}
|
||||
|
||||
public function testIncludePhpVariableFileNameShortag()
|
||||
{
|
||||
$this->smartyBC->disableSecurity();
|
||||
$tpl = $this->smartyBC->createTemplate('string:start {include_php $filename once=false} end');
|
||||
$tpl->assign('filename', 'scripts/test_include_php.php');
|
||||
$result = $this->smartyBC->fetch($tpl);
|
||||
$this->assertStringContainsString("test include php", $result);
|
||||
}
|
||||
}
|
@@ -1,2 +0,0 @@
|
||||
# Ignore anything in here, but keep this directory
|
||||
*
|
@@ -1,2 +0,0 @@
|
||||
<?php
|
||||
echo 'test include php';
|
@@ -1 +0,0 @@
|
||||
start {include_php file='scripts/test_include_php.php'} end
|
@@ -1 +0,0 @@
|
||||
start {include_php file='test_include_php.php' once=false} end
|
@@ -1,2 +0,0 @@
|
||||
# Ignore anything in here, but keep this directory
|
||||
*
|
@@ -1,184 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Smarty PHPunit tests compilation of {php} and <?php...?> tag
|
||||
*
|
||||
* @package PHPunit
|
||||
* @author Uwe Tews
|
||||
*/
|
||||
|
||||
/**
|
||||
* class for {php} and <?php...?> tag tests
|
||||
*
|
||||
* @runTestsInSeparateProcess
|
||||
* @preserveGlobalState disabled
|
||||
* @backupStaticAttributes enabled
|
||||
*/
|
||||
class CompilePhpTest extends PHPUnit_Smarty
|
||||
{
|
||||
public $loadSmartyBC = true;
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->setUpSmarty(dirname(__FILE__));
|
||||
$this->smarty->setUseSubDirs(true);
|
||||
$this->smartyBC->setUseSubDirs(true);
|
||||
$this->smartyBC->disableSecurity();
|
||||
$this->smarty->disableSecurity();
|
||||
$this->smarty->setCompileId($this->getName());
|
||||
$this->smartyBC->setCompileId($this->getName());
|
||||
}
|
||||
|
||||
public function testInit()
|
||||
{
|
||||
$this->cleanDirs();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test
|
||||
* @run InSeparateProcess
|
||||
* @preserveGlobalState disabled
|
||||
* @dataProvider data
|
||||
*
|
||||
*/
|
||||
public function testPHP($phpHandling, $templateFile, $result, $testName)
|
||||
{
|
||||
$result = str_replace("\r", '', $result);
|
||||
$this->smartyBC->force_compile = true;
|
||||
$this->smartyBC->php_handling = $phpHandling;
|
||||
$this->smartyBC->compile_id = $testName.$this->smartyBC->php_handling ;
|
||||
$tpl = $this->smartyBC->createTemplate($templateFile);
|
||||
if ($phpHandling == Smarty::PHP_PASSTHRU || $phpHandling == Smarty::PHP_QUOTE) {
|
||||
$result = str_replace("\r", '', $tpl->source->getContent());
|
||||
}
|
||||
if ($phpHandling == Smarty::PHP_QUOTE) {
|
||||
$result = preg_replace_callback('#(<\?(?:php|=)?)|(<%)|(<script\s+language\s*=\s*["\']?\s*php\s*["\']?\s*>)|(\?>)|(%>)|(<\/script>)#i', array($this, 'quote'), $result);
|
||||
}
|
||||
$content = $tpl->fetch();
|
||||
$this->assertEquals($result, $content, $testName);
|
||||
} /**
|
||||
* Test
|
||||
* @runInSeparateProcess
|
||||
* @preserveGlobalState disabled
|
||||
* @dataProvider data
|
||||
*
|
||||
*/
|
||||
public function testPHPcaching($phpHandling, $templateFile, $result, $testName)
|
||||
{
|
||||
$result = str_replace("\r", '', $result);
|
||||
$this->smartyBC->php_handling = $phpHandling;
|
||||
$this->smartyBC->compile_id = $testName.$this->smartyBC->php_handling ;
|
||||
$this->smartyBC->caching = true;
|
||||
$this->smartyBC->force_cache = true;
|
||||
$tpl = $this->smartyBC->createTemplate($templateFile);
|
||||
if ($phpHandling == Smarty::PHP_PASSTHRU || $phpHandling == Smarty::PHP_QUOTE) {
|
||||
$result = str_replace("\r", '', $tpl->source->getContent());
|
||||
}
|
||||
if ($phpHandling == Smarty::PHP_QUOTE) {
|
||||
$result = preg_replace_callback('#(<\?(?:php|=)?)|(<%)|(<script\s+language\s*=\s*["\']?\s*php\s*["\']?\s*>)|(\?>)|(%>)|(<\/script>)#i', array($this, 'quote'), $result);
|
||||
}
|
||||
$content = $tpl->fetch();
|
||||
$this->assertEquals($result, $content, $testName);
|
||||
}
|
||||
|
||||
public function testPHP_ALLOW_error()
|
||||
{
|
||||
$this->expectException('SmartyCompilerException');
|
||||
$this->expectExceptionMessage('$smarty->php_handling PHP_ALLOW not allowed. Use SmartyBC to enable it');
|
||||
$this->smarty->setPhpHandling(Smarty::PHP_ALLOW);
|
||||
$content = $this->smarty->fetch("string:aa <?php echo 'hallo'; ?> ae");
|
||||
}
|
||||
|
||||
/**
|
||||
* test {php nocache}{/php} tag
|
||||
*/
|
||||
public function testPHP_Tag_Nocache1()
|
||||
{
|
||||
$this->smartyBC->caching = 1;
|
||||
$this->smartyBC->assign('foo', 'foo');
|
||||
$this->smartyBC->compile_id = 'Tag nocache' ;
|
||||
$content = $this->smartyBC->fetch('phptag_nocache.tpl');
|
||||
$this->assertEquals('-->foo<--', $content,'Tag nocache 1');
|
||||
}
|
||||
|
||||
public function testPHP_Tag_Nocache2()
|
||||
{
|
||||
$this->smartyBC->caching = 1;
|
||||
$this->smartyBC->assign('foo', 'bar');
|
||||
$this->smartyBC->compile_id = 'Tag nocache' ;
|
||||
$content = $this->smartyBC->fetch('phptag_nocache.tpl');
|
||||
$this->assertEquals('-->bar<--', $content,'Tag nocache 2');
|
||||
}
|
||||
/**
|
||||
* test {php no cache}illegal option
|
||||
*/
|
||||
public function testPHP_Tag_IllegalOption()
|
||||
{
|
||||
$this->expectException('SmartyCompilerException');
|
||||
$this->expectExceptionMessage('illegal value of option flag \'no cache\'');
|
||||
$this->smartyBC->fetch("string:aa {php no cache} echo 'hallo'; {/php} ae");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test regression that plugin names starting with 'php' do work
|
||||
*/
|
||||
public function testPHPfooPlugin()
|
||||
{
|
||||
$this->smarty->addPluginsDir("./PHPunitplugins/");
|
||||
$this->smartyBC->compile_id = 'Tag nocache' ;
|
||||
$this->assertEquals('phptest okay', $this->smarty->fetch('string:{phptest}'),'testPHPfooPlugin');
|
||||
}
|
||||
|
||||
public function data()
|
||||
{
|
||||
$shortTag = ini_get('short_open_tag') == 1;
|
||||
|
||||
$data = array(
|
||||
/*
|
||||
* php_handling
|
||||
* template file
|
||||
* result
|
||||
* text
|
||||
*/
|
||||
array(Smarty::PHP_REMOVE, 'php.tpl', '--><--', 'PHP_REMOVE, \'php.tpl\''),
|
||||
array(Smarty::PHP_PASSTHRU, 'php.tpl', '', 'PHP_PASSTHRU, \'php.tpl\''),
|
||||
array(Smarty::PHP_QUOTE, 'php.tpl', '', 'PHP_QUOTE, \'php.tpl\''),
|
||||
array(Smarty::PHP_ALLOW, 'php.tpl', '--> hello world <?php ?> <--', 'PHP_ALLOW, \'php.tpl\''),
|
||||
array(Smarty::PHP_REMOVE, 'php_line_comment.tpl', '--><--', 'PHP_REMOVE, \'php_line_comment.tpl\''),
|
||||
array(Smarty::PHP_PASSTHRU, 'php_line_comment.tpl', '', 'PHP_PASSTHRU, \'php_line_comment.tpl\''),
|
||||
array(Smarty::PHP_QUOTE, 'php_line_comment.tpl', '', 'PHP_QUOTE, \'php_line_comment.tpl\''),
|
||||
array(Smarty::PHP_ALLOW, 'php_line_comment.tpl', '--> hello world <?php ?> <--', 'PHP_ALLOW, \'php_line_comment.tpl\''),
|
||||
array(Smarty::PHP_REMOVE, 'php_block_comment.tpl', '--><--', 'PHP_REMOVE, \'php_block_comment.tpl\''),
|
||||
array(Smarty::PHP_PASSTHRU, 'php_block_comment.tpl', '', 'PHP_PASSTHRU, \'php_block_comment.tpl\''),
|
||||
array(Smarty::PHP_QUOTE, 'php_block_comment.tpl', '', 'PHP_QUOTE, \'php_block_comment.tpl\''),
|
||||
array(Smarty::PHP_ALLOW, 'php_block_comment.tpl', '--> hello world <?php ?> <--', 'PHP_ALLOW, \'php_block_comment.tpl\''),
|
||||
array(Smarty::PHP_REMOVE, 'php2.tpl', '--><--', 'PHP_REMOVE, \'php2.tpl\''),
|
||||
array(Smarty::PHP_PASSTHRU, 'php2.tpl', '', 'PHP_PASSTHRU, \'php2.tpl\''),
|
||||
array(Smarty::PHP_QUOTE, 'php2.tpl', '', 'PHP_QUOTE, \'php2.tpl\''),
|
||||
array(Smarty::PHP_ALLOW, 'php2.tpl', $shortTag || strpos(phpversion(), 'hhvm') !== false ? '--> hello world <? ?> <--' : '--><? echo \' hello world \';
|
||||
echo \'<? \';
|
||||
echo \'?> \';
|
||||
?><--', 'PHP_ALLOW, \'php2.tpl\''),
|
||||
array(Smarty::PHP_REMOVE, 'script.tpl', '<br><br>', 'PHP_REMOVE, \'script.tpl\''),
|
||||
array(Smarty::PHP_PASSTHRU, 'script.tpl', '', 'PHP_PASSTHRU, \'script.tpl\''),
|
||||
array(Smarty::PHP_QUOTE, 'script.tpl', '', 'PHP_QUOTE, \'script.tpl\''),
|
||||
array(Smarty::PHP_ALLOW, 'phptag.tpl', '--> hello world {php} {/php} <--', 'PHP_ALLOW, \'phptag.tpl\''),
|
||||
array(Smarty::PHP_ALLOW, 'phptag_line_comment.tpl', '--> hello world {php} {/php} <--', 'PHP_ALLOW, \'phptag_line_comment.tpl\''),
|
||||
array(Smarty::PHP_ALLOW, 'phptag_block_comment.tpl', '--> hello world {php} {/php} <--', 'PHP_ALLOW, \'phptag_block_comment.tpl\''),
|
||||
array(Smarty::PHP_ALLOW, 'phptag_literal.tpl', '-->{ php} echo \' hello world \';
|
||||
echo \'foo \';
|
||||
echo \'bar \';
|
||||
$foo = 3;
|
||||
{ /php}<--', 'PHP_ALLOW, \'phptag_literal.tpl\''),
|
||||
);
|
||||
return $data;
|
||||
}
|
||||
/*
|
||||
* Call back function for $php_handling = PHP_QUOTE
|
||||
*
|
||||
*/
|
||||
private function quote($match)
|
||||
{
|
||||
return htmlspecialchars($match[0], ENT_QUOTES);
|
||||
}
|
||||
|
||||
}
|
@@ -1,5 +0,0 @@
|
||||
<?php
|
||||
function smarty_function_phptest($params,$smarty)
|
||||
{
|
||||
return 'phptest okay';
|
||||
}
|
@@ -1,2 +0,0 @@
|
||||
# Ignore anything in here, but keep this directory
|
||||
*
|
@@ -1,5 +0,0 @@
|
||||
--><?php echo ' hello world ';
|
||||
echo '<?php ';
|
||||
echo '?> ';
|
||||
$foo = 3;
|
||||
?><--
|
@@ -1,4 +0,0 @@
|
||||
--><? echo ' hello world ';
|
||||
echo '<? ';
|
||||
echo '?> ';
|
||||
?><--
|
@@ -1,16 +0,0 @@
|
||||
--><?php echo ' hello world ';
|
||||
/*
|
||||
* comment <?php is okay
|
||||
*
|
||||
* comment <?php once again
|
||||
*/
|
||||
|
||||
echo '<?php ';
|
||||
|
||||
/*
|
||||
* other comment <% foo
|
||||
*/
|
||||
|
||||
echo '?> ';
|
||||
$foo = 3;
|
||||
?><--
|
@@ -1,12 +0,0 @@
|
||||
--><?php echo ' hello world ';
|
||||
// comment <?php is okay
|
||||
//
|
||||
// comment <?php once again
|
||||
|
||||
echo '<?php ';
|
||||
|
||||
// other comment <% foo
|
||||
|
||||
echo '?> ';
|
||||
$foo = 3;
|
||||
?><--
|
@@ -1,5 +0,0 @@
|
||||
-->{php} echo ' hello world ';
|
||||
echo '{php} ';
|
||||
echo '{/php} ';
|
||||
$foo = 3;
|
||||
{/php}<--
|
@@ -1,16 +0,0 @@
|
||||
-->{php} echo ' hello world ';
|
||||
/*
|
||||
* comment {/php} is okay
|
||||
*
|
||||
* comment {/php} once again {/php} foo
|
||||
*/
|
||||
|
||||
echo '{php} ';
|
||||
|
||||
/*
|
||||
* other comment <% foo
|
||||
*/
|
||||
|
||||
echo '{/php} ';
|
||||
$foo = 3;
|
||||
{/php}<--
|
@@ -1,12 +0,0 @@
|
||||
-->{php} echo ' hello world ';
|
||||
// comment {/php} is okay
|
||||
//
|
||||
// comment {/php} once again {/php} foo
|
||||
|
||||
echo '{php} ';
|
||||
|
||||
// other comment <% foo
|
||||
|
||||
echo '{/php} ';
|
||||
$foo = 3;
|
||||
{/php}<--
|
@@ -1,5 +0,0 @@
|
||||
-->{ php} echo ' hello world ';
|
||||
echo 'foo ';
|
||||
echo 'bar ';
|
||||
$foo = 3;
|
||||
{ /php}<--
|
@@ -1,2 +0,0 @@
|
||||
-->{php nocache} echo $_smarty_tpl->getTemplateVars('foo');
|
||||
{/php}<--
|
@@ -1 +0,0 @@
|
||||
<br><script language='php'>echo ' This is a script <br> ';echo 2+3;</script><br>
|
@@ -1,2 +0,0 @@
|
||||
# Ignore anything in here, but keep this directory
|
||||
*
|
@@ -37,23 +37,10 @@ class XmlTest extends PHPUnit_Smarty
|
||||
}
|
||||
|
||||
/**
|
||||
* test standard xml Smarty::PHP_QUOTE
|
||||
*/
|
||||
public function testXmlPhpQuote()
|
||||
{
|
||||
$this->smarty->compile_id = 'PHP_QUOTE';
|
||||
$this->smarty->security_policy->php_handling = Smarty::PHP_QUOTE;
|
||||
$tpl = $this->smarty->createTemplate('xml.tpl');
|
||||
$this->assertEquals('<?xml version="1.0" encoding="UTF-8"?>', $this->smarty->fetch($tpl));
|
||||
}
|
||||
|
||||
/**
|
||||
* test standard xml Smarty::PHP_ALLOW
|
||||
* test standard xml
|
||||
*/
|
||||
public function testXmlPhpAllow()
|
||||
{
|
||||
$this->smarty->compile_id = 'PHP_ALLOW';
|
||||
$this->smarty->security_policy->php_handling = Smarty::PHP_ALLOW;
|
||||
$tpl = $this->smarty->createTemplate('xml.tpl');
|
||||
$this->assertEquals('<?xml version="1.0" encoding="UTF-8"?>', $this->smarty->fetch($tpl));
|
||||
}
|
||||
@@ -63,7 +50,6 @@ class XmlTest extends PHPUnit_Smarty
|
||||
*/
|
||||
public function testXmlCaching()
|
||||
{
|
||||
$this->smarty->security_policy->php_handling = Smarty::PHP_PASSTHRU;
|
||||
$this->smarty->caching = true;
|
||||
$this->smarty->cache_lifetime = 1000;
|
||||
$content = $this->smarty->fetch('xml.tpl');
|
||||
@@ -74,38 +60,13 @@ class XmlTest extends PHPUnit_Smarty
|
||||
*/
|
||||
public function testXmlCaching2()
|
||||
{
|
||||
$this->smarty->security_policy->php_handling = Smarty::PHP_PASSTHRU;
|
||||
$this->smarty->caching = true;
|
||||
$this->smarty->cache_lifetime = 1000;
|
||||
$content = $this->smarty->fetch('xml_main.tpl');
|
||||
$this->assertEquals('<?xml version="1.0" encoding="UTF-8"?>', $content);
|
||||
}
|
||||
|
||||
/**
|
||||
* test xml caching PhpQuote
|
||||
*/
|
||||
public function testXmlCachingPhpQuote()
|
||||
{
|
||||
$this->smarty->compile_id = 'PHP_QUOTE';
|
||||
$this->smarty->security_policy->php_handling = Smarty::PHP_QUOTE;
|
||||
$this->smarty->caching = true;
|
||||
$this->smarty->cache_lifetime = 1000;
|
||||
$content = $this->smarty->fetch('xml.tpl');
|
||||
$this->assertEquals('<?xml version="1.0" encoding="UTF-8"?>', $content);
|
||||
}
|
||||
|
||||
/**
|
||||
* test xml caching PhpAllow
|
||||
*/
|
||||
public function testXmlCachingPhpAllow()
|
||||
{
|
||||
$this->smarty->compile_id = 'PHP_ALLOW';
|
||||
$this->smarty->security_policy->php_handling = Smarty::PHP_ALLOW;
|
||||
$this->smarty->caching = true;
|
||||
$this->smarty->cache_lifetime = 1000;
|
||||
$content = $this->smarty->fetch('xml.tpl');
|
||||
$this->assertEquals('<?xml version="1.0" encoding="UTF-8"?>', $content);
|
||||
}
|
||||
/**
|
||||
* test xml with variable
|
||||
*/
|
||||
|
Reference in New Issue
Block a user