mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-05 02:44:27 +02:00
break down regex to digestable chunks, fix multiple param problem with method calls,
add object method testing to unit_test cases
This commit is contained in:
@@ -151,11 +151,13 @@ class Smarty_Compiler extends Smarty {
|
||||
// $foo->bar($foo->bar())
|
||||
// $foo->bar($foo->bar($blah,$foo,44,"foo",$foo[0].bar))
|
||||
$this->_obj_ext_regexp = '\->(?:\$?' . $this->_dvar_guts_regexp . ')';
|
||||
$this->_obj_params_regexp = '\((?:\w+|(?:'
|
||||
$this->_obj_restricted_param_regexp = '(?:'
|
||||
. $this->_var_regexp . '(?:' . $this->_obj_ext_regexp . '(?:\((?:' . $this->_var_regexp
|
||||
. '(?:\s*,\s*' . $this->_var_regexp . ')*)?\))?)*)(?:\s*,\s*(?:(?:\w+|'
|
||||
. $this->_var_regexp . '(?:' . $this->_obj_ext_regexp . '(?:\((?:' . $this->_var_regexp
|
||||
. '(?:\s*,\s*' . $this->_var_regexp . ')*)?\))?))))*)?\)';
|
||||
. '(?:\s*,\s*' . $this->_var_regexp . ')*)?\))?)*)';
|
||||
$this->_obj_single_param_regexp = '(?:\w+|' . $this->_obj_restricted_param_regexp . '(?:\s*,\s*(?:(?:\w+|'
|
||||
. $this->_var_regexp . $this->_obj_restricted_param_regexp . ')))*)';
|
||||
$this->_obj_params_regexp = '\((?:' . $this->_obj_single_param_regexp
|
||||
. '(?:\s*,\s*' . $this->_obj_single_param_regexp . ')*)?\)';
|
||||
$this->_obj_start_regexp = '(?:' . $this->_dvar_regexp . '(?:' . $this->_obj_ext_regexp . ')+)';
|
||||
$this->_obj_call_regexp = '(?:' . $this->_obj_start_regexp . '(?:' . $this->_obj_params_regexp . ')?)';
|
||||
|
||||
|
@@ -4,6 +4,16 @@ require_once './config.php';
|
||||
require_once SMARTY_DIR . 'Smarty.class.php';
|
||||
require_once 'PHPUnit.php';
|
||||
|
||||
class Obj {
|
||||
var $val = 'val';
|
||||
var $arr = array('one' => 'one');
|
||||
|
||||
function meth($a="a", $b="b") {
|
||||
return "$a:$b";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class SmartyTest extends PHPUnit_TestCase {
|
||||
// contains the object handle of the string class
|
||||
var $abc;
|
||||
@@ -231,6 +241,22 @@ class SmartyTest extends PHPUnit_TestCase {
|
||||
$this->assertEquals($this->smarty->fetch('assign_var.tpl'), 'bar');
|
||||
}
|
||||
|
||||
// test assigning and calling an object
|
||||
function test_obj_meth() {
|
||||
$obj = new Obj();
|
||||
$this->smarty->assign('obj', $obj);
|
||||
$this->smarty->assign('foo', 'foo');
|
||||
$this->assertEquals(
|
||||
'foo:2.5
|
||||
2.5:foo
|
||||
2.5:b
|
||||
val:foo
|
||||
foo:val
|
||||
foo:foo
|
||||
one:2
|
||||
foo:foo:b', $this->smarty->fetch('assign_obj.tpl'));
|
||||
}
|
||||
|
||||
/* CONFIG FILE TESTS */
|
||||
|
||||
// test assigning a double quoted global variable
|
||||
|
Reference in New Issue
Block a user