2013-01-25 18:36:16 +04:00
|
|
|
<?php
|
2013-06-28 11:53:53 +04:00
|
|
|
namespace Fenom;
|
2014-02-27 16:30:44 +04:00
|
|
|
|
2013-06-28 11:53:53 +04:00
|
|
|
use Fenom\Template,
|
|
|
|
Fenom,
|
|
|
|
Fenom\Render;
|
2013-01-25 18:36:16 +04:00
|
|
|
|
2013-05-30 19:00:00 +04:00
|
|
|
/**
|
|
|
|
* Test template parsing
|
|
|
|
*
|
2013-06-28 11:53:53 +04:00
|
|
|
* @package Fenom
|
2013-05-30 19:00:00 +04:00
|
|
|
*/
|
2013-07-29 14:58:14 +04:00
|
|
|
class TemplateTest extends TestCase
|
|
|
|
{
|
2013-01-25 18:36:16 +04:00
|
|
|
|
2013-07-29 14:58:14 +04:00
|
|
|
public function setUp()
|
|
|
|
{
|
2013-07-22 18:03:43 +04:00
|
|
|
parent::setUp();
|
|
|
|
$this->tpl('welcome.tpl', '<b>Welcome, {$username} ({$email})</b>');
|
2014-05-06 14:22:58 +04:00
|
|
|
$_GET['one'] = 'get1';
|
|
|
|
$_POST['one'] = 'post1';
|
2013-08-11 19:55:30 +04:00
|
|
|
$_REQUEST['one'] = 'request1';
|
2014-05-06 14:22:58 +04:00
|
|
|
$_FILES['one'] = 'files1';
|
|
|
|
$_SERVER['one'] = 'server1';
|
2013-08-11 19:55:30 +04:00
|
|
|
$_SESSION['one'] = 'session1';
|
2014-05-06 14:22:58 +04:00
|
|
|
$GLOBALS['one'] = 'globals1';
|
|
|
|
$_ENV['one'] = 'env1';
|
|
|
|
$_COOKIE['one'] = 'cookie1';
|
2013-07-22 18:03:43 +04:00
|
|
|
}
|
|
|
|
|
2013-07-29 14:58:14 +04:00
|
|
|
public static function providerVars()
|
|
|
|
{
|
2014-05-06 14:22:58 +04:00
|
|
|
$a = array("a" => "World");
|
|
|
|
$obj = new \stdClass;
|
2013-01-25 18:36:16 +04:00
|
|
|
$obj->name = "Object";
|
2013-07-22 18:03:43 +04:00
|
|
|
$obj->list = $a;
|
2014-05-06 14:22:58 +04:00
|
|
|
$obj->c = "c";
|
2013-12-01 19:30:09 +04:00
|
|
|
// $world = new
|
|
|
|
$b = array(
|
2014-05-06 14:22:58 +04:00
|
|
|
"b" => array(
|
|
|
|
"c" => "Username",
|
2013-12-01 19:30:09 +04:00
|
|
|
"c_char" => "c",
|
2014-05-06 14:22:58 +04:00
|
|
|
"mcp" => "Master",
|
2013-12-01 19:30:09 +04:00
|
|
|
'm{$c}p' => "Unknown",
|
2014-05-06 14:22:58 +04:00
|
|
|
'obj' => $obj
|
2013-12-01 19:30:09 +04:00
|
|
|
),
|
2014-05-06 14:22:58 +04:00
|
|
|
"c" => "c",
|
2013-12-01 19:30:09 +04:00
|
|
|
"world" => new Helper('world')
|
|
|
|
);
|
2013-01-25 18:36:16 +04:00
|
|
|
$c = array_replace_recursive($b, array("b" => array(3 => $b["b"], 4 => "Mister")));
|
|
|
|
return array(
|
2013-07-29 14:58:14 +04:00
|
|
|
array('hello, {$a}!', $a, 'hello, World!'),
|
|
|
|
array('hello, {$b.c}!', $b, 'hello, Username!'),
|
|
|
|
array('hello, {$b."c"}!', $b, 'hello, Username!'),
|
|
|
|
array('hello, {$b.\'c\'}!', $b, 'hello, Username!'),
|
|
|
|
array('hello, {$b[c]}!', $b, 'hello, Username!'),
|
|
|
|
array('hello, {$b["c"]}!', $b, 'hello, Username!'),
|
|
|
|
array('hello, {$b[\'c\']}!', $b, 'hello, Username!'),
|
|
|
|
array('hello, {$b[ $b.c_char ]}!', $b, 'hello, Username!'),
|
|
|
|
array('hello, {$b[ "$c" ]}!', $b, 'hello, Username!'),
|
|
|
|
array('hello, {$b.$c}!', $b, 'hello, Username!'),
|
|
|
|
array('hello, {$b."$c"}!', $b, 'hello, Username!'),
|
|
|
|
array('hello, {$b."{$c}"}!', $b, 'hello, Username!'),
|
|
|
|
array('hello, {$b[ "{$c}" ]}!', $b, 'hello, Username!'),
|
2014-05-12 00:36:50 +04:00
|
|
|
array('hello, {$b[ ("{$c}") ]}!', $b, 'hello, Username!'),
|
2013-07-29 14:58:14 +04:00
|
|
|
array('hello, {$b[ "mcp" ]}!', $b, 'hello, Master!'),
|
|
|
|
array('hello, {$b[ "m{$c}p" ]}!', $b, 'hello, Master!'),
|
|
|
|
array('hello, {$b."m{$c}p"}!', $b, 'hello, Master!'),
|
2014-05-06 14:22:58 +04:00
|
|
|
array(
|
|
|
|
'hello, {$b[ "m{$b.c_char}p" ]}!',
|
|
|
|
$b,
|
|
|
|
'hello, Master!'
|
|
|
|
),
|
2013-01-25 18:36:16 +04:00
|
|
|
array('hello, {$b[ \'m{$c}p\' ]}!', $b, 'hello, Unknown!'),
|
2013-07-29 14:58:14 +04:00
|
|
|
array('hello, {$b.4}!', $c, 'hello, Mister!'),
|
|
|
|
array('hello, {$b[4]}!', $c, 'hello, Mister!'),
|
|
|
|
array('hello, {$b.3.c}!', $c, 'hello, Username!'),
|
|
|
|
array('hello, {$b.3.$c}!', $c, 'hello, Username!'),
|
|
|
|
array('hello, {$b.3[$b.c_char]}!', $c, 'hello, Username!'),
|
|
|
|
array('hello, {$b[3].c}!', $c, 'hello, Username!'),
|
|
|
|
array('hello, {$b[2+1].c}!', $c, 'hello, Username!'),
|
2014-02-27 16:30:44 +04:00
|
|
|
array('hello, {$b[(2+1)].c}!', $c, 'hello, Username!'),
|
2013-07-29 14:58:14 +04:00
|
|
|
array('hello, {$b[9/3].c}!', $c, 'hello, Username!'),
|
|
|
|
array('hello, {$b[3].$c}!', $c, 'hello, Username!'),
|
2014-02-27 16:30:44 +04:00
|
|
|
array('hello, {$b[(3)].$c}!', $c, 'hello, Username!'),
|
2013-01-25 18:36:16 +04:00
|
|
|
array('hello, {$b[3][$b.c_char]}!', $c, 'hello, Username!'),
|
2014-05-06 14:22:58 +04:00
|
|
|
array(
|
|
|
|
'hello, {$b[ "m{$b.c_char}p" ]} and {$b.3[$b.c_char]}!',
|
|
|
|
$c,
|
|
|
|
'hello, Master and Username!'
|
|
|
|
),
|
2013-07-29 14:58:14 +04:00
|
|
|
array('hello, {$b.obj->name}!', $c, 'hello, Object!'),
|
|
|
|
array('hello, {$b.obj->list.a}!', $c, 'hello, World!'),
|
|
|
|
array('hello, {$b[obj]->name}!', $c, 'hello, Object!'),
|
|
|
|
array('hello, {$b["obj"]->name}!', $c, 'hello, Object!'),
|
|
|
|
array('hello, {$b."obj"->name}!', $c, 'hello, Object!'),
|
2014-05-06 14:22:58 +04:00
|
|
|
array(
|
|
|
|
'hello, {$b.obj->name|upper}!',
|
|
|
|
$c,
|
|
|
|
'hello, OBJECT!'
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'hello, {$b.obj->list.a|upper}!',
|
|
|
|
$c,
|
|
|
|
'hello, WORLD!'
|
|
|
|
),
|
2013-07-29 14:58:14 +04:00
|
|
|
array('hello, {$b[ $b.obj->c ]}!', $b, 'hello, Username!'),
|
2014-02-27 16:30:44 +04:00
|
|
|
array('hello, {$b[ ( $b.obj->c ) ]}!', $b, 'hello, Username!'),
|
2014-05-06 14:22:58 +04:00
|
|
|
array(
|
|
|
|
'hello, {$b[ "{$b.obj->c}" ]}!',
|
|
|
|
$b,
|
|
|
|
'hello, Username!'
|
|
|
|
),
|
2013-07-29 14:58:14 +04:00
|
|
|
array('hello, {"World"}!', $a, 'hello, World!'),
|
|
|
|
array('hello, {"W{$a}d"}!', $a, 'hello, WWorldd!'),
|
2013-12-01 19:30:09 +04:00
|
|
|
array('hello, {$world->chunk(1)->self->chunk("new")}!', $b, 'hello, world!'),
|
2013-01-25 18:36:16 +04:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2013-02-21 22:51:24 +04:00
|
|
|
|
2013-07-29 14:58:14 +04:00
|
|
|
public static function providerVarsInvalid()
|
|
|
|
{
|
2013-01-25 18:36:16 +04:00
|
|
|
return array(
|
2013-07-29 16:15:52 +04:00
|
|
|
array('hello, {$a.}!', 'Fenom\Error\CompileException', "Unexpected end of expression"),
|
2014-08-06 01:17:21 +04:00
|
|
|
array('hello, {$b[}!', 'Fenom\Error\CompileException', "Unexpected end of expression"),
|
|
|
|
array('hello, {$b.}!', 'Fenom\Error\CompileException', "Unexpected end of expression"),
|
2013-07-29 16:15:52 +04:00
|
|
|
array('hello, {$b[c}!', 'Fenom\Error\CompileException', "Unexpected end of expression"),
|
|
|
|
array('hello, {$b.c]}!', 'Fenom\Error\CompileException', "Unexpected token ']'"),
|
2014-08-06 01:17:21 +04:00
|
|
|
array('hello, {$b[ ]}!', 'Fenom\Error\CompileException', "Unexpected end of expression"),
|
2013-07-29 16:15:52 +04:00
|
|
|
array('hello, {$b[9/].c}!', 'Fenom\Error\CompileException', "Unexpected token ']'"),
|
|
|
|
array('hello, {$b[3]$c}!', 'Fenom\Error\CompileException', "Unexpected token '\$c'"),
|
|
|
|
array('hello, {$b[3]c}!', 'Fenom\Error\CompileException', "Unexpected token 'c'"),
|
2014-05-06 14:22:58 +04:00
|
|
|
array(
|
|
|
|
'hello, {$b.obj->valid()}!',
|
|
|
|
'Fenom\Error\SecurityException',
|
|
|
|
"Forbidden to call methods",
|
|
|
|
Fenom::DENY_METHODS
|
|
|
|
),
|
2013-01-25 18:36:16 +04:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2013-07-29 14:58:14 +04:00
|
|
|
public static function providerModifiers()
|
|
|
|
{
|
2013-01-25 18:36:16 +04:00
|
|
|
$b = array(
|
2014-05-06 14:22:58 +04:00
|
|
|
"a" => "World",
|
|
|
|
"b" => array(
|
2013-01-25 18:36:16 +04:00
|
|
|
"c" => "Username",
|
|
|
|
),
|
2014-05-06 14:22:58 +04:00
|
|
|
"c" => "c",
|
|
|
|
"lorem" => "Lorem ipsum dolor sit amet",
|
|
|
|
"next" => " next -->",
|
|
|
|
"rescue" => "Chip & Dale",
|
2013-07-29 14:58:14 +04:00
|
|
|
"rescue_html" => "Chip & Dale",
|
2014-05-06 14:22:58 +04:00
|
|
|
"rescue_url" => "Chip+%26+Dale",
|
|
|
|
"date" => "26-07-2012",
|
|
|
|
"time" => 1343323616,
|
|
|
|
"tags" => "my name is <b>Legion</b>"
|
2013-01-25 18:36:16 +04:00
|
|
|
);
|
|
|
|
return array(
|
2013-07-29 14:58:14 +04:00
|
|
|
array('hello, {$a|upper}!', $b, 'hello, WORLD!'),
|
|
|
|
array('hello, {$b.c|upper}!', $b, 'hello, USERNAME!'),
|
|
|
|
array('hello, {$b."c"|upper}!', $b, 'hello, USERNAME!'),
|
|
|
|
array('hello, {$b["C"|lower]|upper}!', $b, 'hello, USERNAME!'),
|
|
|
|
array('Mod: {$rescue|escape}!', $b, 'Mod: Chip & Dale!'),
|
|
|
|
array('Mod: {$rescue|escape:"html"}!', $b, 'Mod: Chip & Dale!'),
|
|
|
|
array('Mod: {$rescue|escape:"url"}!', $b, 'Mod: Chip+%26+Dale!'),
|
|
|
|
array('Mod: {$rescue|escape:"unknown"}!', $b, 'Mod: Chip & Dale!'),
|
2014-07-11 12:11:51 +04:00
|
|
|
array('Mod: {$rescue|escape:"js"}!', $b, 'Mod: "Chip & Dale"!'),
|
2013-07-29 14:58:14 +04:00
|
|
|
array('Mod: {$rescue_html|unescape}!', $b, 'Mod: Chip & Dale!'),
|
|
|
|
array('Mod: {$rescue_html|unescape:"html"}!', $b, 'Mod: Chip & Dale!'),
|
|
|
|
array('Mod: {$rescue_url|unescape:"url"}!', $b, 'Mod: Chip & Dale!'),
|
|
|
|
array('Mod: {$rescue|unescape:"unknown"}!', $b, 'Mod: Chip & Dale!'),
|
|
|
|
array('Mod: {$time|date_format:"%Y %m %d"}!', $b, 'Mod: 2012 07 26!'),
|
|
|
|
array('Mod: {$date|date_format:"%Y %m %d"}!', $b, 'Mod: 2012 07 26!'),
|
|
|
|
array('Mod: {$time|date:"Y m d"}!', $b, 'Mod: 2012 07 26!'),
|
|
|
|
array('Mod: {$date|date:"Y m d"}!', $b, 'Mod: 2012 07 26!'),
|
|
|
|
array('Mod: {$tags|strip_tags}!', $b, 'Mod: my name is Legion!'),
|
|
|
|
array('Mod: {$b.c|json_encode}!', $b, 'Mod: "Username"!'),
|
2013-09-02 17:40:58 +04:00
|
|
|
array('Mod: {($time/1024/1024)|round:2}!', $b, 'Mod: 1281.09!'),
|
2013-07-29 14:58:14 +04:00
|
|
|
array('Mod: {time()|date:"Y m d"}!', $b, 'Mod: ' . date("Y m d") . '!'),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function providerModifiersInvalid()
|
|
|
|
{
|
2013-01-25 18:36:16 +04:00
|
|
|
return array(
|
2013-07-29 16:15:52 +04:00
|
|
|
array('Mod: {$lorem|}!', 'Fenom\Error\CompileException', "Unexpected end of expression"),
|
2014-05-06 14:22:58 +04:00
|
|
|
array(
|
|
|
|
'Mod: {$lorem|str_rot13}!',
|
|
|
|
'Fenom\Error\CompileException',
|
|
|
|
"Modifier str_rot13 not found",
|
2014-05-08 12:56:37 +04:00
|
|
|
Fenom::DENY_NATIVE_FUNCS
|
2014-05-06 14:22:58 +04:00
|
|
|
),
|
2013-07-29 16:15:52 +04:00
|
|
|
array('Mod: {$lorem|my_encode}!', 'Fenom\Error\CompileException', "Modifier my_encode not found"),
|
|
|
|
array('Mod: {$lorem|truncate:}!', 'Fenom\Error\CompileException', "Unexpected end of expression"),
|
|
|
|
array('Mod: {$lorem|truncate:abs}!', 'Fenom\Error\CompileException', "Unexpected token 'abs'"),
|
|
|
|
array('Mod: {$lorem|truncate:80|}!', 'Fenom\Error\CompileException', "Unexpected end of expression"),
|
2013-01-25 18:36:16 +04:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2013-07-29 14:58:14 +04:00
|
|
|
public static function providerExpressions()
|
|
|
|
{
|
2013-01-25 18:36:16 +04:00
|
|
|
$b = array(
|
|
|
|
"x" => $x = 9,
|
|
|
|
"y" => 27,
|
|
|
|
"z" => 8.9,
|
|
|
|
"k" => array("i" => "")
|
|
|
|
);
|
|
|
|
return array(
|
2013-07-29 14:58:14 +04:00
|
|
|
array('Exp: {' . $x . '+$y} result', $b, 'Exp: 36 result'),
|
|
|
|
array('Exp: {$y/' . $x . '} result', $b, 'Exp: 3 result'),
|
|
|
|
array('Exp: {$y-' . $x . '} result', $b, 'Exp: 18 result'),
|
|
|
|
array('Exp: {' . $x . '*$y} result', $b, 'Exp: 243 result'),
|
|
|
|
array('Exp: {$y^' . $x . '} result', $b, 'Exp: 18 result'),
|
|
|
|
array('Exp: {$x+$y} result', $b, 'Exp: 36 result'),
|
|
|
|
array('Exp: {$y/$x} result', $b, 'Exp: 3 result'),
|
|
|
|
array('Exp: {$y-$x} result', $b, 'Exp: 18 result'),
|
|
|
|
array('Exp: {$y*$x} result', $b, 'Exp: 243 result'),
|
|
|
|
array('Exp: {$y^$x} result', $b, 'Exp: 18 result'),
|
|
|
|
array('Exp: {-($x)} result', $b, 'Exp: -9 result'),
|
|
|
|
array('Exp: {!$x} result', $b, 'Exp: result'),
|
|
|
|
array('Exp: {!($x)} result', $b, 'Exp: result'),
|
|
|
|
array('Exp: {!5} result', $b, 'Exp: result'),
|
|
|
|
array('Exp: {-1} result', $b, 'Exp: -1 result'),
|
|
|
|
array('Exp: {$z = 5} {$z} result', $b, 'Exp: 5 5 result'),
|
|
|
|
array('Exp: {$k.i = "str"} {$k.i} result', $b, 'Exp: str str result'),
|
2014-05-06 14:22:58 +04:00
|
|
|
array(
|
|
|
|
'Exp: {($y*$x - (($x+$y) + $y/$x) ^ $y)/4} result',
|
|
|
|
$b,
|
|
|
|
'Exp: 53.75 result'
|
|
|
|
),
|
2013-07-29 14:58:14 +04:00
|
|
|
array('Exp: {$x+max($x, $y)} result', $b, 'Exp: 36 result'),
|
|
|
|
array('Exp: {max(1,2)} result', $b, 'Exp: 2 result'),
|
|
|
|
array('Exp: {round(sin(pi()), 8)} result', $b, 'Exp: 0 result'),
|
2014-05-06 14:22:58 +04:00
|
|
|
array(
|
|
|
|
'Exp: {max($x, $y) + round(sin(pi()), 8) - min($x, $y) +3} result',
|
|
|
|
$b,
|
|
|
|
'Exp: 21 result'
|
|
|
|
),
|
2013-01-25 18:36:16 +04:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2013-07-29 14:58:14 +04:00
|
|
|
public static function providerExpressionsInvalid()
|
|
|
|
{
|
2013-01-25 18:36:16 +04:00
|
|
|
return array(
|
2013-07-29 16:15:52 +04:00
|
|
|
array('If: {-"hi"} end', 'Fenom\Error\CompileException', "Unexpected token '-'"),
|
2013-08-02 20:29:18 +04:00
|
|
|
array('If: {-[1,2]} end', 'Fenom\Error\CompileException', "Unexpected token '-'"),
|
2013-07-29 16:15:52 +04:00
|
|
|
array('If: {($a++)++} end', 'Fenom\Error\CompileException', "Unexpected token '++'"),
|
|
|
|
array('If: {$a + * $c} end', 'Fenom\Error\CompileException', "Unexpected token '*'"),
|
2013-08-02 20:29:18 +04:00
|
|
|
array('If: {$a + } end', 'Fenom\Error\CompileException', "Unexpected end of expression"),
|
2013-07-29 16:15:52 +04:00
|
|
|
array('If: {$a + =} end', 'Fenom\Error\CompileException', "Unexpected token '='"),
|
|
|
|
array('If: {$a + 1 =} end', 'Fenom\Error\CompileException', "Unexpected token '='"),
|
|
|
|
array('If: {$a + 1 = 6} end', 'Fenom\Error\CompileException', "Unexpected token '='"),
|
|
|
|
array('If: {/$a} end', 'Fenom\Error\CompileException', "Unexpected token '\$a'"),
|
|
|
|
array('If: {$a == 5 > 4} end', 'Fenom\Error\CompileException', "Unexpected token '>'"),
|
|
|
|
array('If: {$a != 5 <= 4} end', 'Fenom\Error\CompileException', "Unexpected token '<='"),
|
|
|
|
array('If: {$a != 5 => 4} end', 'Fenom\Error\CompileException', "Unexpected token '=>'"),
|
|
|
|
array('If: {$a + (*6)} end', 'Fenom\Error\CompileException', "Unexpected token '*'"),
|
|
|
|
array('If: {$a + ( 6} end', 'Fenom\Error\CompileException', "Unexpected end of expression, expect ')'"),
|
2013-09-15 16:05:18 +04:00
|
|
|
array('If: {$a end', 'Fenom\Error\CompileException', "Unclosed tag in line"),
|
2014-02-27 16:30:44 +04:00
|
|
|
array('If: {!!$a}', 'Fenom\Error\CompileException', "Unexpected token '!'"),
|
2013-07-29 14:58:14 +04:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function providerInclude()
|
|
|
|
{
|
2014-05-06 14:22:58 +04:00
|
|
|
$a = array(
|
|
|
|
"name" => "welcome",
|
|
|
|
"tpl" => "welcome.tpl",
|
|
|
|
"fragment" => "come",
|
2013-01-25 18:36:16 +04:00
|
|
|
"pr_fragment" => "Come",
|
2014-05-06 14:22:58 +04:00
|
|
|
"pr_name" => "Welcome",
|
|
|
|
"username" => "Master",
|
|
|
|
"email" => "dev@null.net"
|
2013-01-25 18:36:16 +04:00
|
|
|
);
|
2014-05-06 14:22:58 +04:00
|
|
|
$result = 'Include <b>Welcome, Master (dev@null.net)</b> template';
|
2013-01-25 18:36:16 +04:00
|
|
|
$result2 = 'Include <b>Welcome, Flame (dev@null.net)</b> template';
|
|
|
|
$result3 = 'Include <b>Welcome, Master (flame@dev.null)</b> template';
|
|
|
|
$result4 = 'Include <b>Welcome, Flame (flame@dev.null)</b> template';
|
|
|
|
return array(
|
2013-07-29 14:58:14 +04:00
|
|
|
array('Include {include "welcome.tpl"} template', $a, $result),
|
2013-09-14 11:24:23 +04:00
|
|
|
array('Include {include "welcome.tpl"} template', $a, $result, Fenom::FORCE_INCLUDE),
|
2013-07-29 14:58:14 +04:00
|
|
|
array('Include {include $tpl} template', $a, $result),
|
|
|
|
array('Include {include "$tpl"} template', $a, $result),
|
|
|
|
array('Include {include "{$tpl}"} template', $a, $result),
|
|
|
|
array('Include {include "$name.tpl"} template', $a, $result),
|
|
|
|
array('Include {include "{$name}.tpl"} template', $a, $result),
|
|
|
|
array('Include {include "{$pr_name|lower}.tpl"} template', $a, $result),
|
|
|
|
array('Include {include "wel{$fragment}.tpl"} template', $a, $result),
|
|
|
|
array('Include {include "wel{$pr_fragment|lower}.tpl"} template', $a, $result),
|
|
|
|
array('Include {include "welcome.tpl" username="Flame"} template', $a, $result2),
|
2013-09-14 11:24:23 +04:00
|
|
|
array('Include {include "welcome.tpl" username="Flame"} template', $a, $result2, Fenom::FORCE_INCLUDE),
|
2013-07-29 14:58:14 +04:00
|
|
|
array('Include {include "welcome.tpl" email="flame@dev.null"} template', $a, $result3),
|
2014-05-06 14:22:58 +04:00
|
|
|
array(
|
|
|
|
'Include {include "welcome.tpl" email="flame@dev.null"} template',
|
|
|
|
$a,
|
|
|
|
$result3,
|
|
|
|
Fenom::FORCE_INCLUDE
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'Include {include "welcome.tpl" username="Flame" email="flame@dev.null"} template',
|
|
|
|
$a,
|
|
|
|
$result4
|
|
|
|
),
|
2013-01-25 18:36:16 +04:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2013-07-29 14:58:14 +04:00
|
|
|
public static function providerIncludeInvalid()
|
|
|
|
{
|
2013-01-25 18:36:16 +04:00
|
|
|
return array(
|
2013-07-29 16:15:52 +04:00
|
|
|
array('Include {include} template', 'Fenom\Error\CompileException', "Unexpected end of expression"),
|
2014-05-06 14:22:58 +04:00
|
|
|
array(
|
|
|
|
'Include {include another="welcome.tpl"} template',
|
|
|
|
'Fenom\Error\CompileException',
|
|
|
|
"Unexpected token 'another'"
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'Include {include "../../TestCase.php"} template',
|
|
|
|
'Fenom\Error\SecurityException',
|
|
|
|
"Template ../../TestCase.php not found"
|
|
|
|
),
|
2013-01-25 18:36:16 +04:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2013-09-14 11:24:23 +04:00
|
|
|
public static function providerInsert()
|
|
|
|
{
|
2014-05-06 14:22:58 +04:00
|
|
|
$a = array(
|
|
|
|
"name" => "welcome",
|
|
|
|
"tpl" => "welcome.tpl",
|
|
|
|
"fragment" => "come",
|
2013-09-14 11:24:23 +04:00
|
|
|
"pr_fragment" => "Come",
|
2014-05-06 14:22:58 +04:00
|
|
|
"pr_name" => "Welcome",
|
|
|
|
"username" => "Master",
|
|
|
|
"email" => "dev@null.net"
|
2013-09-14 11:24:23 +04:00
|
|
|
);
|
2013-09-14 19:55:53 +04:00
|
|
|
$result = 'Include <b>Welcome, Master (dev@null.net)</b> template';
|
2013-09-14 11:24:23 +04:00
|
|
|
return array(
|
|
|
|
array('Include {insert "welcome.tpl"} template', $a, $result),
|
|
|
|
array("Include {insert 'welcome.tpl'} template", $a, $result),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function providerInsertInvalid()
|
|
|
|
{
|
|
|
|
return array(
|
|
|
|
array('Include {insert} template', 'Fenom\Error\CompileException', "Unexpected end of expression"),
|
2014-05-06 14:22:58 +04:00
|
|
|
array(
|
|
|
|
'Include {insert another="welcome.tpl"} template',
|
|
|
|
'Fenom\Error\CompileException',
|
|
|
|
"Unexpected token 'another'"
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'Include {insert $tpl} template',
|
|
|
|
'Fenom\Error\CompileException',
|
|
|
|
"Tag {insert} accept only static template name"
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'Include {insert "$tpl"} template',
|
|
|
|
'Fenom\Error\CompileException',
|
|
|
|
"Tag {insert} accept only static template name"
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'Include {insert "{$tpl}"} template',
|
|
|
|
'Fenom\Error\CompileException',
|
|
|
|
"Tag {insert} accept only static template name"
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'Include {insert "$name.tpl"} template',
|
|
|
|
'Fenom\Error\CompileException',
|
|
|
|
"Tag {insert} accept only static template name"
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'Include {insert "{$name}.tpl"} template',
|
|
|
|
'Fenom\Error\CompileException',
|
|
|
|
"Tag {insert} accept only static template name"
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'Include {insert "{$pr_name|lower}.tpl"} template',
|
|
|
|
'Fenom\Error\CompileException',
|
|
|
|
"Tag {insert} accept only static template name"
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'Include {insert "wel{$fragment}.tpl"} template',
|
|
|
|
'Fenom\Error\CompileException',
|
|
|
|
"Tag {insert} accept only static template name"
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'Include {insert "welcome.tpl" email="flame@dev.null"} template',
|
|
|
|
'Fenom\Error\CompileException',
|
|
|
|
"Unexpected token 'email'"
|
|
|
|
),
|
2013-09-14 11:24:23 +04:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2013-07-29 14:58:14 +04:00
|
|
|
public static function providerIf()
|
|
|
|
{
|
2013-01-25 18:36:16 +04:00
|
|
|
$a = array(
|
|
|
|
"val1" => 1,
|
|
|
|
"val0" => 0,
|
2014-05-06 14:22:58 +04:00
|
|
|
"x" => 9,
|
|
|
|
"y" => 27
|
2013-01-25 18:36:16 +04:00
|
|
|
);
|
|
|
|
return array(
|
2013-07-29 14:58:14 +04:00
|
|
|
array('if: {if 1} block1 {/if} end', $a, 'if: block1 end'),
|
|
|
|
array('if: {if 1} block1 {else} block2 {/if} end', $a, 'if: block1 end'),
|
|
|
|
array('if: {if 0} block1 {/if} end', $a, 'if: end'),
|
|
|
|
array('if: {if $val0} block1 {else} block2 {/if} end', $a, 'if: block2 end'),
|
|
|
|
array('if: {if $val1} block1 {else} block2 {/if} end', $a, 'if: block1 end'),
|
|
|
|
array('if: {if $val1 || $val0} block1 {else} block2 {/if} end', $a, 'if: block1 end'),
|
|
|
|
array('if: {if $val1 && $val0} block1 {else} block2 {/if} end', $a, 'if: block2 end'),
|
2014-05-06 14:22:58 +04:00
|
|
|
array(
|
|
|
|
'if: {if $x-9} block1 {elseif $x} block2 {else} block3 {/if} end',
|
|
|
|
$a,
|
|
|
|
'if: block2 end'
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'if: {if round(sin(pi()), 8)} block1 {elseif $x} block2 {else} block3 {/if} end',
|
|
|
|
$a,
|
|
|
|
'if: block2 end'
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'if: {if round(sin(pi()), 8)} block1 {elseif $val0} block2 {else} block3 {/if} end',
|
|
|
|
$a,
|
|
|
|
'if: block3 end'
|
|
|
|
),
|
2013-07-29 14:58:14 +04:00
|
|
|
array('if: {if empty($val0)} block1 {else} block2 {/if} end', $a, 'if: block1 end'),
|
|
|
|
array('if: {if $val0?} block1 {else} block2 {/if} end', $a, 'if: block2 end'),
|
|
|
|
array('if: {if $val1?} block1 {else} block2 {/if} end', $a, 'if: block1 end'),
|
|
|
|
array('if: {if $val0!} block1 {else} block2 {/if} end', $a, 'if: block1 end'),
|
|
|
|
array('if: {if $val1!} block1 {else} block2 {/if} end', $a, 'if: block1 end'),
|
|
|
|
array('if: {if $val0.x.y.z?} block1 {else} block2 {/if} end', $a, 'if: block2 end'),
|
|
|
|
array('if: {if $val0.x.y.z!} block1 {else} block2 {/if} end', $a, 'if: block2 end'),
|
|
|
|
array('if: {if true} block1 {else} block2 {/if} end', $a, 'if: block1 end'),
|
|
|
|
array('if: {if false} block1 {else} block2 {/if} end', $a, 'if: block2 end'),
|
|
|
|
array('if: {if null} block1 {else} block2 {/if} end', $a, 'if: block2 end'),
|
2013-08-06 12:04:23 +04:00
|
|
|
array('if: {if max(2, 4) > 1 && max(2, 3) < 1} block1 {else} block2 {/if} end', $a, 'if: block2 end'),
|
2014-05-06 14:22:58 +04:00
|
|
|
array(
|
|
|
|
'if: {if ($val1 || $val0) && $x} block1 {else} block2 {/if} end',
|
|
|
|
$a,
|
|
|
|
'if: block1 end'
|
|
|
|
),
|
2013-07-29 14:58:14 +04:00
|
|
|
array('if: {if $unexist} block1 {else} block2 {/if} end', $a, 'if: block2 end', Fenom::FORCE_VERIFY),
|
2013-01-25 18:36:16 +04:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2013-07-29 14:58:14 +04:00
|
|
|
public static function providerIfInvalid()
|
|
|
|
{
|
2013-01-25 18:36:16 +04:00
|
|
|
return array(
|
2013-07-29 16:15:52 +04:00
|
|
|
array('If: {if} block1 {/if} end', 'Fenom\Error\CompileException', "Unexpected end of expression"),
|
2014-05-06 14:22:58 +04:00
|
|
|
array(
|
|
|
|
'If: {if 1} block1 {elseif} block2 {/if} end',
|
|
|
|
'Fenom\Error\CompileException',
|
|
|
|
"Unexpected end of expression"
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'If: {if 1} block1 {else} block2 {elseif 0} block3 {/if} end',
|
|
|
|
'Fenom\Error\CompileException',
|
|
|
|
"Incorrect use of the tag {elseif}"
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'If: {if 1} block1 {else} block2 {/if} block3 {elseif 0} end',
|
|
|
|
'Fenom\Error\CompileException',
|
|
|
|
"Unexpected tag 'elseif' (this tag can be used with 'if')"
|
|
|
|
),
|
2013-01-25 18:36:16 +04:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2013-07-29 14:58:14 +04:00
|
|
|
public static function providerCreateVar()
|
|
|
|
{
|
2013-01-25 18:36:16 +04:00
|
|
|
$a = array(
|
|
|
|
"x" => 9,
|
|
|
|
"y" => 27,
|
|
|
|
"z" => 99
|
|
|
|
);
|
|
|
|
return array(
|
2014-08-06 00:08:51 +04:00
|
|
|
array('Create: {set $v = $x+$y} Result: {$v} end', $a, 'Create: Result: 36 end'),
|
|
|
|
array('Create: {add $x = $x+$y} Result: {$x} end', $a, 'Create: Result: 9 end'),
|
|
|
|
array('Create: {add $v = 3} {add $v = 9} Result: {$v} end', $a, 'Create: Result: 3 end'),
|
2014-05-06 14:22:58 +04:00
|
|
|
array(
|
2014-08-06 00:08:51 +04:00
|
|
|
'Create: {set $v =
|
2014-05-06 14:22:58 +04:00
|
|
|
$x
|
|
|
|
+
|
|
|
|
$y} Result: {$v} end',
|
|
|
|
$a,
|
|
|
|
'Create: Result: 36 end'
|
|
|
|
),
|
2014-08-06 00:08:51 +04:00
|
|
|
array('Create: {set $v = $z++} Result: {$v}, {$z} end', $a, 'Create: Result: 99, 100 end'),
|
|
|
|
array('Create: {set $v = $z++ + 1} Result: {$v}, {$z} end', $a, 'Create: Result: 100, 100 end'),
|
|
|
|
array('Create: {set $v = --$z} Result: {$v}, {$z} end', $a, 'Create: Result: 98, 98 end'),
|
|
|
|
array('Create: {set $v = $y/$x} Result: {$v} end', $a, 'Create: Result: 3 end'),
|
|
|
|
array('Create: {set $v = $y-$x} Result: {$v} end', $a, 'Create: Result: 18 end'),
|
|
|
|
array('Create: {set $v = $y*$x-2} Result: {$v} end', $a, 'Create: Result: 241 end'),
|
|
|
|
array('Create: {set $v = ($y^$x)+7} Result: {$v} end', $a, 'Create: Result: 25 end'),
|
|
|
|
array('Create: {set $v = [1,2,3]} Result: {$v.1} end', $a, 'Create: Result: 2 end'),
|
2014-05-06 14:22:58 +04:00
|
|
|
array(
|
2014-08-06 00:08:51 +04:00
|
|
|
'Create: {set $v = []} Result: {if $v} have items {else} empty {/if} end',
|
2014-05-06 14:22:58 +04:00
|
|
|
$a,
|
|
|
|
'Create: Result: empty end'
|
|
|
|
),
|
|
|
|
array(
|
2014-08-06 00:08:51 +04:00
|
|
|
'Create: {set $v = ["one"|upper => 1, 4 => $x, "three" => 3]} Result: {$v.three}, {$v.4}, {$v.ONE} end',
|
2014-05-06 14:22:58 +04:00
|
|
|
$a,
|
|
|
|
'Create: Result: 3, 9, 1 end'
|
|
|
|
),
|
|
|
|
array(
|
2014-08-06 00:08:51 +04:00
|
|
|
'Create: {set $v = ["key1" => $y*$x-2, "key2" => ["z" => $z]]} Result: {$v.key1}, {$v.key2.z} end',
|
2014-05-06 14:22:58 +04:00
|
|
|
$a,
|
|
|
|
'Create: Result: 241, 99 end'
|
|
|
|
),
|
|
|
|
array(
|
2014-08-06 00:08:51 +04:00
|
|
|
'Create: {set $v = count([1,2,3])+7} Result: {$v} end',
|
2014-05-06 14:22:58 +04:00
|
|
|
$a,
|
|
|
|
'Create: Result: 10 end'
|
|
|
|
),
|
2013-01-25 18:36:16 +04:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2013-07-29 14:58:14 +04:00
|
|
|
public static function providerCreateVarInvalid()
|
|
|
|
{
|
2013-01-25 18:36:16 +04:00
|
|
|
return array(
|
2014-08-06 00:08:51 +04:00
|
|
|
array('Create: {set $v} Result: {$v} end', 'Fenom\Error\CompileException', "Unclosed tag: {set} opened"),
|
|
|
|
array('Create: {add $v} Result: {$v} end', 'Fenom\Error\CompileException', "Unclosed tag: {add} opened"),
|
2014-05-06 14:22:58 +04:00
|
|
|
array(
|
2014-08-06 00:08:51 +04:00
|
|
|
'Create: {set $v = } Result: {$v} end',
|
2014-05-06 14:22:58 +04:00
|
|
|
'Fenom\Error\CompileException',
|
|
|
|
"Unexpected end of expression"
|
|
|
|
),
|
2014-08-06 00:08:51 +04:00
|
|
|
array('Create: {set $v = 1++} Result: {$v} end', 'Fenom\Error\CompileException', "Unexpected token '++'"),
|
|
|
|
array('Create: {set $v = c} Result: {$v} end', 'Fenom\Error\CompileException', "Unexpected token 'c'"),
|
2014-05-06 14:22:58 +04:00
|
|
|
array(
|
2014-08-06 00:08:51 +04:00
|
|
|
'Create: {set $v = ($a)++} Result: {$v} end',
|
2014-05-06 14:22:58 +04:00
|
|
|
'Fenom\Error\CompileException',
|
|
|
|
"Unexpected token '++'"
|
|
|
|
),
|
|
|
|
array(
|
2014-08-06 00:08:51 +04:00
|
|
|
'Create: {set $v = --$a++} Result: {$v} end',
|
2014-05-06 14:22:58 +04:00
|
|
|
'Fenom\Error\CompileException',
|
|
|
|
"Unexpected token '++'"
|
|
|
|
),
|
|
|
|
array(
|
2014-08-06 00:08:51 +04:00
|
|
|
'Create: {set $v = $a|upper++} Result: {$v} end',
|
2014-05-06 14:22:58 +04:00
|
|
|
'Fenom\Error\CompileException',
|
|
|
|
"Unexpected token '++'"
|
|
|
|
),
|
|
|
|
array(
|
2014-08-06 00:08:51 +04:00
|
|
|
'Create: {set $v = max($a,2)++} Result: {$v} end',
|
2014-05-06 14:22:58 +04:00
|
|
|
'Fenom\Error\CompileException',
|
|
|
|
"Unexpected token '++'"
|
|
|
|
),
|
|
|
|
array(
|
2014-08-06 00:08:51 +04:00
|
|
|
'Create: {set $v = max($a,2)} Result: {$v} end',
|
2014-05-06 14:22:58 +04:00
|
|
|
'Fenom\Error\CompileException',
|
|
|
|
"Function max not found",
|
|
|
|
Fenom::DENY_NATIVE_FUNCS
|
|
|
|
),
|
|
|
|
array(
|
2014-08-06 00:08:51 +04:00
|
|
|
'Create: {set $v = 4*} Result: {$v} end',
|
2014-05-06 14:22:58 +04:00
|
|
|
'Fenom\Error\CompileException',
|
|
|
|
"Unexpected end of expression"
|
|
|
|
),
|
2014-08-06 00:08:51 +04:00
|
|
|
array('Create: {set $v = ""$a} Result: {$v} end', 'Fenom\Error\CompileException', "Unexpected token '\$a'"),
|
2014-05-06 14:22:58 +04:00
|
|
|
array(
|
2014-08-06 00:08:51 +04:00
|
|
|
'Create: {set $v = [1,2} Result: {$v} end',
|
2014-05-06 14:22:58 +04:00
|
|
|
'Fenom\Error\CompileException',
|
|
|
|
"Unexpected end of expression"
|
|
|
|
),
|
|
|
|
array(
|
2014-08-06 00:08:51 +04:00
|
|
|
'Create: {set $v = empty(2)} Result: {$v} end',
|
2014-05-06 14:22:58 +04:00
|
|
|
'Fenom\Error\CompileException',
|
|
|
|
"Unexpected token 2, isset() and empty() accept only variables"
|
|
|
|
),
|
|
|
|
array(
|
2014-08-06 00:08:51 +04:00
|
|
|
'Create: {set $v = isset(2)} Result: {$v} end',
|
2014-05-06 14:22:58 +04:00
|
|
|
'Fenom\Error\CompileException',
|
|
|
|
"Unexpected token 2, isset() and empty() accept only variables"
|
|
|
|
),
|
2013-01-25 18:36:16 +04:00
|
|
|
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2014-06-28 21:08:20 +04:00
|
|
|
public static function providerArrays()
|
|
|
|
{
|
|
|
|
return array(
|
2014-08-06 01:17:21 +04:00
|
|
|
array('{set $arr[] = 4}', array(4)),
|
2014-08-06 00:08:51 +04:00
|
|
|
array('{set $arr = []}', array()),
|
|
|
|
array('{set $arr = [1]}', array(1)),
|
|
|
|
array('{set $arr = [1,]}', array(1)),
|
|
|
|
array('{set $arr = [1, 2, 3, 5]}', array(1, 2, 3, 5)),
|
|
|
|
array('{set $arr = [1, true, false, null, -1, 1.1, -2.2, 5, "str"]}', array(1, true, false, null, -1, 1.1, -2.2, 5, "str")),
|
|
|
|
array('{set $arr = [5 => 1, "two" => 2, 3]}', array(5 => 1, "two" => 2, 3)),
|
|
|
|
array('{set $arr = [1 + 1, 2 * 2, 3 / 3 + 7,]}', array(1 + 1, 2 * 2, 3 / 3 + 7)),
|
|
|
|
array('{set $arr = [$zero, $two => $one, $num.3 => $.const.PHP_VERSION]}', array(0, 2 => 1, "three" => PHP_VERSION)),
|
|
|
|
array('{set $arr = [5 - 1 => 1, "two"|up => "two"|low, 3 => count([1,2])]}', array(4 => 1, "TWO" => "two", 3 => 2)),
|
2014-06-28 21:08:20 +04:00
|
|
|
|
2014-08-06 00:08:51 +04:00
|
|
|
array('{set $arr = [[1]]}', array(array(1))),
|
|
|
|
array('{set $arr = [[],[]]}', array(array(),array())),
|
|
|
|
array('{set $arr = [1, [2, 3], 5]}', array(1, array(2, 3), 5)),
|
|
|
|
array('{set $arr = [1, [true, false, null, -1, 1.1, -2.2, 5], "str"]}', array(1, array(true, false, null, -1, 1.1, -2.2, 5), "str")),
|
|
|
|
array('{set $arr = [5 => [1, "two" => 2], 3]}', array(5 => array(1, "two" => 2), 3)),
|
|
|
|
array('{set $arr = [1 + 1, [2 * 2, 3 / 3 + 7,],]}', array(1 + 1, array(2 * 2, 3 / 3 + 7))),
|
|
|
|
array('{set $arr = [$zero, [$two => $one, $num.3 => $.const.PHP_VERSION]]}', array(0, array(2 => 1, "three" => PHP_VERSION))),
|
|
|
|
array('{set $arr = [5 - 1 => 1, ["two"|up => ("two"|low ~ "..."), 3 => count([1,2])]]}', array(4 => 1, array("TWO" => "two...", 3 => 2))),
|
2014-06-28 21:08:20 +04:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2014-06-28 22:15:30 +04:00
|
|
|
public static function providerUnset() {
|
|
|
|
return array(
|
2014-08-06 00:08:51 +04:00
|
|
|
array('{set $a = 5} {unset $a} {if $a is not set}not set{/if}', 'not set'),
|
|
|
|
array('{set $a = ["b" => 5, "c" => 6]} {unset $a.b} {if $a.b is not set}not set{/if} but c is {$a.c}', 'not set but c is 6'),
|
|
|
|
array('{set $a = ["b" => 5, "c" => 6]} {unset $a.b $a.c} {if $a.b is not set}not set{/if} {if $a.c is not set}not set{/if}', 'not set not set'),
|
2014-06-28 22:15:30 +04:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2013-07-29 14:58:14 +04:00
|
|
|
public static function providerTernary()
|
|
|
|
{
|
2013-02-07 17:37:16 +04:00
|
|
|
$a = array(
|
2014-05-06 14:22:58 +04:00
|
|
|
"a" => 1,
|
|
|
|
"em" => "empty",
|
|
|
|
"empty" => array(
|
|
|
|
"array" => array(),
|
|
|
|
"int" => 0,
|
2013-02-07 17:37:16 +04:00
|
|
|
"string" => "",
|
|
|
|
"double" => 0.0,
|
2014-05-06 14:22:58 +04:00
|
|
|
"bool" => false,
|
2013-02-07 17:37:16 +04:00
|
|
|
),
|
|
|
|
"nonempty" => array(
|
2014-05-06 14:22:58 +04:00
|
|
|
"array" => array(1, 2),
|
|
|
|
"int" => 2,
|
2013-02-07 17:37:16 +04:00
|
|
|
"string" => "abc",
|
|
|
|
"double" => 0.2,
|
2014-05-06 14:22:58 +04:00
|
|
|
"bool" => true,
|
2013-02-07 17:37:16 +04:00
|
|
|
)
|
|
|
|
);
|
|
|
|
return array(
|
|
|
|
// ?
|
2013-07-29 14:58:14 +04:00
|
|
|
array('{if $a?} right {/if}', $a),
|
2014-02-27 16:30:44 +04:00
|
|
|
array('{if 1?} right {/if}', $a),
|
|
|
|
array('{if 0?} no way {else} right {/if}', $a),
|
2013-07-29 14:58:14 +04:00
|
|
|
array('{if $unexists?} no way {else} right {/if}', $a),
|
|
|
|
array('{if $empty.array?} no way {else} right {/if}', $a),
|
|
|
|
array('{if $empty.int?} no way {else} right {/if}', $a),
|
|
|
|
array('{if $empty.string?} no way {else} right {/if}', $a),
|
|
|
|
array('{if $empty.double?} no way {else} right {/if}', $a),
|
|
|
|
array('{if $empty.bool?} no way {else} right {/if}', $a),
|
2013-02-07 17:37:16 +04:00
|
|
|
array('{if $empty.unexist?} no way {else} right {/if}', $a),
|
2013-07-29 14:58:14 +04:00
|
|
|
array('{if $nonempty.array?} right {/if}', $a),
|
|
|
|
array('{if $nonempty.int?} right {/if}', $a),
|
|
|
|
array('{if $nonempty.string?} right {/if}', $a),
|
|
|
|
array('{if $nonempty.double?} right {/if}', $a),
|
|
|
|
array('{if $nonempty.bool?} right {/if}', $a),
|
2013-02-07 17:37:16 +04:00
|
|
|
// ?: ...
|
2013-07-29 14:58:14 +04:00
|
|
|
array('{$a?:"empty"}', $a, "1"),
|
|
|
|
array('{$unexists?:"empty"}', $a, "empty"),
|
|
|
|
array('{$empty.array?:"empty"}', $a, "empty"),
|
|
|
|
array('{$empty.int?:"empty"}', $a, "empty"),
|
|
|
|
array('{$empty.string?:"empty"}', $a, "empty"),
|
|
|
|
array('{$empty.double?:"empty"}', $a, "empty"),
|
|
|
|
array('{$empty.bool?:"empty"}', $a, "empty"),
|
|
|
|
array('{$empty.unexist?:"empty"}', $a, "empty"),
|
2014-02-27 16:30:44 +04:00
|
|
|
array('{0?:"empty"}', $a, "empty"),
|
2013-02-07 17:37:16 +04:00
|
|
|
// ? ... : ....
|
2013-08-02 23:30:44 +04:00
|
|
|
array('{$unexists ? "no way" : "right"}', $a),
|
2014-02-27 16:30:44 +04:00
|
|
|
array('{0 ? "no way" : "right"}', $a),
|
2013-08-02 23:30:44 +04:00
|
|
|
array('{$a ? "right" : "no way"}', $a),
|
2014-02-27 16:30:44 +04:00
|
|
|
array('{1 ? "right" : "no way"}', $a),
|
2013-02-07 17:37:16 +04:00
|
|
|
// !
|
2013-07-29 14:58:14 +04:00
|
|
|
array('{if $a!} right {/if}', $a),
|
2014-02-27 16:30:44 +04:00
|
|
|
array('{if 1!} right {/if}', $a),
|
|
|
|
array('{if 0!} right {/if}', $a),
|
|
|
|
array('{if null!} no way {else} right {/if}', $a),
|
2013-07-29 14:58:14 +04:00
|
|
|
array('{if $unexists!} no way {else} right {/if}', $a),
|
|
|
|
array('{if $empty.array!} right {/if}', $a),
|
|
|
|
array('{if $empty.int!} right {/if}', $a),
|
|
|
|
array('{if $empty.string!} right {/if}', $a),
|
|
|
|
array('{if $empty.double!} right {/if}', $a),
|
|
|
|
array('{if $empty.bool!} right {/if}', $a),
|
2013-02-07 17:37:16 +04:00
|
|
|
array('{if $empty.unexist!} no way {else} right {/if}', $a),
|
2013-07-29 14:58:14 +04:00
|
|
|
array('{if $nonempty.array!} right {/if}', $a),
|
|
|
|
array('{if $nonempty.int!} right {/if}', $a),
|
|
|
|
array('{if $nonempty.string!} right {/if}', $a),
|
|
|
|
array('{if $nonempty.double!} right {/if}', $a),
|
|
|
|
array('{if $nonempty.bool!} right {/if}', $a),
|
2013-07-20 21:25:32 +04:00
|
|
|
// ! ... : ...
|
2013-08-02 23:01:06 +04:00
|
|
|
array('{$unexists ! "no way" : "right"}', $a),
|
|
|
|
array('{$a ! "right" : "no way"}', $a),
|
2014-02-27 16:30:44 +04:00
|
|
|
array('{1 ! "right" : "no way"}', $a),
|
2013-07-20 21:25:32 +04:00
|
|
|
// !: ...
|
2013-08-02 23:01:06 +04:00
|
|
|
array('{$unexists !: "right"}', $a),
|
|
|
|
array('{$a !: "right"}', $a, '1'),
|
2014-02-27 16:30:44 +04:00
|
|
|
array('{1 !: "right"}', $a, '1'),
|
2013-02-07 17:37:16 +04:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2013-07-29 14:58:14 +04:00
|
|
|
public static function providerForeach()
|
|
|
|
{
|
2013-01-25 18:36:16 +04:00
|
|
|
$a = array(
|
2014-05-06 14:22:58 +04:00
|
|
|
"list" => array(1 => "one", 2 => "two", 3 => "three"),
|
2014-07-03 11:28:59 +04:00
|
|
|
"empty" => array(),
|
|
|
|
"obj" => new Helper("testing")
|
2013-01-25 18:36:16 +04:00
|
|
|
);
|
|
|
|
return array(
|
|
|
|
array('Foreach: {foreach $list as $e} {$e}, {/foreach} end', $a, 'Foreach: one, two, three, end'),
|
|
|
|
array('Foreach: {foreach $list as $e} {$e},{break} break {/foreach} end', $a, 'Foreach: one, end'),
|
2014-05-06 14:22:58 +04:00
|
|
|
array(
|
|
|
|
'Foreach: {foreach $list as $e} {$e},{continue} continue {/foreach} end',
|
|
|
|
$a,
|
|
|
|
'Foreach: one, two, three, end'
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'Foreach: {foreach ["one", "two", "three"] as $e} {$e}, {/foreach} end',
|
|
|
|
$a,
|
|
|
|
'Foreach: one, two, three, end'
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'Foreach: {foreach $list as $k => $e} {$k} => {$e}, {/foreach} end',
|
|
|
|
$a,
|
|
|
|
'Foreach: 1 => one, 2 => two, 3 => three, end'
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'Foreach: {foreach [1 => "one", 2 => "two", 3 => "three"] as $k => $e} {$k} => {$e}, {/foreach} end',
|
|
|
|
$a,
|
|
|
|
'Foreach: 1 => one, 2 => two, 3 => three, end'
|
|
|
|
),
|
2013-01-25 18:36:16 +04:00
|
|
|
array('Foreach: {foreach $empty as $k => $e} {$k} => {$e}, {/foreach} end', $a, 'Foreach: end'),
|
|
|
|
array('Foreach: {foreach [] as $k => $e} {$k} => {$e}, {/foreach} end', $a, 'Foreach: end'),
|
2014-07-03 11:28:59 +04:00
|
|
|
array('Foreach: {foreach $obj->getArray() as $k => $e} {$k} => {$e}, {/foreach} end', $a, 'Foreach: 0 => 1, 1 => 2, 2 => 3, end'),
|
2014-06-28 21:08:20 +04:00
|
|
|
array('Foreach: {foreach $unexists as $k => $e} {$k} => {$e}, {/foreach} end', $a, 'Foreach: end'),
|
2014-05-06 14:22:58 +04:00
|
|
|
array(
|
|
|
|
'Foreach: {foreach $empty as $k => $e} {$k} => {$e}, {foreachelse} empty {/foreach} end',
|
|
|
|
$a,
|
|
|
|
'Foreach: empty end'
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'Foreach: {foreach $list as $e index=$i} {$i}: {$e}, {/foreach} end',
|
|
|
|
$a,
|
|
|
|
'Foreach: 0: one, 1: two, 2: three, end'
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'Foreach: {foreach $list as $k => $e index=$i} {$i}: {$k} => {$e}, {/foreach} end',
|
|
|
|
$a,
|
|
|
|
'Foreach: 0: 1 => one, 1: 2 => two, 2: 3 => three, end'
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'Foreach: {foreach $empty as $k => $e index=$i} {$i}: {$k} => {$e}, {foreachelse} empty {/foreach} end',
|
|
|
|
$a,
|
|
|
|
'Foreach: empty end'
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'Foreach: {foreach $list as $k => $e first=$f index=$i} {if $f}first{/if} {$i}: {$k} => {$e}, {/foreach} end',
|
|
|
|
$a,
|
|
|
|
'Foreach: first 0: 1 => one, 1: 2 => two, 2: 3 => three, end'
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'Foreach: {foreach $list as $k => $e last=$l first=$f index=$i} {if $f}first{/if} {$i}: {$k} => {$e}, {if $l}last{/if} {/foreach} end',
|
|
|
|
$a,
|
|
|
|
'Foreach: first 0: 1 => one, 1: 2 => two, 2: 3 => three, last end'
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'Foreach: {foreach $empty as $k => $e last=$l first=$f index=$i} {if $f}first{/if} {$i}: {$k} => {$e}, {if $l}last{/if} {foreachelse} empty {/foreach} end',
|
|
|
|
$a,
|
|
|
|
'Foreach: empty end'
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'Foreach: {foreach [1 => "one", 2 => "two", 3 => "three"] as $k => $e last=$l first=$f index=$i} {if $f}first{/if} {$i}: {$k} => {$e}, {if $l}last{/if} {/foreach} end',
|
|
|
|
$a,
|
|
|
|
'Foreach: first 0: 1 => one, 1: 2 => two, 2: 3 => three, last end'
|
|
|
|
),
|
2013-01-25 18:36:16 +04:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2013-07-29 14:58:14 +04:00
|
|
|
public static function providerForeachInvalid()
|
|
|
|
{
|
2013-01-25 18:36:16 +04:00
|
|
|
return array(
|
2014-05-06 14:22:58 +04:00
|
|
|
array(
|
|
|
|
'Foreach: {foreach} {$e}, {/foreach} end',
|
|
|
|
'Fenom\Error\CompileException',
|
|
|
|
"Unexpected end of tag {foreach}"
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'Foreach: {foreach $list} {$e}, {/foreach} end',
|
|
|
|
'Fenom\Error\CompileException',
|
|
|
|
"Unexpected end of expression"
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'Foreach: {foreach $list+1 as $e} {$e}, {/foreach} end',
|
|
|
|
'Fenom\Error\CompileException',
|
|
|
|
"Unexpected token '+'"
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'Foreach: {foreach array_random() as $e} {$e}, {/foreach} end',
|
|
|
|
'Fenom\Error\CompileException',
|
|
|
|
"Unexpected token 'array_random'"
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'Foreach: {foreach $list as $e+1} {$e}, {/foreach} end',
|
|
|
|
'Fenom\Error\CompileException',
|
|
|
|
"Unexpected token '+'"
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'Foreach: {foreach $list as $k+1 => $e} {$e}, {/foreach} end',
|
|
|
|
'Fenom\Error\CompileException',
|
|
|
|
"Unexpected token '+'"
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'Foreach: {foreach $list as max($i,1) => $e} {$e}, {/foreach} end',
|
|
|
|
'Fenom\Error\CompileException',
|
|
|
|
"Unexpected token 'max'"
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'Foreach: {foreach $list as max($e,1)} {$e}, {/foreach} end',
|
|
|
|
'Fenom\Error\CompileException',
|
|
|
|
"Unexpected token 'max'"
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'Foreach: {foreach $list => $e} {$e}, {/foreach} end',
|
|
|
|
'Fenom\Error\CompileException',
|
|
|
|
"Unexpected token '=>'"
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'Foreach: {foreach $list $k => $e} {$e}, {/foreach} end',
|
|
|
|
'Fenom\Error\CompileException',
|
|
|
|
"Unexpected token '\$k'"
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'Foreach: {foreach $list as $k =>} {$e}, {/foreach} end',
|
|
|
|
'Fenom\Error\CompileException',
|
|
|
|
"Unexpected end of expression"
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'Foreach: {foreach last=$l $list as $e } {$e}, {/foreach} end',
|
|
|
|
'Fenom\Error\CompileException',
|
|
|
|
"Unexpected token 'last' in tag {foreach}"
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'Foreach: {foreach $list as $e unknown=1} {$e}, {/foreach} end',
|
|
|
|
'Fenom\Error\CompileException',
|
|
|
|
"Unknown parameter 'unknown'"
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'Foreach: {foreach $list as $e index=$i+1} {$e}, {/foreach} end',
|
|
|
|
'Fenom\Error\CompileException',
|
|
|
|
"Unexpected token '+'"
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'Foreach: {foreach $list as $e first=$f+1} {$e}, {/foreach} end',
|
|
|
|
'Fenom\Error\CompileException',
|
|
|
|
"Unexpected token '+'"
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'Foreach: {foreach $list as $e last=$l+1} {$e}, {/foreach} end',
|
|
|
|
'Fenom\Error\CompileException',
|
|
|
|
"Unexpected token '+'"
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'Foreach: {foreach $list as $e index=max($i,1)} {$e}, {/foreach} end',
|
|
|
|
'Fenom\Error\CompileException',
|
|
|
|
"Unexpected token 'max'"
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'Foreach: {foreach $list as $e first=max($i,1)} {$e}, {/foreach} end',
|
|
|
|
'Fenom\Error\CompileException',
|
|
|
|
"Unexpected token 'max'"
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'Foreach: {foreach $list as $e last=max($i,1)} {$e}, {/foreach} end',
|
|
|
|
'Fenom\Error\CompileException',
|
|
|
|
"Unexpected token 'max'"
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'Foreach: {foreach $list as $e} {$e}, {foreachelse} {break} {/foreach} end',
|
|
|
|
'Fenom\Error\CompileException',
|
|
|
|
"Improper usage of the tag {break}"
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'Foreach: {foreach $list as $e} {$e}, {foreachelse} {continue} {/foreach} end',
|
|
|
|
'Fenom\Error\CompileException',
|
|
|
|
"Improper usage of the tag {continue}"
|
|
|
|
),
|
2013-01-25 18:36:16 +04:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2013-07-29 14:58:14 +04:00
|
|
|
public static function providerIgnores()
|
|
|
|
{
|
2013-01-25 18:36:16 +04:00
|
|
|
$a = array("a" => "lit. A");
|
|
|
|
return array(
|
2013-07-29 14:58:14 +04:00
|
|
|
array('{if 0}none{/if} literal: {$a} end', $a, 'literal: lit. A end'),
|
|
|
|
array('{if 0}none{/if} literal:{ignore} {$a} {/ignore} end', $a, 'literal: {$a} end'),
|
|
|
|
array('{if 0}none{/if} literal: { $a} end', $a, 'literal: { $a} end'),
|
|
|
|
array('{if 0}none{/if} literal: { $a}{$a}{ $a} end', $a, 'literal: { $a}lit. A{ $a} end'),
|
2014-05-06 14:22:58 +04:00
|
|
|
array(
|
|
|
|
'{if 0}none{/if} literal: {
|
|
|
|
$a} end',
|
|
|
|
$a,
|
|
|
|
'literal: { $a} end'
|
|
|
|
),
|
2014-05-12 00:36:50 +04:00
|
|
|
array('{if 0}none{/if}literal: function () { return 1; } end', $a, 'literal: function () { return 1; } end'),
|
|
|
|
array('{if:ignore 1}literal: {$a} end{/if}', $a, 'literal: {$a} end'),
|
2013-01-25 18:36:16 +04:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2013-07-29 14:58:14 +04:00
|
|
|
public static function providerSwitch()
|
|
|
|
{
|
2013-01-25 18:36:16 +04:00
|
|
|
$code1 = 'Switch: {switch $a}
|
2013-09-02 17:40:58 +04:00
|
|
|
{case 1, "one"} one
|
|
|
|
{case 2, "two"} two
|
2014-05-14 17:07:48 +04:00
|
|
|
{case "string", default} str
|
2013-01-25 18:36:16 +04:00
|
|
|
{default} def
|
|
|
|
{/switch} end';
|
|
|
|
|
|
|
|
$code2 = 'Switch: {switch $a}
|
2013-09-02 17:40:58 +04:00
|
|
|
{case 1, "one"} one
|
|
|
|
{case 2, "two"} two
|
|
|
|
{case "string"} str
|
2013-01-25 18:36:16 +04:00
|
|
|
{/switch} end';
|
|
|
|
|
|
|
|
$code3 = 'Switch: {switch $a} invalid
|
2013-09-02 17:40:58 +04:00
|
|
|
{case 1, "one"} one
|
2013-01-25 18:36:16 +04:00
|
|
|
{/switch} end';
|
|
|
|
|
|
|
|
return array(
|
|
|
|
array($code1, array("a" => 1), 'Switch: one end'),
|
2013-09-02 17:40:58 +04:00
|
|
|
array($code1, array("a" => 'one'), 'Switch: one end'),
|
2013-01-25 18:36:16 +04:00
|
|
|
array($code1, array("a" => 2), 'Switch: two end'),
|
2013-09-02 17:40:58 +04:00
|
|
|
array($code1, array("a" => 'two'), 'Switch: two end'),
|
2013-01-25 18:36:16 +04:00
|
|
|
array($code1, array("a" => "string"), 'Switch: str end'),
|
2014-05-14 17:07:48 +04:00
|
|
|
array($code1, array("a" => "unk"), 'Switch: str def end'),
|
2013-01-25 18:36:16 +04:00
|
|
|
array($code2, array("a" => "unk"), 'Switch: end'),
|
2013-09-02 17:40:58 +04:00
|
|
|
array($code3, array("a" => 1), 'Switch: one end'),
|
|
|
|
array($code3, array("a" => 'one'), 'Switch: one end'),
|
2013-01-25 18:36:16 +04:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2013-07-29 14:58:14 +04:00
|
|
|
public static function providerSwitchInvalid()
|
|
|
|
{
|
2013-01-25 18:36:16 +04:00
|
|
|
return array(
|
2014-05-06 14:22:58 +04:00
|
|
|
array(
|
|
|
|
'Switch: {switch}{case 1} one {/switch} end',
|
|
|
|
'Fenom\Error\CompileException',
|
|
|
|
"Unexpected end of expression"
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'Switch: {switch 1}{case} one{/switch} end',
|
|
|
|
'Fenom\Error\CompileException',
|
|
|
|
"Unexpected end of expression"
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'Switch: {switch 1}{case $var} one {/switch} end',
|
|
|
|
'Fenom\Error\CompileException',
|
|
|
|
"Unexpected token '\$var' in expression"
|
|
|
|
),
|
2013-01-25 18:36:16 +04:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2013-07-29 14:58:14 +04:00
|
|
|
public static function providerWhile()
|
|
|
|
{
|
2013-01-25 18:36:16 +04:00
|
|
|
$a = array("a" => 3);
|
|
|
|
return array(
|
|
|
|
array('While: {while false} block {/while} end', $a, 'While: end'),
|
|
|
|
array('While: {while --$a} {$a}, {/while} end', $a, 'While: 2, 1, end'),
|
|
|
|
array('While: {while --$a} {$a},{break} break {/while} end', $a, 'While: 2, end'),
|
|
|
|
array('While: {while --$a} {$a},{continue} continue {/while} end', $a, 'While: 2, 1, end'),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2013-07-29 14:58:14 +04:00
|
|
|
public static function providerWhileInvalid()
|
|
|
|
{
|
2013-01-25 18:36:16 +04:00
|
|
|
return array(
|
2013-07-29 16:15:52 +04:00
|
|
|
array('While: {while} block {/while} end', 'Fenom\Error\CompileException', "Unexpected end of expression"),
|
2013-01-25 18:36:16 +04:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2013-07-29 14:58:14 +04:00
|
|
|
public static function providerFor()
|
|
|
|
{
|
2013-01-25 18:36:16 +04:00
|
|
|
$a = array("c" => 1, "s" => 1, "m" => 3);
|
|
|
|
return array(
|
2013-07-29 14:58:14 +04:00
|
|
|
array('For: {for $a=4 to=6} $a: {$a}, {/for} end', $a, 'For: $a: 4, $a: 5, $a: 6, end'),
|
|
|
|
array('For: {for $a=4 step=2 to=10} $a: {$a}, {/for} end', $a, 'For: $a: 4, $a: 6, $a: 8, $a: 10, end'),
|
|
|
|
array('For: {for $a=4 step=-2 to=0} $a: {$a}, {/for} end', $a, 'For: $a: 4, $a: 2, $a: 0, end'),
|
|
|
|
array('For: {for $a=$c step=$s to=$m} $a: {$a}, {/for} end', $a, 'For: $a: 1, $a: 2, $a: 3, end'),
|
|
|
|
array('For: {for $a=-1 step=-max(1,2) to=-5} $a: {$a}, {/for} end', $a, 'For: $a: -1, $a: -3, $a: -5, end'),
|
2013-01-25 18:36:16 +04:00
|
|
|
array('For: {for $a=4 step=2 to=10} $a: {$a}, {break} break {/for} end', $a, 'For: $a: 4, end'),
|
2014-05-06 14:22:58 +04:00
|
|
|
array(
|
|
|
|
'For: {for $a=4 step=2 to=8} $a: {$a}, {continue} continue {/for} end',
|
|
|
|
$a,
|
|
|
|
'For: $a: 4, $a: 6, $a: 8, end'
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'For: {for $a=4 step=2 to=8 index=$i} $a{$i}: {$a}, {/for} end',
|
|
|
|
$a,
|
|
|
|
'For: $a0: 4, $a1: 6, $a2: 8, end'
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'For: {for $a=4 step=2 to=8 index=$i first=$f} {if $f}first{/if} $a{$i}: {$a}, {/for} end',
|
|
|
|
$a,
|
|
|
|
'For: first $a0: 4, $a1: 6, $a2: 8, end'
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'For: {for $a=4 step=2 to=8 index=$i first=$f last=$l} {if $f} first {/if} $a{$i}: {$a}, {if $l} last {/if} {/for} end',
|
|
|
|
$a,
|
|
|
|
'For: first $a0: 4, $a1: 6, $a2: 8, last end'
|
|
|
|
),
|
2013-07-29 14:58:14 +04:00
|
|
|
array('For: {for $a=1 to=-1 } $a: {$a}, {forelse} empty {/for} end', $a, 'For: empty end'),
|
2014-05-06 14:22:58 +04:00
|
|
|
array(
|
|
|
|
'For: {for $a=1 to=-1 index=$i first=$f last=$l} {if $f} first {/if} $a{$i}: {$a}, {if $l} last {/if} {forelse} empty {/for} end',
|
|
|
|
$a,
|
|
|
|
'For: empty end'
|
|
|
|
),
|
2013-01-25 18:36:16 +04:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2013-07-29 14:58:14 +04:00
|
|
|
public static function providerForInvalid()
|
|
|
|
{
|
2013-01-25 18:36:16 +04:00
|
|
|
return array(
|
2013-07-29 16:15:52 +04:00
|
|
|
array('For: {for} block1 {/for} end', 'Fenom\Error\CompileException', "Unexpected end of expression"),
|
|
|
|
array('For: {for $a=} block1 {/for} end', 'Fenom\Error\CompileException', "Unexpected end of expression"),
|
|
|
|
array('For: {for $a+1=3 to=6} block1 {/for} end', 'Fenom\Error\CompileException', "Unexpected token '+'"),
|
2014-05-06 14:22:58 +04:00
|
|
|
array(
|
|
|
|
'For: {for max($a,$b)=3 to=6} block1 {/for} end',
|
|
|
|
'Fenom\Error\CompileException',
|
|
|
|
"Unexpected token '='"
|
|
|
|
),
|
2013-07-29 16:15:52 +04:00
|
|
|
array('For: {for to=6 $a=3} block1 {/for} end', 'Fenom\Error\CompileException', "Unexpected token 'to'"),
|
2014-05-06 14:22:58 +04:00
|
|
|
array(
|
|
|
|
'For: {for index=$i $a=3 to=6} block1 {/for} end',
|
|
|
|
'Fenom\Error\CompileException',
|
|
|
|
"Unexpected token 'index'"
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'For: {for first=$i $a=3 to=6} block1 {/for} end',
|
|
|
|
'Fenom\Error\CompileException',
|
|
|
|
"Unexpected token 'first'"
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'For: {for last=$i $a=3 to=6} block1 {/for} end',
|
|
|
|
'Fenom\Error\CompileException',
|
|
|
|
"Unexpected token 'last'"
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'For: {for $a=4 to=6 unk=4} block1 {/for} end',
|
|
|
|
'Fenom\Error\CompileException',
|
|
|
|
"Unknown parameter 'unk'"
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'For: {for $a=4 to=6 step=0} block1 {/for} end',
|
|
|
|
'Fenom\Error\CompileException',
|
|
|
|
"Invalid step value"
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'For: {for $a=4 to=6} $a: {$a}, {forelse} {break} {/for} end',
|
|
|
|
'Fenom\Error\CompileException',
|
|
|
|
"Improper usage of the tag {break}"
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'For: {for $a=4 to=6} $a: {$a}, {forelse} {continue} {/for} end',
|
|
|
|
'Fenom\Error\CompileException',
|
|
|
|
"Improper usage of the tag {continue}"
|
|
|
|
),
|
2013-01-25 18:36:16 +04:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2013-07-29 14:58:14 +04:00
|
|
|
public static function providerLayersInvalid()
|
|
|
|
{
|
2013-01-25 18:36:16 +04:00
|
|
|
return array(
|
2014-05-06 14:22:58 +04:00
|
|
|
array(
|
|
|
|
'Layers: {foreach $list as $e} block1 {if 1} {foreachelse} {/if} {/foreach} end',
|
|
|
|
'Fenom\Error\CompileException',
|
|
|
|
"Unexpected tag 'foreachelse' (this tag can be used with 'foreach')"
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'Layers: {foreach $list as $e} block1 {if 1} {/foreach} {/if} end',
|
|
|
|
'Fenom\Error\CompileException',
|
|
|
|
"Unexpected closing of the tag 'foreach'"
|
|
|
|
),
|
2014-02-27 16:30:44 +04:00
|
|
|
array('Layers: {blah} end', 'Fenom\Error\CompileException', "Unexpected tag 'blah'"),
|
2014-05-06 14:22:58 +04:00
|
|
|
array(
|
|
|
|
'Layers: {for $a=4 to=6} block1 {if 1} {forelse} {/if} {/for} end',
|
|
|
|
'Fenom\Error\CompileException',
|
|
|
|
"Unexpected tag 'forelse' (this tag can be used with 'for')"
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'Layers: {for $a=4 to=6} block1 {if 1} {/for} {/if} end',
|
|
|
|
'Fenom\Error\CompileException',
|
|
|
|
"Unexpected closing of the tag 'for'"
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'Layers: {switch 1} {if 1} {case 1} {/if} {/switch} end',
|
|
|
|
'Fenom\Error\CompileException',
|
|
|
|
"Unexpected tag 'case' (this tag can be used with 'switch')"
|
|
|
|
),
|
2013-07-29 16:15:52 +04:00
|
|
|
array('Layers: {/switch} end', 'Fenom\Error\CompileException', "Unexpected closing of the tag 'switch'"),
|
|
|
|
array('Layers: {if 1} end', 'Fenom\Error\CompileException', "Unclosed tag: {if}"),
|
2013-01-25 18:36:16 +04:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2013-07-29 14:58:14 +04:00
|
|
|
public static function providerExtends()
|
|
|
|
{
|
2013-01-25 18:36:16 +04:00
|
|
|
return array(
|
2013-02-07 17:37:16 +04:00
|
|
|
array('{extends file="parent.tpl"}{block name="bk1"} block1 {/block}', "Template extended by block1"),
|
|
|
|
array('{extends "parent.tpl"}{block "bk1"} block1 {/block}', "Template extended by block1"),
|
2014-05-06 14:22:58 +04:00
|
|
|
array(
|
|
|
|
'{extends "parent.tpl"}{block "bk1"} block1 {/block}{block "bk2"} block2 {/block} garbage',
|
|
|
|
"Template extended by block1"
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'{extends file="parent.tpl"}{block "bk1"} block1 {/block}{block "bk2"} block2 {/block} garbage',
|
|
|
|
"Template multi-extended by block1"
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'{extends "parent.tpl"}{block "bk1"} block1 {/block}{block "bk2"} block2 {/block} {block "bk3"} block3 {/block} garbage',
|
|
|
|
"Template multi-extended by block1"
|
|
|
|
),
|
|
|
|
array(
|
2014-08-06 00:08:51 +04:00
|
|
|
'{extends "parent.tpl"}{set $bk = "bk3"}{block "bk1"} block1 {/block}{block "bk2"} block2 {/block} {block "$bk"} block3 {/block} garbage',
|
2014-05-06 14:22:58 +04:00
|
|
|
"Template multi-extended by block1"
|
|
|
|
),
|
2013-01-25 18:36:16 +04:00
|
|
|
);
|
2013-02-07 17:37:16 +04:00
|
|
|
}
|
2013-01-25 18:36:16 +04:00
|
|
|
|
2013-07-29 14:58:14 +04:00
|
|
|
public static function providerIsOperator()
|
|
|
|
{
|
2013-07-22 18:03:43 +04:00
|
|
|
return array(
|
|
|
|
// is {$type}
|
|
|
|
array('{if $one is int} block1 {else} block2 {/if}', 'block1'),
|
|
|
|
array('{if $one && $one is int} block1 {else} block2 {/if}', 'block1'),
|
|
|
|
array('{if $zero && $one is int} block1 {else} block2 {/if}', 'block2'),
|
|
|
|
array('{if $one is 1} block1 {else} block2 {/if}', 'block1'),
|
|
|
|
array('{if $one is 2} block1 {else} block2 {/if}', 'block2'),
|
|
|
|
array('{if $one is not int} block1 {else} block2 {/if}', 'block2'),
|
|
|
|
array('{if $one is not 1} block1 {else} block2 {/if}', 'block2'),
|
|
|
|
array('{if $one is not 2} block1 {else} block2 {/if}', 'block1'),
|
|
|
|
array('{if $one is $one} block1 {else} block2 {/if}', 'block1'),
|
2014-02-27 16:30:44 +04:00
|
|
|
array('{if $bool is true} block1 {else} block2 {/if}', 'block1'),
|
2013-07-22 18:03:43 +04:00
|
|
|
array('{if $float is float} block1 {else} block2 {/if}', 'block1'),
|
|
|
|
array('{if $float is not float} block1 {else} block2 {/if}', 'block2'),
|
|
|
|
array('{if $obj is object} block1 {else} block2 {/if}', 'block1'),
|
|
|
|
array('{if $obj is $obj} block1 {else} block2 {/if}', 'block1'),
|
|
|
|
array('{if $list is array} block1 {else} block2 {/if}', 'block1'),
|
|
|
|
array('{if $list is iterable} block1 {else} block2 {/if}', 'block1'),
|
|
|
|
array('{if $list is not scalar} block1 {else} block2 {/if}', 'block1'),
|
|
|
|
array('{if $list is $list} block1 {else} block2 {/if}', 'block1'),
|
|
|
|
array('{if $one is scalar} block1 {else} block2 {/if}', 'block1'),
|
|
|
|
// is set
|
|
|
|
array('{if $one is set} block1 {else} block2 {/if}', 'block1'),
|
|
|
|
array('{if $one is not set} block1 {else} block2 {/if}', 'block2'),
|
|
|
|
array('{if $unexists is set} block1 {else} block2 {/if}', 'block2'),
|
|
|
|
array('{if $unexists is not set} block1 {else} block2 {/if}', 'block1'),
|
|
|
|
array('{if 5 is set} block1 {else} block2 {/if}', 'block1'),
|
|
|
|
array('{if time() is set} block1 {else} block2 {/if}', 'block1'),
|
|
|
|
array('{if null is set} block1 {else} block2 {/if}', 'block2'),
|
|
|
|
array('{if 0 is empty} block1 {else} block2 {/if}', 'block1'),
|
|
|
|
array('{if "" is empty} block1 {else} block2 {/if}', 'block1'),
|
2013-09-15 16:05:18 +04:00
|
|
|
array('{if [] is empty} block1 {else} block2 {/if}', 'block1'),
|
2013-07-22 18:03:43 +04:00
|
|
|
array('{if "data" is empty} block1 {else} block2 {/if}', 'block2'),
|
|
|
|
array('{if time() is not empty} block1 {else} block2 {/if}', 'block1'),
|
|
|
|
// is empty
|
|
|
|
array('{if $one is empty} block1 {else} block2 {/if}', 'block2'),
|
|
|
|
array('{if $one is not empty} block1 {else} block2 {/if}', 'block1'),
|
|
|
|
array('{if $unexists is empty} block1 {else} block2 {/if}', 'block1'),
|
|
|
|
array('{if $unexists is not empty} block1 {else} block2 {/if}', 'block2'),
|
|
|
|
array('{if $zero is empty} block1 {else} block2 {/if}', 'block1'),
|
|
|
|
array('{if $zero is not empty} block1 {else} block2 {/if}', 'block2'),
|
|
|
|
// instaceof
|
|
|
|
array('{if $obj is StdClass} block1 {else} block2 {/if}', 'block1'),
|
|
|
|
array('{if $obj is \StdClass} block1 {else} block2 {/if}', 'block1'),
|
|
|
|
array('{if $obj is not \My\StdClass} block1 {else} block2 {/if}', 'block1'),
|
|
|
|
// event, odd
|
|
|
|
array('{if $one is odd} block1 {else} block2 {/if}', 'block1'),
|
|
|
|
array('{if $one is even} block1 {else} block2 {/if}', 'block2'),
|
2013-09-15 16:05:18 +04:00
|
|
|
array('{if ($one + 1) is even} block1 {else} block2 {/if}', 'block1'),
|
2013-07-22 18:03:43 +04:00
|
|
|
array('{if $two is even} block1 {else} block2 {/if}', 'block1'),
|
|
|
|
array('{if $two is odd} block1 {else} block2 {/if}', 'block2'),
|
2013-09-15 16:05:18 +04:00
|
|
|
array('{if ($two+1) is odd} block1 {else} block2 {/if}', 'block1'),
|
2013-07-22 18:03:43 +04:00
|
|
|
// template
|
|
|
|
array('{if "welcome.tpl" is template} block1 {else} block2 {/if}', 'block1'),
|
|
|
|
array('{if "welcome2.tpl" is template} block1 {else} block2 {/if}', 'block2'),
|
|
|
|
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2013-07-29 14:58:14 +04:00
|
|
|
public static function providerInOperator()
|
|
|
|
{
|
2013-07-22 18:03:43 +04:00
|
|
|
return array(
|
|
|
|
array('{if $one in "qwertyuiop 1"} block1 {else} block2 {/if}', 'block1'),
|
|
|
|
array('{if $one in string "qwertyuiop 1"} block1 {else} block2 {/if}', 'block1'),
|
|
|
|
array('{if $one in "qwertyuiop"} block1 {else} block2 {/if}', 'block2'),
|
|
|
|
array('{if $one not in "qwertyuiop 1"} block1 {else} block2 {/if}', 'block2'),
|
|
|
|
array('{if $one not in "qwertyuiop"} block1 {else}v block2 {/if}', 'block1'),
|
|
|
|
array('{if $one in [1, 2, 3]} block1 {else} block2 {/if}', 'block1'),
|
|
|
|
array('{if $one in list [1, 2, 3]} block1 {else} block2 {/if}', 'block1'),
|
|
|
|
array('{if $one in ["one", "two", "three"]} block1 {else} block2 {/if}', 'block2'),
|
|
|
|
array('{if $one in keys [1 => "one", 2 => "two", 3 => "three"]} block1 {else} block2 {/if}', 'block1'),
|
|
|
|
array('{if $one in $two} block1 {else} block2 {/if}', 'block2'),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2014-02-27 16:30:44 +04:00
|
|
|
public static function providerInOperatorInvalid()
|
|
|
|
{
|
|
|
|
return array(
|
|
|
|
array('{$one not all 3}', 'Fenom\Error\CompileException', "Unexpected token 'not'"),
|
|
|
|
array('{$one in all}', 'Fenom\Error\CompileException', "Unexpected token 'all'"),
|
|
|
|
array('{$one in string [1,2,3]}', 'Fenom\Error\CompileException', "Can not use string operation for array"),
|
|
|
|
array('{$one in list "blah"}', 'Fenom\Error\CompileException', "Can not use array operation for string"),
|
|
|
|
array('{$one in true}', 'Fenom\Error\CompileException', "Unexpected token 'true'"),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function providerConcat()
|
|
|
|
{
|
2013-08-03 18:56:17 +04:00
|
|
|
return array(
|
|
|
|
array('{"string" ~ $one ~ up("end")}', "string1END"),
|
|
|
|
array('{"string" ~ $one++ ~ "end"}', "string1end"),
|
|
|
|
array('{"string" ~ ++$one ~ "end"}', "string2end"),
|
|
|
|
array('{"string" ~ "one" ~ "end"}', "stringoneend"),
|
|
|
|
array('{"string" ~ 1 ~ "end"}', "string1end"),
|
2014-06-08 23:50:43 +04:00
|
|
|
array('{$one ~= "string"} is {$one}', "1string is 1string"),
|
2013-08-03 18:56:17 +04:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2014-02-27 16:30:44 +04:00
|
|
|
public static function providerAccessor()
|
|
|
|
{
|
2013-08-11 19:55:30 +04:00
|
|
|
return array(
|
|
|
|
array('{$.get.one}', 'get1'),
|
|
|
|
array('{$.post.one}', 'post1'),
|
|
|
|
array('{$.request.one}', 'request1'),
|
|
|
|
array('{$.session.one}', 'session1'),
|
|
|
|
array('{$.files.one}', 'files1'),
|
|
|
|
array('{$.globals.one}', 'globals1'),
|
|
|
|
array('{$.cookie.one}', 'cookie1'),
|
|
|
|
array('{$.server.one}', 'server1'),
|
|
|
|
array('{$.const.PHP_EOL}', PHP_EOL),
|
2014-02-27 16:30:44 +04:00
|
|
|
array('{$.const.MY}', ''),
|
2013-08-11 19:55:30 +04:00
|
|
|
array('{$.version}', Fenom::VERSION),
|
2013-08-29 11:29:34 +04:00
|
|
|
array('{"string"|append:"_":$.get.one}', 'string_get1'),
|
2013-08-11 19:55:30 +04:00
|
|
|
array('{$.get.one?}', '1'),
|
|
|
|
array('{$.get.one is set}', '1'),
|
|
|
|
array('{$.get.two is empty}', '1'),
|
2013-09-15 16:05:18 +04:00
|
|
|
array('{$.version}', Fenom::VERSION),
|
|
|
|
array('{$.tpl?}', '1'),
|
|
|
|
array('{$.tpl.name}', 'runtime.tpl'),
|
|
|
|
array('{$.tpl.time}', '0'),
|
|
|
|
array('{$.tpl.schema}', ''),
|
2013-08-11 19:55:30 +04:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2014-02-27 16:30:44 +04:00
|
|
|
public static function providerAccessorInvalid()
|
|
|
|
{
|
|
|
|
return array(
|
|
|
|
array('{$.nope.one}', 'Fenom\Error\CompileException', "Unexpected token 'nope'"),
|
|
|
|
array('{$.get.one}', 'Fenom\Error\SecurityException', 'Accessor are disabled', Fenom::DENY_ACCESSOR),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function providerStatic()
|
|
|
|
{
|
2014-01-28 21:24:47 +04:00
|
|
|
return array(
|
2014-04-17 23:22:50 +04:00
|
|
|
// array('{Fenom\TemplateTest::multi x=3 y=4}', '12'),
|
2014-01-28 21:24:47 +04:00
|
|
|
array('{Fenom\TemplateTest::multi(3,4)}', '12'),
|
|
|
|
array('{12 + Fenom\TemplateTest::multi(3,4)}', '24'),
|
|
|
|
array('{12 + 3|Fenom\TemplateTest::multi:4}', '24'),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2014-02-27 16:30:44 +04:00
|
|
|
public function providerStaticInvalid()
|
|
|
|
{
|
2014-01-28 21:24:47 +04:00
|
|
|
return array(
|
2014-05-06 14:22:58 +04:00
|
|
|
array(
|
|
|
|
'{Fenom\TemplateTest::multi x=3 y=4}',
|
|
|
|
'Fenom\Error\SecurityException',
|
|
|
|
"Static methods are disabled",
|
|
|
|
Fenom::DENY_STATICS
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'{Fenom\TemplateTest::multi(3,4)}',
|
|
|
|
'Fenom\Error\SecurityException',
|
|
|
|
"Static methods are disabled",
|
|
|
|
Fenom::DENY_STATICS
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'{12 + Fenom\TemplateTest::multi(3,4)}',
|
|
|
|
'Fenom\Error\SecurityException',
|
|
|
|
"Static methods are disabled",
|
|
|
|
Fenom::DENY_STATICS
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'{12 + 3|Fenom\TemplateTest::multi:4}',
|
|
|
|
'Fenom\Error\SecurityException',
|
|
|
|
"Static methods are disabled",
|
|
|
|
Fenom::DENY_STATICS
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'{Fenom\TemplateTest::multi_invalid x=3 y=4}',
|
|
|
|
'Fenom\Error\CompileException',
|
|
|
|
'Method Fenom\TemplateTest::multi_invalid doesn\'t exist'
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'{Fenom\TemplateTest::multi_invalid(3,4)}',
|
|
|
|
'Fenom\Error\CompileException',
|
|
|
|
'Method Fenom\TemplateTest::multi_invalid doesn\'t exist'
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'{12 + Fenom\TemplateTest::multi_invalid(3,4)}',
|
|
|
|
'Fenom\Error\CompileException',
|
|
|
|
'Method Fenom\TemplateTest::multi_invalid doesn\'t exist'
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'{12 + 3|Fenom\TemplateTest::multi_invalid:4}',
|
|
|
|
'Fenom\Error\CompileException',
|
|
|
|
'Method Fenom\TemplateTest::multi_invalid doesn\'t exist'
|
|
|
|
),
|
2014-01-28 21:24:47 +04:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2014-06-28 16:38:50 +04:00
|
|
|
/**
|
|
|
|
* @group sb
|
|
|
|
*/
|
2014-06-28 22:15:30 +04:00
|
|
|
public function _testSandbox()
|
2013-07-29 14:58:14 +04:00
|
|
|
{
|
2013-07-22 18:03:43 +04:00
|
|
|
try {
|
2014-05-06 14:22:58 +04:00
|
|
|
var_dump(
|
2014-06-28 16:38:50 +04:00
|
|
|
$this->fenom->compileCode(
|
2014-08-06 01:17:21 +04:00
|
|
|
'{add $a[] = 5}'
|
2014-05-06 14:22:58 +04:00
|
|
|
)->getBody()
|
|
|
|
);
|
2013-07-29 14:58:14 +04:00
|
|
|
} catch (\Exception $e) {
|
|
|
|
print_r($e->getMessage() . "\n" . $e->getTraceAsString());
|
2014-02-27 16:30:44 +04:00
|
|
|
while ($e->getPrevious()) {
|
2014-01-28 21:24:47 +04:00
|
|
|
$e = $e->getPrevious();
|
2014-06-28 21:08:20 +04:00
|
|
|
print_r("\n\n" . $e->getMessage() . " in {$e->getFile()}:{$e->getLine()}\n" . $e->getTraceAsString());
|
2014-01-28 21:24:47 +04:00
|
|
|
}
|
2013-07-22 18:03:43 +04:00
|
|
|
}
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
2014-02-27 16:30:44 +04:00
|
|
|
/**
|
|
|
|
* @dataProvider providerScalars
|
|
|
|
*/
|
|
|
|
public function testScalars($code, $result)
|
|
|
|
{
|
|
|
|
$this->exec("{" . $code . "}", $this->values, $result);
|
|
|
|
}
|
|
|
|
|
2013-01-25 18:36:16 +04:00
|
|
|
/**
|
|
|
|
* @dataProvider providerVars
|
|
|
|
*/
|
2013-07-29 14:58:14 +04:00
|
|
|
public function testVars($code, $vars, $result)
|
|
|
|
{
|
2013-01-25 18:36:16 +04:00
|
|
|
$this->exec($code, $vars, $result);
|
2013-07-29 14:58:14 +04:00
|
|
|
}
|
2013-01-25 18:36:16 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider providerVarsInvalid
|
|
|
|
*/
|
2013-07-29 14:58:14 +04:00
|
|
|
public function testVarsInvalid($code, $exception, $message, $options = 0)
|
|
|
|
{
|
2013-01-25 18:36:16 +04:00
|
|
|
$this->execError($code, $exception, $message, $options);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider providerModifiers
|
|
|
|
*/
|
2013-07-29 14:58:14 +04:00
|
|
|
public function testModifiers($code, $vars, $result)
|
|
|
|
{
|
2013-01-25 18:36:16 +04:00
|
|
|
$this->exec($code, $vars, $result);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider providerModifiersInvalid
|
|
|
|
*/
|
2013-07-29 14:58:14 +04:00
|
|
|
public function testModifiersInvalid($code, $exception, $message, $options = 0)
|
|
|
|
{
|
2013-01-25 18:36:16 +04:00
|
|
|
$this->execError($code, $exception, $message, $options);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-03-17 14:37:23 +04:00
|
|
|
* @group expression
|
2013-01-25 18:36:16 +04:00
|
|
|
* @dataProvider providerExpressions
|
|
|
|
*/
|
2013-07-29 14:58:14 +04:00
|
|
|
public function testExpressions($code, $vars, $result)
|
|
|
|
{
|
2013-01-25 18:36:16 +04:00
|
|
|
$this->exec($code, $vars, $result);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider providerExpressionsInvalid
|
|
|
|
*/
|
2013-07-29 14:58:14 +04:00
|
|
|
public function testExpressionsInvalid($code, $exception, $message, $options = 0)
|
|
|
|
{
|
2013-01-25 18:36:16 +04:00
|
|
|
$this->execError($code, $exception, $message, $options);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-03-18 00:35:20 +04:00
|
|
|
* @group include
|
2013-01-25 18:36:16 +04:00
|
|
|
* @dataProvider providerInclude
|
|
|
|
*/
|
2013-09-14 11:24:23 +04:00
|
|
|
public function testInclude($code, $vars, $result, $options = 0)
|
2013-07-29 14:58:14 +04:00
|
|
|
{
|
2013-09-14 11:24:23 +04:00
|
|
|
$this->exec($code, $vars, $result, $options);
|
2013-01-25 18:36:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider providerIncludeInvalid
|
2014-01-20 11:54:28 +04:00
|
|
|
* @group testIncludeInvalid
|
2013-01-25 18:36:16 +04:00
|
|
|
*/
|
2013-07-29 14:58:14 +04:00
|
|
|
public function testIncludeInvalid($code, $exception, $message, $options = 0)
|
|
|
|
{
|
2013-01-25 18:36:16 +04:00
|
|
|
$this->execError($code, $exception, $message, $options);
|
|
|
|
}
|
|
|
|
|
2013-09-14 11:24:23 +04:00
|
|
|
/**
|
|
|
|
* @group insert
|
|
|
|
* @dataProvider providerInsert
|
|
|
|
*/
|
|
|
|
public function testInsert($code, $vars, $result)
|
|
|
|
{
|
2013-09-14 19:55:53 +04:00
|
|
|
$this->values = $vars;
|
2013-09-15 16:05:18 +04:00
|
|
|
$this->tpl("insert.tpl", $code);
|
|
|
|
$tpl = $this->fenom->getTemplate('insert.tpl');
|
|
|
|
$this->assertSame($result, $tpl->fetch($vars));
|
|
|
|
$this->assertTrue($tpl->isValid());
|
2013-09-14 11:24:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @group insert
|
|
|
|
* @dataProvider providerInsertInvalid
|
|
|
|
*/
|
|
|
|
public function testInsertInvalid($code, $exception, $message, $options = 0)
|
|
|
|
{
|
|
|
|
$this->execError($code, $exception, $message, $options);
|
|
|
|
}
|
|
|
|
|
2013-01-25 18:36:16 +04:00
|
|
|
/**
|
|
|
|
* @dataProvider providerIf
|
2013-07-20 21:25:32 +04:00
|
|
|
* @group test-if
|
2013-01-25 18:36:16 +04:00
|
|
|
*/
|
2013-07-29 14:58:14 +04:00
|
|
|
public function testIf($code, $vars, $result, $options = 0)
|
|
|
|
{
|
2013-07-20 21:25:32 +04:00
|
|
|
$this->exec($code, $vars, $result, $options);
|
2013-01-25 18:36:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider providerIfInvalid
|
|
|
|
*/
|
2013-07-29 14:58:14 +04:00
|
|
|
public function testIfInvalid($code, $exception, $message, $options = 0)
|
|
|
|
{
|
2013-01-25 18:36:16 +04:00
|
|
|
$this->execError($code, $exception, $message, $options);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider providerCreateVar
|
|
|
|
*/
|
2013-07-29 14:58:14 +04:00
|
|
|
public function testCreateVar($code, $vars, $result)
|
|
|
|
{
|
2013-01-25 18:36:16 +04:00
|
|
|
$this->exec($code, $vars, $result);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider providerCreateVarInvalid
|
|
|
|
*/
|
2013-07-29 14:58:14 +04:00
|
|
|
public function testCreateVarInvalid($code, $exception, $message, $options = 0)
|
|
|
|
{
|
2013-01-25 18:36:16 +04:00
|
|
|
$this->execError($code, $exception, $message, $options);
|
|
|
|
}
|
|
|
|
|
2014-06-28 21:08:20 +04:00
|
|
|
/**
|
|
|
|
* @dataProvider providerArrays
|
|
|
|
* @group arrays
|
|
|
|
*/
|
|
|
|
public function testArrays($code, $vars)
|
|
|
|
{
|
|
|
|
$v = $this->getVars();
|
|
|
|
$v['vars'] = $vars;
|
|
|
|
$this->exec($code.'{if $arr === $vars}equal{/if}', $v, 'equal');
|
|
|
|
}
|
|
|
|
|
2014-06-28 22:15:30 +04:00
|
|
|
/**
|
|
|
|
* @dataProvider providerUnset
|
|
|
|
* @group unset
|
|
|
|
*/
|
|
|
|
public function testUnset($code, $result)
|
|
|
|
{
|
|
|
|
$this->exec($code, $this->getVars(), $result);
|
|
|
|
}
|
|
|
|
|
2014-06-28 21:08:20 +04:00
|
|
|
/**
|
|
|
|
* @dataProvider providerCreateVarInvalid
|
|
|
|
*/
|
|
|
|
// public function testCreateVarInvalid($code, $exception, $message, $options = 0)
|
|
|
|
// {
|
|
|
|
// $this->execError($code, $exception, $message, $options);
|
|
|
|
// }
|
|
|
|
|
2013-02-07 17:37:16 +04:00
|
|
|
/**
|
|
|
|
* @group ternary
|
|
|
|
* @dataProvider providerTernary
|
|
|
|
*/
|
2013-07-29 14:58:14 +04:00
|
|
|
public function testTernary($code, $vars, $result = 'right')
|
|
|
|
{
|
|
|
|
$this->exec(__FUNCTION__ . ": $code end", $vars, __FUNCTION__ . ": $result end");
|
2013-02-07 17:37:16 +04:00
|
|
|
}
|
|
|
|
|
2013-01-25 18:36:16 +04:00
|
|
|
/**
|
|
|
|
* @dataProvider providerForeach
|
|
|
|
*/
|
2013-07-29 14:58:14 +04:00
|
|
|
public function testForeach($code, $vars, $result)
|
|
|
|
{
|
2013-01-25 18:36:16 +04:00
|
|
|
$this->exec($code, $vars, $result);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider providerForeachInvalid
|
|
|
|
*/
|
2013-07-29 14:58:14 +04:00
|
|
|
public function testForeachInvalid($code, $exception, $message, $options = 0)
|
|
|
|
{
|
2013-01-25 18:36:16 +04:00
|
|
|
$this->execError($code, $exception, $message, $options);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider providerFor
|
|
|
|
*/
|
2013-07-29 14:58:14 +04:00
|
|
|
public function testFor($code, $vars, $result)
|
|
|
|
{
|
2013-01-25 18:36:16 +04:00
|
|
|
$this->exec($code, $vars, $result);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider providerForInvalid
|
|
|
|
*/
|
2013-07-29 14:58:14 +04:00
|
|
|
public function testForInvalid($code, $exception, $message, $options = 0)
|
|
|
|
{
|
2013-01-25 18:36:16 +04:00
|
|
|
$this->execError($code, $exception, $message, $options);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-05-12 00:36:50 +04:00
|
|
|
* @group testIgnores
|
2013-02-07 17:37:16 +04:00
|
|
|
* @dataProvider providerIgnores
|
2013-01-25 18:36:16 +04:00
|
|
|
*/
|
2013-07-29 14:58:14 +04:00
|
|
|
public function testIgnores($code, $vars, $result)
|
|
|
|
{
|
2013-01-25 18:36:16 +04:00
|
|
|
$this->exec($code, $vars, $result);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-09-02 17:40:58 +04:00
|
|
|
* @group switch
|
2013-01-25 18:36:16 +04:00
|
|
|
* @dataProvider providerSwitch
|
|
|
|
*/
|
2013-07-29 14:58:14 +04:00
|
|
|
public function testSwitch($code, $vars, $result)
|
|
|
|
{
|
2013-01-25 18:36:16 +04:00
|
|
|
$this->exec($code, $vars, $result);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-09-02 17:40:58 +04:00
|
|
|
* @group switch-bad
|
2013-01-25 18:36:16 +04:00
|
|
|
* @dataProvider providerSwitchInvalid
|
|
|
|
*/
|
2013-07-29 14:58:14 +04:00
|
|
|
public function testSwitchInvalid($code, $exception, $message, $options = 0)
|
|
|
|
{
|
2013-01-25 18:36:16 +04:00
|
|
|
$this->execError($code, $exception, $message, $options);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider providerWhile
|
|
|
|
*/
|
2013-07-29 14:58:14 +04:00
|
|
|
public function testWhile($code, $vars, $result)
|
|
|
|
{
|
2013-01-25 18:36:16 +04:00
|
|
|
$this->exec($code, $vars, $result);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider providerWhileInvalid
|
|
|
|
*/
|
2013-07-29 14:58:14 +04:00
|
|
|
public function testWhileInvalid($code, $exception, $message, $options = 0)
|
|
|
|
{
|
2013-01-25 18:36:16 +04:00
|
|
|
$this->execError($code, $exception, $message, $options);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider providerLayersInvalid
|
|
|
|
*/
|
2013-07-29 14:58:14 +04:00
|
|
|
public function testLayersInvalid($code, $exception, $message, $options = 0)
|
|
|
|
{
|
2013-01-25 18:36:16 +04:00
|
|
|
$this->execError($code, $exception, $message, $options);
|
|
|
|
}
|
2013-07-22 18:03:43 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @group is_operator
|
|
|
|
* @dataProvider providerIsOperator
|
|
|
|
*/
|
2013-07-29 14:58:14 +04:00
|
|
|
public function testIsOperator($code, $result)
|
|
|
|
{
|
2013-07-22 18:03:43 +04:00
|
|
|
$this->exec($code, self::getVars(), $result);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @group in_operator
|
|
|
|
* @dataProvider providerInOperator
|
|
|
|
*/
|
2013-07-29 14:58:14 +04:00
|
|
|
public function testInOperator($code, $result)
|
|
|
|
{
|
2013-07-22 18:03:43 +04:00
|
|
|
$this->exec($code, self::getVars(), $result);
|
|
|
|
}
|
2013-08-03 18:56:17 +04:00
|
|
|
|
2014-02-27 16:30:44 +04:00
|
|
|
/**
|
|
|
|
* @group in_operator_invalid
|
|
|
|
* @dataProvider providerInOperatorInvalid
|
|
|
|
*/
|
|
|
|
public function testInOperatorInvalid($code, $exception, $message, $options = 0)
|
|
|
|
{
|
|
|
|
$this->execError($code, $exception, $message, $options);
|
|
|
|
}
|
|
|
|
|
2013-08-03 18:56:17 +04:00
|
|
|
/**
|
|
|
|
* @dataProvider providerConcat
|
2014-06-08 23:50:43 +04:00
|
|
|
* @group testConcat
|
2013-08-03 18:56:17 +04:00
|
|
|
*/
|
|
|
|
public function testConcat($code, $result)
|
|
|
|
{
|
|
|
|
$this->exec($code, self::getVars(), $result);
|
|
|
|
}
|
2013-08-11 19:55:30 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @group accessor
|
|
|
|
* @dataProvider providerAccessor
|
|
|
|
*/
|
|
|
|
public function testAccessor($code, $result)
|
|
|
|
{
|
|
|
|
$this->exec($code, self::getVars(), $result);
|
|
|
|
}
|
2014-01-28 21:24:47 +04:00
|
|
|
|
2014-02-27 16:30:44 +04:00
|
|
|
/**
|
|
|
|
* @group accessor
|
|
|
|
* @dataProvider providerAccessorInvalid
|
|
|
|
*/
|
|
|
|
public function testAccessorInvalid($code, $exception, $message, $options = 0)
|
|
|
|
{
|
|
|
|
$this->execError($code, $exception, $message, $options);
|
|
|
|
}
|
|
|
|
|
2014-01-28 21:24:47 +04:00
|
|
|
/**
|
|
|
|
* @group static
|
|
|
|
* @dataProvider providerStatic
|
|
|
|
*/
|
|
|
|
public function testStatic($code, $result)
|
|
|
|
{
|
|
|
|
$this->exec($code, self::getVars(), $result, true);
|
|
|
|
}
|
|
|
|
|
2014-02-28 18:32:59 +04:00
|
|
|
/**
|
|
|
|
* Helper
|
|
|
|
* @param $x
|
|
|
|
* @param int $y
|
|
|
|
* @return mixed
|
|
|
|
*/
|
2014-02-27 16:30:44 +04:00
|
|
|
public static function multi($x, $y = 42)
|
|
|
|
{
|
2014-01-28 21:24:47 +04:00
|
|
|
return $x * $y;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @group static-invalid
|
|
|
|
* @dataProvider providerStaticInvalid
|
|
|
|
*/
|
|
|
|
public function testStaticInvalid($code, $exception, $message, $options = 0)
|
|
|
|
{
|
|
|
|
$this->execError($code, $exception, $message, $options);
|
|
|
|
}
|
2013-01-25 18:36:16 +04:00
|
|
|
}
|
|
|
|
|