mirror of
https://github.com/espocrm/espocrm.git
synced 2026-06-28 06:56:05 +00:00
formula: return last expression
This commit is contained in:
@@ -29,17 +29,21 @@
|
||||
|
||||
namespace Espo\Core\Formula\Functions;
|
||||
|
||||
use Espo\Core\Formula\{
|
||||
Functions\BaseFunction,
|
||||
ArgumentList,
|
||||
};
|
||||
use Espo\Core\Formula\ArgumentList;
|
||||
|
||||
/**
|
||||
* @noinspection PhpUnused
|
||||
*/
|
||||
class BundleType extends BaseFunction
|
||||
{
|
||||
public function process(ArgumentList $args)
|
||||
{
|
||||
$value = null;
|
||||
|
||||
foreach ($args as $item) {
|
||||
$this->evaluate($item);
|
||||
$value = $this->evaluate($item);
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1620,4 +1620,74 @@ class EvaluatorTest extends TestCase
|
||||
|
||||
$this->assertEquals("<p><strong>test</strong></p>\n", $result);
|
||||
}
|
||||
|
||||
public function testLastExpressionEvaluation1(): void
|
||||
{
|
||||
$expression = "\$a = 1; \$b = \$a + 1; \$b;";
|
||||
|
||||
/** @noinspection PhpUnhandledExceptionInspection */
|
||||
$result = $this->evaluator->process($expression);
|
||||
|
||||
$this->assertEquals(2, $result);
|
||||
}
|
||||
|
||||
public function testLastExpressionEvaluation2(): void
|
||||
{
|
||||
$expression = "\$a = 1; \$b = \$a + 1; \$b";
|
||||
|
||||
/** @noinspection PhpUnhandledExceptionInspection */
|
||||
$result = $this->evaluator->process($expression);
|
||||
|
||||
$this->assertEquals(2, $result);
|
||||
}
|
||||
|
||||
public function testLastExpressionEvaluation3(): void
|
||||
{
|
||||
$expression = "\$a = 1; \$a + 1;";
|
||||
|
||||
/** @noinspection PhpUnhandledExceptionInspection */
|
||||
$result = $this->evaluator->process($expression);
|
||||
|
||||
$this->assertEquals(2, $result);
|
||||
}
|
||||
|
||||
public function testLastExpressionEvaluation4(): void
|
||||
{
|
||||
$expression = "\$a = 1; \$b = \$a + 1;";
|
||||
|
||||
/** @noinspection PhpUnhandledExceptionInspection */
|
||||
$result = $this->evaluator->process($expression);
|
||||
|
||||
$this->assertEquals(2, $result);
|
||||
}
|
||||
|
||||
public function testLastExpressionEvaluation5(): void
|
||||
{
|
||||
$expression = "\$c = (\$a = 1; \$b = \$a + 1;); \$c;";
|
||||
|
||||
/** @noinspection PhpUnhandledExceptionInspection */
|
||||
$result = $this->evaluator->process($expression);
|
||||
|
||||
$this->assertEquals(2, $result);
|
||||
}
|
||||
|
||||
public function testLastExpressionEvaluationNull1(): void
|
||||
{
|
||||
$expression = "null";
|
||||
|
||||
/** @noinspection PhpUnhandledExceptionInspection */
|
||||
$result = $this->evaluator->process($expression);
|
||||
|
||||
$this->assertEquals(null, $result);
|
||||
}
|
||||
|
||||
public function testLastExpressionEvaluationNull2(): void
|
||||
{
|
||||
$expression = "";
|
||||
|
||||
/** @noinspection PhpUnhandledExceptionInspection */
|
||||
$result = $this->evaluator->process($expression);
|
||||
|
||||
$this->assertEquals(null, $result);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user