Fix logic operator issue (#104)

Co-authored-by: Julien Nahum <julien@nahum.net>
This commit is contained in:
Chirag Chhatrala 2023-03-15 22:41:25 +05:30 committed by GitHub
parent 5df4488c25
commit 825492bf45
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 1 deletions

View File

@ -562,7 +562,7 @@ class FormPropertyLogicRule implements Rule, DataAwareRule
private function checkConditions($conditions) private function checkConditions($conditions)
{ {
if (isset($conditions['operatorIdentifier'])) { if (array_key_exists('operatorIdentifier', $conditions)) {
if (($conditions['operatorIdentifier'] !== 'and') && ($conditions['operatorIdentifier'] !== 'or')) { if (($conditions['operatorIdentifier'] !== 'and') && ($conditions['operatorIdentifier'] !== 'or')) {
$this->conditionErrors[] = 'missing operator'; $this->conditionErrors[] = 'missing operator';
$this->isConditionCorrect = false; $this->isConditionCorrect = false;

View File

@ -135,4 +135,38 @@ it('can validate form logic rules for conditions', function () {
$validatorObj = $this->app['validator']->make($data, $rules); $validatorObj = $this->app['validator']->make($data, $rules);
$this->assertFalse($validatorObj->passes()); $this->assertFalse($validatorObj->passes());
expect($validatorObj->errors()->messages()['properties.0.logic'][0])->toBe("The logic conditions for Name are not complete. Error detail(s): missing condition value"); expect($validatorObj->errors()->messages()['properties.0.logic'][0])->toBe("The logic conditions for Name are not complete. Error detail(s): missing condition value");
$data = [
'properties' => [
[
'id' => "title",
'name' => "Name",
'type' => 'text',
'hidden' => false,
'required' => false,
'logic' => [
"conditions" => [
"operatorIdentifier"=> null,
"children"=> [
[
"identifier"=> "title",
"value"=> [
"operator"=> "starts_with",
"property_meta"=> [
"id"=> "title",
"type"=> "text"
],
]
]
]
],
"actions" => []
]
]
]
];
$validatorObj = $this->app['validator']->make($data, $rules);
$this->assertFalse($validatorObj->passes());
expect($validatorObj->errors()->messages()['properties.0.logic'][0])->toBe("The logic conditions for Name are not complete. Error detail(s): missing operator");
}); });