2013-07-11 14:14:34 +04:00
|
|
|
<?php
|
|
|
|
namespace Fenom;
|
|
|
|
|
2013-07-29 14:58:14 +04:00
|
|
|
class FunctionsTest extends TestCase
|
|
|
|
{
|
2013-07-11 14:14:34 +04:00
|
|
|
|
2013-07-29 14:58:14 +04:00
|
|
|
const FUNCTION_ARGUMENT_CONSTANT = 1;
|
2013-07-11 14:14:34 +04:00
|
|
|
|
2013-07-29 14:58:14 +04:00
|
|
|
public static function functionSum($of = array())
|
|
|
|
{
|
|
|
|
return array_sum($of);
|
|
|
|
}
|
2013-07-11 14:14:34 +04:00
|
|
|
|
2013-07-29 14:58:14 +04:00
|
|
|
public static function functionPow($a, $n = 2)
|
|
|
|
{
|
|
|
|
return pow($a, $n);
|
|
|
|
}
|
2013-07-11 14:14:34 +04:00
|
|
|
|
2013-07-29 14:58:14 +04:00
|
|
|
public static function functionInc($a, $i = self::FUNCTION_ARGUMENT_CONSTANT)
|
|
|
|
{
|
|
|
|
return $a + $i;
|
|
|
|
}
|
2013-07-11 14:14:34 +04:00
|
|
|
|
2013-07-29 14:58:14 +04:00
|
|
|
public function setUp()
|
|
|
|
{
|
2013-07-11 14:14:34 +04:00
|
|
|
parent::setUp();
|
2013-07-29 14:58:14 +04:00
|
|
|
$this->fenom->addFunctionSmart('sum', __CLASS__ . '::functionSum');
|
|
|
|
$this->fenom->addFunctionSmart('pow', __CLASS__ . '::functionPow');
|
|
|
|
$this->fenom->addFunctionSmart('inc', __CLASS__ . '::functionInc');
|
2013-07-11 14:14:34 +04:00
|
|
|
|
2013-07-29 14:58:14 +04:00
|
|
|
$this->tpl('function_params_scalar.tpl', '{pow a=2 n=3}');
|
|
|
|
$this->tpl('function_params_dynamic.tpl', '{pow a=$a n=$n}');
|
|
|
|
$this->tpl('function_default_param_scalar.tpl', '{pow a=2}');
|
|
|
|
$this->tpl('function_default_param_empty_array.tpl', '{sum}');
|
|
|
|
$this->tpl('function_default_param_const.tpl', '{inc a=1}');
|
|
|
|
$this->tpl('function_array_param.tpl', '{sum of=[1, 2, 3, 4, 5]}');
|
|
|
|
$this->tpl('function_array_param_pos.tpl', '{sum [1, 2, 3, 4, 5]}');
|
|
|
|
}
|
2013-07-11 14:14:34 +04:00
|
|
|
|
2013-07-29 14:58:14 +04:00
|
|
|
public function testFunctionWithParams()
|
|
|
|
{
|
2013-07-11 14:14:34 +04:00
|
|
|
$output = $this->fenom->fetch('function_params_scalar.tpl');
|
2013-07-29 14:58:14 +04:00
|
|
|
$this->assertEquals('8', $output);
|
2013-07-11 14:14:34 +04:00
|
|
|
}
|
|
|
|
|
2013-07-29 14:58:14 +04:00
|
|
|
public function testFunctionWithDynamicParams()
|
|
|
|
{
|
2013-07-11 14:14:34 +04:00
|
|
|
$output = $this->fenom->fetch('function_params_dynamic.tpl', array('a' => 3, 'n' => 4));
|
2013-07-29 14:58:14 +04:00
|
|
|
$this->assertEquals('81', $output);
|
2013-07-11 14:14:34 +04:00
|
|
|
}
|
|
|
|
|
2013-07-29 14:58:14 +04:00
|
|
|
public function testFunctionWithDefaultParamScalar()
|
|
|
|
{
|
|
|
|
$output = $this->fenom->fetch('function_default_param_scalar.tpl');
|
|
|
|
$this->assertEquals('4', $output);
|
|
|
|
}
|
2013-07-11 14:14:34 +04:00
|
|
|
|
2013-07-29 14:58:14 +04:00
|
|
|
public function testFunctionWithDefaultParamArray()
|
|
|
|
{
|
|
|
|
$output = $this->fenom->fetch('function_default_param_empty_array.tpl');
|
|
|
|
$this->assertEquals('0', $output);
|
|
|
|
}
|
2013-07-11 14:14:34 +04:00
|
|
|
|
2013-07-29 14:58:14 +04:00
|
|
|
public function testFunctionWithDefaultParamConst()
|
|
|
|
{
|
|
|
|
$output = $this->fenom->fetch('function_default_param_const.tpl');
|
|
|
|
$this->assertEquals('2', $output);
|
|
|
|
}
|
2013-07-11 14:14:34 +04:00
|
|
|
|
2013-07-29 14:58:14 +04:00
|
|
|
public function testFunctionWithArrayNamedParam()
|
|
|
|
{
|
|
|
|
$output = $this->fenom->fetch('function_array_param.tpl');
|
|
|
|
$this->assertEquals('15', $output);
|
|
|
|
}
|
2013-07-11 14:14:34 +04:00
|
|
|
|
2013-07-29 14:58:14 +04:00
|
|
|
public function testFunctionWithArrayPositionalParam()
|
|
|
|
{
|
|
|
|
$output = $this->fenom->fetch('function_array_param_pos.tpl');
|
|
|
|
$this->assertEquals('15', $output);
|
|
|
|
}
|
2013-07-11 16:13:11 +04:00
|
|
|
|
2013-07-11 14:14:34 +04:00
|
|
|
}
|