From 825492bf45ab8e4bf11edce4b3d459eff2a6f5a2 Mon Sep 17 00:00:00 2001 From: Chirag Chhatrala <60499540+chiragchhatrala@users.noreply.github.com> Date: Wed, 15 Mar 2023 22:41:25 +0530 Subject: [PATCH] Fix logic operator issue (#104) Co-authored-by: Julien Nahum --- app/Rules/FormPropertyLogicRule.php | 2 +- tests/Feature/Forms/FormPropertyLogicTest.php | 34 +++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/app/Rules/FormPropertyLogicRule.php b/app/Rules/FormPropertyLogicRule.php index fae01c0..6e0784d 100644 --- a/app/Rules/FormPropertyLogicRule.php +++ b/app/Rules/FormPropertyLogicRule.php @@ -562,7 +562,7 @@ class FormPropertyLogicRule implements Rule, DataAwareRule private function checkConditions($conditions) { - if (isset($conditions['operatorIdentifier'])) { + if (array_key_exists('operatorIdentifier', $conditions)) { if (($conditions['operatorIdentifier'] !== 'and') && ($conditions['operatorIdentifier'] !== 'or')) { $this->conditionErrors[] = 'missing operator'; $this->isConditionCorrect = false; diff --git a/tests/Feature/Forms/FormPropertyLogicTest.php b/tests/Feature/Forms/FormPropertyLogicTest.php index 430aea1..ad3b1d7 100644 --- a/tests/Feature/Forms/FormPropertyLogicTest.php +++ b/tests/Feature/Forms/FormPropertyLogicTest.php @@ -135,4 +135,38 @@ it('can validate form logic rules for conditions', function () { $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 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"); }); \ No newline at end of file