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
|
<?php
namespace Civi\Test\Api4\Action;
use Civi\Api4\MockBasicEntity;
use Civi\Test\Api4\UnitTestCase;
/**
* @group headless
*/
class EvaluateConditionTest extends UnitTestCase {
public function testEvaluateCondition() {
$action = MockBasicEntity::get();
$reflection = new \ReflectionClass($action);
$method = $reflection->getMethod('evaluateCondition');
$method->setAccessible(TRUE);
$data = [
'nada' => 0,
'uno' => 1,
'dos' => 2,
'apple' => 'red',
'banana' => 'yellow',
'values' => ['one' => 1, 'two' => 2, 'three' => 3],
];
$this->assertFalse($method->invoke($action, '$uno > $dos', $data));
$this->assertTrue($method->invoke($action, '$uno < $dos', $data));
$this->assertTrue($method->invoke($action, '$apple == "red" && $banana != "red"', $data));
$this->assertFalse($method->invoke($action, '$apple == "red" && $banana != "yellow"', $data));
$this->assertTrue($method->invoke($action, '$values.one == $uno', $data));
$this->assertTrue($method->invoke($action, '$values.one + $dos == $values.three', $data));
$this->assertTrue($method->invoke($action, 'empty($nada)', $data));
$this->assertFalse($method->invoke($action, 'empty($values)', $data));
}
}
|