4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC. All rights reserved. |
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 |
10 +--------------------------------------------------------------------+
16 * @copyright CiviCRM LLC https://civicrm.org/licensing
22 namespace api\v
4\Action
;
24 use Civi\Api4\MockBasicEntity
;
25 use api\v
4\UnitTestCase
;
30 class EvaluateConditionTest
extends UnitTestCase
{
32 public function testEvaluateCondition() {
33 $action = MockBasicEntity
::get();
34 $reflection = new \
ReflectionClass($action);
35 $method = $reflection->getMethod('evaluateCondition');
36 $method->setAccessible(TRUE);
44 'values' => ['one' => 1, 'two' => 2, 'three' => 3],
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));