diff --git a/application/Espo/Core/Formula/Functions/AttributeType.php b/application/Espo/Core/Formula/Functions/AttributeType.php index 355a083dc4..6d7df402dc 100644 --- a/application/Espo/Core/Formula/Functions/AttributeType.php +++ b/application/Espo/Core/Formula/Functions/AttributeType.php @@ -1,4 +1,4 @@ -value)) { + throw new Error(); + } + + if (count($item->value) < 1) { + throw new Error(); + } + + $attribute = $this->evaluate($item->value[0]); + + return $this->getAttributeValue($attribute); + } } \ No newline at end of file diff --git a/application/Espo/Core/Formula/Functions/EntityGroup/IsAttributeChangedType.php b/application/Espo/Core/Formula/Functions/EntityGroup/IsAttributeChangedType.php index 5ebbdb3c8e..aa55f2f37d 100644 --- a/application/Espo/Core/Formula/Functions/EntityGroup/IsAttributeChangedType.php +++ b/application/Espo/Core/Formula/Functions/EntityGroup/IsAttributeChangedType.php @@ -1,4 +1,4 @@ -value)) { - $attributeList = $attribute; - foreach ($item->value as $value) { - $attribute = $this->evaluate($item->value); - $attributeList[] = $attribute; - } - } else { - $attribute = $this->evaluate($item->value); - $attributeList[] = $attribute; + if (!is_array($item->value)) { + throw new Error(); } - return $this->check($attributeList); + if (count($item->value) < 1) { + throw new Error(); + } + + $attribute = $this->evaluate($item->value[0]); + + return $this->check($attribute); } - protected function check(array $attributeList) + protected function check($attribute) { - $result = true; - foreach ($attributeList as $i => $attribute) { - if (!$this->getEntity()->isAttributeChanged($attribute)) { - $result = false; - break; - } - } - return $result; + return $this->getEntity()->isAttributeChanged($attribute); } } \ No newline at end of file diff --git a/application/Espo/Core/Formula/Functions/EntityGroup/IsAttributeNotChangedType.php b/application/Espo/Core/Formula/Functions/EntityGroup/IsAttributeNotChangedType.php index ac7e7718c3..8251e99e79 100644 --- a/application/Espo/Core/Formula/Functions/EntityGroup/IsAttributeNotChangedType.php +++ b/application/Espo/Core/Formula/Functions/EntityGroup/IsAttributeNotChangedType.php @@ -1,4 +1,4 @@ -assertEquals('Test', $result); } - function testAttributeFetched() + function testEntityAttribute() + { + $item = json_decode(' + { + "type": "entity\\\\attribute", + "value": [ + { + "type": "value", + "value": "name" + } + ] + } + '); + + $this->setEntityAttributes($this->entity, array( + 'name' => 'Test' + )); + + $result = $this->formula->process($item, $this->entity); + + $this->assertEquals('Test', $result); + } + + function testEntityAttributeFetched() { $item = json_decode(' { "type": "entity\\\\attributeFetched", - "value": "name" + "value": [ + { + "type": "value", + "value": "name" + } + ] } '); @@ -162,10 +190,12 @@ class FormulaTest extends \PHPUnit_Framework_TestCase $item = json_decode(' { "type": "entity\\\\isAttributeChanged", - "value": { - "type": "value", - "value": "name" - } + "value": [ + { + "type": "value", + "value": "name" + } + ] } '); @@ -188,10 +218,12 @@ class FormulaTest extends \PHPUnit_Framework_TestCase $item = json_decode(' { "type": "entity\\\\isAttributeNotChanged", - "value": { - "type": "value", - "value": "name" - } + "value": [ + { + "type": "value", + "value": "name" + } + ] } ');