@@ -32,6 +32,10 @@ public static function setUpBeforeClass() {
3232 'name ' => 'other text question ' ,
3333 'fieldtype ' => 'text ' ,
3434 ],
35+ [
36+ 'name ' => 'third text question ' ,
37+ 'fieldtype ' => 'text ' ,
38+ ],
3539 ],
3640 ],
3741 ];
@@ -173,10 +177,10 @@ public function testConditionForMultipleValue($condition) {
173177 $ question ->updateConditions ($ condition );
174178
175179 //Run the condition
176- $ currentValues = array (
177- "formcreator_field_ $ firstQuestionId " => array ( $ condition ['show_value ' ][0 ] . " and now for something completely different " ) ,
180+ $ currentValues = [
181+ "formcreator_field_ $ firstQuestionId " => [ $ condition ['show_value ' ][0 ] . " and now for something completely different " ] ,
178182 "formcreator_field_ $ secondQuestionId " => '' ,
179- ) ;
183+ ] ;
180184 $ visibility = PluginFormcreatorFields::updateVisibility ($ currentValues );
181185
182186 // Check the result
@@ -197,4 +201,110 @@ public function testConditionForMultipleValue($condition) {
197201 // Check the result
198202 $ this ->assertEquals (!$ expected , $ visibility ["formcreator_field_ $ secondQuestionId " ]);
199203 }
204+
205+ public function testConditionForManyQuestions () {
206+ $ form = new PluginFormcreatorForm ();
207+ $ form ->add ([
208+ 'entities_id ' => 0 ,
209+ 'name ' => 'a form ' ,
210+ 'description ' => 'form description ' ,
211+ 'content ' => 'a content ' ,
212+ 'is_active ' => 1 ,
213+ 'validation_required ' => 0
214+ ]);
215+
216+ $ section = new PluginFormcreatorSection ();
217+ $ sectionId = $ section ->add ([
218+ 'name ' => 'section ' ,
219+ 'plugin_formcreator_forms_id ' => $ form ->getID (),
220+ ]);
221+ $ questions = [];
222+ $ questions [0 ] = new PluginFormcreatorQuestion ();
223+ $ questions [1 ] = new PluginFormcreatorQuestion ();
224+ $ questions [2 ] = new PluginFormcreatorQuestion ();
225+
226+ // create questions
227+ $ firstQuestionId = $ questions [0 ]->add ([
228+ 'name ' => 'text question 0 ' ,
229+ 'fieldtype ' => 'text ' ,
230+ 'plugin_formcreator_sections_id ' => $ sectionId ,
231+ ]);
232+ $ secondQuestionId = $ questions [1 ]->add ([
233+ 'name ' => 'text question 1 ' ,
234+ 'fieldtype ' => 'text ' ,
235+ 'plugin_formcreator_sections_id ' => $ sectionId ,
236+ 'show_rule ' => 'hidden ' ,
237+ ]);
238+ $ thirdQuestionId = $ questions [2 ]->add ([
239+ 'name ' => 'text question 2 ' ,
240+ 'fieldtype ' => 'text ' ,
241+ 'plugin_formcreator_sections_id ' => $ sectionId ,
242+ 'show_rule ' => 'hidden ' ,
243+ ]);
244+
245+ // create conditions
246+ $ condition = new PluginFormcreatorQuestion_Condition ();
247+ $ condition ->add ([
248+ 'plugin_formcreator_questions_id ' => $ secondQuestionId ,
249+ 'show_field ' => $ firstQuestionId ,
250+ 'show_condition ' => '== ' ,
251+ 'show_value ' => 'a ' ,
252+ 'show_logic ' => 'OR ' ,
253+ ]);
254+ $ condition ->add ([
255+ 'plugin_formcreator_questions_id ' => $ thirdQuestionId ,
256+ 'show_field ' => $ firstQuestionId ,
257+ 'show_condition ' => '== ' ,
258+ 'show_value ' => 'c ' ,
259+ 'show_logic ' => 'OR ' ,
260+ ]);
261+ $ condition ->add ([
262+ 'plugin_formcreator_questions_id ' => $ thirdQuestionId ,
263+ 'show_field ' => $ secondQuestionId ,
264+ 'show_condition ' => '== ' ,
265+ 'show_value ' => 'c ' ,
266+ 'show_logic ' => 'OR ' ,
267+ ]);
268+
269+ // test the conditions engine
270+ $ currentValues = [
271+ "formcreator_field_ $ firstQuestionId " => '' ,
272+ "formcreator_field_ $ secondQuestionId " => '' ,
273+ "formcreator_field_ $ thirdQuestionId " => '' ,
274+ ];
275+ $ visibility = PluginFormcreatorFields::updateVisibility ($ currentValues );
276+ $ this ->assertEquals (true , $ visibility ["formcreator_field_ $ firstQuestionId " ]);
277+ $ this ->assertEquals (false , $ visibility ["formcreator_field_ $ secondQuestionId " ]);
278+ $ this ->assertEquals (false , $ visibility ["formcreator_field_ $ thirdQuestionId " ]);
279+
280+ $ currentValues = [
281+ "formcreator_field_ $ firstQuestionId " => 'a ' ,
282+ "formcreator_field_ $ secondQuestionId " => '' ,
283+ "formcreator_field_ $ thirdQuestionId " => '' ,
284+ ];
285+ $ visibility = PluginFormcreatorFields::updateVisibility ($ currentValues );
286+ $ this ->assertEquals (true , $ visibility ["formcreator_field_ $ firstQuestionId " ]);
287+ $ this ->assertEquals (true , $ visibility ["formcreator_field_ $ secondQuestionId " ]);
288+ $ this ->assertEquals (false , $ visibility ["formcreator_field_ $ thirdQuestionId " ]);
289+
290+ $ currentValues = [
291+ "formcreator_field_ $ firstQuestionId " => 'a ' ,
292+ "formcreator_field_ $ secondQuestionId " => 'c ' ,
293+ "formcreator_field_ $ thirdQuestionId " => '' ,
294+ ];
295+ $ visibility = PluginFormcreatorFields::updateVisibility ($ currentValues );
296+ $ this ->assertEquals (true , $ visibility ["formcreator_field_ $ firstQuestionId " ]);
297+ $ this ->assertEquals (true , $ visibility ["formcreator_field_ $ secondQuestionId " ]);
298+ $ this ->assertEquals (true , $ visibility ["formcreator_field_ $ thirdQuestionId " ]);
299+
300+ $ currentValues = [
301+ "formcreator_field_ $ firstQuestionId " => '' ,
302+ "formcreator_field_ $ secondQuestionId " => 'c ' ,
303+ "formcreator_field_ $ thirdQuestionId " => '' ,
304+ ];
305+ $ visibility = PluginFormcreatorFields::updateVisibility ($ currentValues );
306+ $ this ->assertEquals (true , $ visibility ["formcreator_field_ $ firstQuestionId " ]);
307+ $ this ->assertEquals (false , $ visibility ["formcreator_field_ $ secondQuestionId " ]);
308+ $ this ->assertEquals (true , $ visibility ["formcreator_field_ $ thirdQuestionId " ]);
309+ }
200310}
0 commit comments