Commit | Line | Data |
---|---|---|
19b53e5b C |
1 | <?php |
2 | ||
380f3545 TO |
3 | /* |
4 | +--------------------------------------------------------------------+ | |
7d61e75f | 5 | | Copyright CiviCRM LLC. All rights reserved. | |
380f3545 | 6 | | | |
7d61e75f TO |
7 | | This work is published under the GNU AGPLv3 license with some | |
8 | | permitted exceptions and without any warranty. For full license | | |
9 | | and copyright information, see https://civicrm.org/licensing | | |
380f3545 TO |
10 | +--------------------------------------------------------------------+ |
11 | */ | |
12 | ||
13 | /** | |
14 | * | |
15 | * @package CRM | |
ca5cec67 | 16 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
380f3545 TO |
17 | * $Id$ |
18 | * | |
19 | */ | |
20 | ||
21 | ||
19b53e5b C |
22 | namespace api\v4\Action; |
23 | ||
24 | use Civi\Api4\MockBasicEntity; | |
25 | use api\v4\UnitTestCase; | |
26 | ||
27 | /** | |
28 | * @group headless | |
29 | */ | |
30 | class EvaluateConditionTest extends UnitTestCase { | |
31 | ||
32 | public function testEvaluateCondition() { | |
33 | $action = MockBasicEntity::get(); | |
34 | $reflection = new \ReflectionClass($action); | |
35 | $method = $reflection->getMethod('evaluateCondition'); | |
36 | $method->setAccessible(TRUE); | |
37 | ||
38 | $data = [ | |
39 | 'nada' => 0, | |
40 | 'uno' => 1, | |
41 | 'dos' => 2, | |
42 | 'apple' => 'red', | |
43 | 'banana' => 'yellow', | |
44 | 'values' => ['one' => 1, 'two' => 2, 'three' => 3], | |
45 | ]; | |
46 | ||
47 | $this->assertFalse($method->invoke($action, '$uno > $dos', $data)); | |
48 | $this->assertTrue($method->invoke($action, '$uno < $dos', $data)); | |
49 | $this->assertTrue($method->invoke($action, '$apple == "red" && $banana != "red"', $data)); | |
50 | $this->assertFalse($method->invoke($action, '$apple == "red" && $banana != "yellow"', $data)); | |
51 | $this->assertTrue($method->invoke($action, '$values.one == $uno', $data)); | |
52 | $this->assertTrue($method->invoke($action, '$values.one + $dos == $values.three', $data)); | |
53 | $this->assertTrue($method->invoke($action, 'empty($nada)', $data)); | |
54 | $this->assertFalse($method->invoke($action, 'empty($values)', $data)); | |
55 | } | |
56 | ||
57 | } |