diff --git a/application/Espo/Core/Formula/Functions/StringGroup/PosType.php b/application/Espo/Core/Formula/Functions/StringGroup/PosType.php new file mode 100644 index 0000000000..9784596ec3 --- /dev/null +++ b/application/Espo/Core/Formula/Functions/StringGroup/PosType.php @@ -0,0 +1,51 @@ +value ?? []; + + if (count($args) < 2) throw new Error("Bad arguments passed to function string\\pos."); + + $string = $this->evaluate($args[0]); + $needle = $this->evaluate($args[1]); + + if (!is_string($string)) { + return false; + } + + return mb_strpos($string, $needle); + } +} \ 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 be454fca6f..ff1fa4cf6c 100644 --- a/tests/unit/Espo/Core/Formula/FormulaTest.php +++ b/tests/unit/Espo/Core/Formula/FormulaTest.php @@ -2816,6 +2816,47 @@ class FormulaTest extends \PHPUnit\Framework\TestCase $this->assertEquals('12', $actual); } + function testPps() + { + $item = json_decode(' + { + "type": "string\\\\pos", + "value": [ + { + "type": "value", + "value": "1234" + }, + { + "type": "value", + "value": 23 + } + ] + } + '); + + $actual = $this->formula->process($item, $this->entity); + $this->assertEquals(1, $actual); + + $item = json_decode(' + { + "type": "string\\\\pos", + "value": [ + { + "type": "value", + "value": "1234" + }, + { + "type": "value", + "value": 54 + } + ] + } + '); + + $actual = $this->formula->process($item, $this->entity); + $this->assertFalse($actual); + } + function testBundle() { $item = json_decode('