From c5af04ec2b1c85efb55311ef4c0c358c58322d61 Mon Sep 17 00:00:00 2001 From: yuri Date: Wed, 18 Oct 2017 12:17:38 +0300 Subject: [PATCH 1/2] formula nl support --- .../Espo/Core/Formula/Functions/ValueType.php | 10 ++++++++-- tests/unit/Espo/Core/Formula/FormulaTest.php | 14 ++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/application/Espo/Core/Formula/Functions/ValueType.php b/application/Espo/Core/Formula/Functions/ValueType.php index 99ec8add30..1e90fd5e7d 100644 --- a/application/Espo/Core/Formula/Functions/ValueType.php +++ b/application/Espo/Core/Formula/Functions/ValueType.php @@ -1,4 +1,4 @@ -value; + $value = $item->value; + + if (is_string($value)) { + $value = str_replace("\\n", "\n", $value); + } + + return $value; } } \ 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 b39129dea5..a9559cd9a6 100644 --- a/tests/unit/Espo/Core/Formula/FormulaTest.php +++ b/tests/unit/Espo/Core/Formula/FormulaTest.php @@ -926,6 +926,20 @@ class FormulaTest extends \PHPUnit_Framework_TestCase $this->assertTrue($result); } + function testStringNewLine() + { + $item = json_decode(' + { + "type": "value", + "value": "test\\ntest" + } + '); + + $result = $this->formula->process($item, $this->entity); + + $this->assertEquals("test\ntest", $result); + } + function testVariable() { $item = json_decode(' From 3a48b155e2f8ac0229a78361de30b6106bccabe2 Mon Sep 17 00:00:00 2001 From: yuri Date: Wed, 18 Oct 2017 12:18:58 +0300 Subject: [PATCH 2/2] formula: undefined variable treated as null --- application/Espo/Core/Formula/Functions/VariableType.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/application/Espo/Core/Formula/Functions/VariableType.php b/application/Espo/Core/Formula/Functions/VariableType.php index f43fe84efb..863781cf67 100644 --- a/application/Espo/Core/Formula/Functions/VariableType.php +++ b/application/Espo/Core/Formula/Functions/VariableType.php @@ -1,4 +1,4 @@ -getVariables(), $name)) { - throw new Error(); + return null; } return $this->getVariables()->$name;