@@ -295,6 +295,62 @@ public function testPost_purgeItem() {
295295 $ this ->boolean ($ output )->isFalse ();
296296 }
297297
298+ public function testUpdateValidators () {
299+ $ form = $ this ->getForm ();
300+
301+ $ formValidator = new \PluginFormcreatorForm_Validator ();
302+ $ rows = $ formValidator ->find ([
303+ 'plugin_formcreator_forms_id ' => $ form ->getID (),
304+ ]);
305+ $ this ->array ($ rows )->hasSize (0 );
306+
307+ $ form = $ this ->getForm ([
308+ 'validation_required ' => \PluginFormcreatorForm_Validator::VALIDATION_USER ,
309+ '_validator_users ' => ['2 ' ], // glpi account
310+ ]);
311+
312+ $ rows = $ formValidator ->find ([
313+ 'plugin_formcreator_forms_id ' => $ form ->getID (),
314+ ]);
315+ $ this ->array ($ rows )->hasSize (1 );
316+ $ formValidator ->getFromResultSet (array_pop ($ rows ));
317+ $ this ->integer ((int ) $ formValidator ->fields ['items_id ' ])->isEqualTo (2 );
318+ $ this ->string ( $ formValidator ->fields ['itemtype ' ])->isEqualTo (\User::class);
319+ $ this ->integer ((int ) $ formValidator ->fields ['plugin_formcreator_forms_id ' ])->isEqualTo ($ form ->getID ());
320+
321+ $ form = $ this ->getForm ([
322+ 'validation_required ' => \PluginFormcreatorForm_Validator::VALIDATION_GROUP ,
323+ '_validator_groups ' => ['1 ' ], // a group ID (not created in this test)
324+ ]);
325+ $ rows = $ formValidator ->find ([
326+ 'plugin_formcreator_forms_id ' => $ form ->getID (),
327+ ]);
328+ $ this ->array ($ rows )->hasSize (1 );
329+ $ formValidator ->getFromResultSet (array_pop ($ rows ));
330+ $ this ->integer ((int ) $ formValidator ->fields ['items_id ' ])->isEqualTo (1 );
331+ $ this ->string ( $ formValidator ->fields ['itemtype ' ])->isEqualTo (\Group::class);
332+ $ this ->integer ((int ) $ formValidator ->fields ['plugin_formcreator_forms_id ' ])->isEqualTo ($ form ->getID ());
333+ }
334+
335+ public function testIncreateUsageCount () {
336+ $ form = $ this ->getForm ();
337+ $ this ->integer ((int ) $ form ->fields ['usage_count ' ])->isEqualTo (0 );
338+
339+ $ form ->increaseUsageCount ();
340+ $ this ->integer ((int ) $ form ->fields ['usage_count ' ])->isEqualTo (1 );
341+ }
342+
343+ public function testGetByQuestionId () {
344+ $ question = $ this ->getQuestion ();
345+ $ section = new \PluginFormcreatorSection ();
346+ $ section ->getFromDB ($ question ->fields ['plugin_formcreator_sections_id ' ]) ;
347+ $ expected = $ section ->fields ['plugin_formcreator_forms_id ' ];
348+ $ form = $ this ->newTestedInstance ();
349+ $ form ->getByQuestionId ($ question ->getID ());
350+
351+ $ this ->integer ((int ) $ form ->getID ())->isEqualTo ($ expected );
352+ }
353+
298354 public function testCreateValidationNotification () {
299355 global $ DB ;
300356
0 commit comments