forked from ProcessMaker/processmaker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFEELFormulasTest.php
More file actions
65 lines (56 loc) · 1.96 KB
/
FEELFormulasTest.php
File metadata and controls
65 lines (56 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
namespace Tests\Feature;
use ProcessMaker\Exception\ExpressionFailedException;
use ProcessMaker\Exception\ScriptLanguageNotSupported;
use ProcessMaker\Exception\SyntaxErrorException;
use ProcessMaker\Models\FormalExpression;
use Tests\TestCase;
/**
* Test friendly enough expression language evaluator working together with mustache expressions
*/
class FEELFormulasTest extends TestCase
{
/**
* Test to use an unsupported language
*/
public function testUnsupportedLanguage()
{
$this->expectException(ScriptLanguageNotSupported::class);
$expresion = new FormalExpression();
$expresion->setLanguage('application/x-unsupported');
$expresion->setBody('"hello world"');
$response = $expresion([]);
}
/**
* Test formulas
*/
public function testCalculatedFields()
{
$expresion = new FormalExpression();
$expresion->setLanguage('FEEL');
// When calculation is true
$expresion->setBody('Height == 2 * Weight');
$response = $expresion(['Height' => 120, 'Weight' => 60]);
$this->assertSame(true, $response);
// When calculation is false
$expresion->setBody('Height == 1 * Weight');
$response = $expresion(['Height' => 120, 'Weight' => 60]);
$this->assertSame(false, $response);
}
/**
* Test formulas with strings concatenation
*/
public function testConcatenatedFormula()
{
$expresion = new FormalExpression();
$expresion->setLanguage('FEEL');
// When calculation is true
$expresion->setBody("Height == 'cm: ' ~ (2 * Weight)");
$response = $expresion(['Height' => 'cm: 120', 'Weight' => 60]);
$this->assertSame(true, $response);
// When calculation is false
$expresion->setBody("Height == 'cm: ' ~ (2 * Weight)");
$response = $expresion(['Height' => 'km: 120', 'Weight' => 60]);
$this->assertSame(false, $response);
}
}