Merge pull request #17943 from jitendrapurohit/core-1906
[civicrm-core.git] / tests / phpunit / api / v4 / Action / EvaluateConditionTest.php
1 <?php
2
3 /*
4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC. All rights reserved. |
6 | |
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 +--------------------------------------------------------------------+
11 */
12
13 /**
14 *
15 * @package CRM
16 * @copyright CiviCRM LLC https://civicrm.org/licensing
17 */
18
19
20 namespace api\v4\Action;
21
22 use Civi\Api4\MockBasicEntity;
23 use api\v4\UnitTestCase;
24
25 /**
26 * @group headless
27 */
28 class EvaluateConditionTest extends UnitTestCase {
29
30 public function testEvaluateCondition() {
31 $action = MockBasicEntity::get();
32 $reflection = new \ReflectionClass($action);
33 $method = $reflection->getMethod('evaluateCondition');
34 $method->setAccessible(TRUE);
35
36 $data = [
37 'nada' => 0,
38 'uno' => 1,
39 'dos' => 2,
40 'apple' => 'red',
41 'banana' => 'yellow',
42 'values' => ['one' => 1, 'two' => 2, 'three' => 3],
43 ];
44
45 $this->assertFalse($method->invoke($action, '$uno > $dos', $data));
46 $this->assertTrue($method->invoke($action, '$uno < $dos', $data));
47 $this->assertTrue($method->invoke($action, '$apple == "red" && $banana != "red"', $data));
48 $this->assertFalse($method->invoke($action, '$apple == "red" && $banana != "yellow"', $data));
49 $this->assertTrue($method->invoke($action, '$values.one == $uno', $data));
50 $this->assertTrue($method->invoke($action, '$values.one + $dos == $values.three', $data));
51 $this->assertTrue($method->invoke($action, 'empty($nada)', $data));
52 $this->assertFalse($method->invoke($action, 'empty($values)', $data));
53 }
54
55 }