Merge pull request #23283 from eileenmcnaughton/import_saved_map
[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\Api4TestBase;
24 use Civi\Test\TransactionalInterface;
25
26 /**
27 * @group headless
28 */
29 class EvaluateConditionTest extends Api4TestBase implements TransactionalInterface {
30
31 public function testEvaluateCondition() {
32 $action = MockBasicEntity::get();
33 $reflection = new \ReflectionClass($action);
34 $method = $reflection->getMethod('evaluateCondition');
35 $method->setAccessible(TRUE);
36
37 $data = [
38 'nada' => 0,
39 'uno' => 1,
40 'dos' => 2,
41 'apple' => 'red',
42 'banana' => 'yellow',
43 'values' => ['one' => 1, 'two' => 2, 'three' => 3],
44 ];
45
46 $this->assertFalse($method->invoke($action, '$uno > $dos', $data));
47 $this->assertTrue($method->invoke($action, '$uno < $dos', $data));
48 $this->assertTrue($method->invoke($action, '$apple == "red" && $banana != "red"', $data));
49 $this->assertFalse($method->invoke($action, '$apple == "red" && $banana != "yellow"', $data));
50 $this->assertTrue($method->invoke($action, '$values.one == $uno', $data));
51 $this->assertTrue($method->invoke($action, '$values.one + $dos == $values.three', $data));
52 $this->assertTrue($method->invoke($action, 'empty($nada)', $data));
53 $this->assertFalse($method->invoke($action, 'empty($values)', $data));
54 }
55
56 }