mirror of
https://github.com/smarty-php/smarty.git
synced 2026-05-03 19:30:49 +02:00
Feature/merge smarty-phpunit into tests subfolder (#580)
* 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>
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
/**
|
||||
* Smarty plugin for testing scopes
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage PHPunitPlugin
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smarty {checkvar}
|
||||
*
|
||||
* @param array $params parameter array
|
||||
* @param object $template template object
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function smarty_function_checkvar($params, $template)
|
||||
{
|
||||
$output = '';
|
||||
$types = array('template', 'data', 'smarty', 'global');
|
||||
if (isset($params['types'])) {
|
||||
$types = (array)$params['types'];
|
||||
}
|
||||
$var = $params['var'];
|
||||
$ptr = $template;
|
||||
while ($ptr) {
|
||||
if (in_array('template', $types) && $ptr instanceof Smarty_Internal_Template) {
|
||||
$output .= "#{$ptr->source->name}:\${$var} =";
|
||||
$output .= isset($ptr->tpl_vars[$var]) ? preg_replace('/\s/', '', var_export($ptr->tpl_vars[$var]->value, true)) : '>unassigned<';
|
||||
$i = 0;
|
||||
while (isset($ptr->_cache[ 'varStack' ][ $i ])) {
|
||||
$output .= "#{$ptr->_cache[ 'varStack' ][ $i ]['name']} = ";
|
||||
$output .= isset($ptr->_cache[ 'varStack' ][ $i ][ 'tpl' ][$var]) ? preg_replace('/\s/', '', var_export($ptr->_cache[ 'varStack' ][ $i ][ 'tpl' ][$var]->value, true)) : '>unassigned<';
|
||||
$i ++;
|
||||
}
|
||||
$ptr = $ptr->parent;
|
||||
} elseif (in_array('data', $types) && $ptr instanceof Smarty_Data) {
|
||||
$output .= "#data:\${$var} =";
|
||||
$output .= isset($ptr->tpl_vars[$var]) ? preg_replace('/\s/', '', var_export($ptr->tpl_vars[$var]->value, true)) : '>unassigned<';
|
||||
$ptr = $ptr->parent;
|
||||
} else {
|
||||
$ptr = null;
|
||||
}
|
||||
}
|
||||
if (in_array('smarty', $types)) {
|
||||
$output .= "#Smarty:\${$var} =";
|
||||
$output .= isset($template->smarty->tpl_vars[ $var ]) ?
|
||||
preg_replace('/\s/', '', var_export($template->smarty->tpl_vars[ $var ]->value, true)) : '>unassigned<';
|
||||
}
|
||||
if (in_array('global', $types)) {
|
||||
$output .= "#global:\${$var} =";
|
||||
$output .= isset(Smarty::$global_tpl_vars[ $var ]) ?
|
||||
preg_replace('/\s/', '', var_export(Smarty::$global_tpl_vars[ $var ]->value, true)) : '>unassigned<';
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
Reference in New Issue
Block a user