diff --git a/application/Espo/Core/Formula/Functions/ArrayGroup/IncludesType.php b/application/Espo/Core/Formula/Functions/ArrayGroup/IncludesType.php new file mode 100644 index 0000000000..5ef054d1db --- /dev/null +++ b/application/Espo/Core/Formula/Functions/ArrayGroup/IncludesType.php @@ -0,0 +1,53 @@ +value)) { + throw new Error('Value for \'Array\\Includses\' item is not array.'); + } + if (count($item->value) < 2) { + throw new Error('Bad arguments passed to \'Array\\Includses\'.'); + } + $list = $this->evaluate($item->value[0]); + $needle = $this->evaluate($item->value[1]); + + if (!is_array($list)) { + return false; + } + + return in_array($needle, $list); + } +} \ No newline at end of file diff --git a/tests/unit/Espo/Core/Formula/FormulaTest.php b/tests/unit/Espo/Core/Formula/FormulaTest.php index dc4bc7403c..4c456949dc 100644 --- a/tests/unit/Espo/Core/Formula/FormulaTest.php +++ b/tests/unit/Espo/Core/Formula/FormulaTest.php @@ -1364,6 +1364,63 @@ class FormulaTest extends \PHPUnit_Framework_TestCase $this->assertEquals('2017-01-01 19:30:00', $actual); } + function testArrayIncludes() + { + $item = json_decode(' + { + "type": "array\\\\includes", + "value": [ + { + "type": "value", + "value": ["Test", "Hello"] + }, + { + "type": "value", + "value": "Test" + } + ] + } + '); + $actual = $this->formula->process($item, $this->entity); + $this->assertTrue($actual); + + $item = json_decode(' + { + "type": "array\\\\includes", + "value": [ + { + "type": "value", + "value": false + }, + { + "type": "value", + "value": "" + } + ] + } + '); + $actual = $this->formula->process($item, $this->entity); + $this->assertFalse($actual); + + $item = json_decode(' + { + "type": "array\\\\includes", + "value": [ + { + "type": "value", + "value": ["Test", "Hello"] + }, + { + "type": "value", + "value": "Yok" + } + ] + } + '); + $actual = $this->formula->process($item, $this->entity); + $this->assertFalse($actual); + } + function testEnvUserAttribute() { $item = json_decode('