@@ -46,6 +46,25 @@ public function beforeTestMethod($method) {
4646 case 'testCountAvailableForm ' :
4747 $ this ->login ('glpi ' , 'glpi ' );
4848 }
49+
50+ switch ($ method ) {
51+ case 'testCreateValidationNotification ' :
52+ \Config::setConfigurationValues (
53+ 'core ' ,
54+ ['use_notifications ' => 1 , 'notifications_mailing ' => 1 ]
55+ );
56+ }
57+ }
58+
59+ public function afterTestMethod ($ method ) {
60+ parent ::afterTestMethod ($ method );
61+ switch ($ method ) {
62+ case 'testCreateValidationNotification ' :
63+ \Config::setConfigurationValues (
64+ 'core ' ,
65+ ['use_notifications ' => 0 , 'notifications_mailing ' => 0 ]
66+ );
67+ }
4968 }
5069
5170 public function providerGetTypeName () {
@@ -390,50 +409,81 @@ public function testIncreateUsageCount() {
390409 $ this ->integer ((int ) $ form ->fields ['usage_count ' ])->isEqualTo (1 );
391410 }
392411
393- public function testCreateValidationNotification () {
394- global $ DB , $ CFG_GLPI ;
412+ public function providerCreateValidationNotification () {
413+ // give email address to users
414+ $ validator = new \User ();
415+ $ validator ->getFromDBbyName ('tech ' );
416+ $ useremail = new \UserEmail ();
417+ $ useremail ->deleteByCriteria ([
418+ 'users_id ' => $ validator ->getID (),
419+ ]);
420+ $ validator ->update ([
421+ 'id ' => $ validator ->getID (),
422+ '_useremails ' => [
423+ 'tech@localhost.com ' ,
424+ ]
425+ ]);
395426
396- // Enable notifications in GLPI
397- \Config::setConfigurationValues (
398- 'core ' ,
399- ['use_notifications ' => 1 , 'notifications_mailing ' => 1 ]
400- );
401- $ CFG_GLPI ['use_notifications ' ] = 1 ;
402- $ CFG_GLPI ['notifications_mailing ' ] = 1 ;
403- $ user = new \User ();
404- $ user ->getFromDBbyName ('glpi ' );
405- $ _SESSION ['glpiID ' ] = $ user ->getID ();
427+ $ requester = new \User ();
428+ $ requester ->getFromDBbyName ('normal ' );
406429 $ useremail = new \UserEmail ();
407430 $ useremail ->deleteByCriteria ([
408- 'users_id ' => $ user ->getID (),
431+ 'users_id ' => $ requester ->getID (),
409432 ]);
410- $ user ->update ([
411- 'id ' => $ _SESSION [ ' glpiID ' ] ,
433+ $ requester ->update ([
434+ 'id ' => $ requester -> getID () ,
412435 '_useremails ' => [
413- 'glpi @localhost.com ' ,
436+ 'normal @localhost.com ' ,
414437 ]
415438 ]);
439+
440+ yield [
441+ $ requester ,
442+ $ validator ,
443+ 2
444+ ];
445+
446+ yield [
447+ $ requester ,
448+ $ requester ,
449+ 1
450+ ];
451+ }
452+
453+ /**
454+ * @dataProvider providerCreateValidationNotification
455+ */
456+ public function testCreateValidationNotification (\User $ requester , \User $ validator , $ expectedNotificationCount ) {
457+ global $ DB , $ CFG_GLPI ;
458+
459+ // Enable notifications in GLPI
460+ \Config::setConfigurationValues (
461+ 'core ' ,
462+ ['use_notifications ' => 1 , 'notifications_mailing ' => 1 ]
463+ );
464+ // $CFG_GLPI['use_notifications'] = 1;
465+ // $CFG_GLPI['notifications_mailing'] = 1;
466+
416467 $ form = $ this ->getForm ([
417468 'name ' => 'validation notification ' ,
418469 'validation_required ' => \PluginFormcreatorForm_Validator::VALIDATION_USER ,
419- '_validator_users ' => [$ _SESSION [ ' glpiID ' ] ],
470+ '_validator_users ' => [$ validator -> getID () ],
420471 ]);
421472 $ this ->getSection ([
422473 \PluginFormcreatorForm::getForeignKeyField () => $ form ->getID (),
423474 'name ' => 'section ' ,
424475 ]);
425476
426477 $ formAnswer = new \PluginFormcreatorFormAnswer ();
478+ $ this ->login ('normal ' , 'normal ' );
427479 $ this ->disableDebug ();
428480 $ formAnswerId = $ formAnswer ->add ([
429481 'plugin_formcreator_forms_id ' => $ form ->getID (),
430- 'formcreator_validator ' => \User::class . '_ ' . $ _SESSION [ ' glpiID ' ] ,
482+ 'formcreator_validator ' => $ validator -> getType () . '_ ' . $ validator -> getID () ,
431483 ]);
432484 $ this ->restoreDebug ();
433485 $ this ->boolean ($ formAnswer ->isNewItem ())->isFalse ();
434486
435- // 1 notification to the validator
436- // 1 notification to the requester
437487 $ foundNotifications = $ DB ->request ([
438488 'COUNT ' => 'cpt ' ,
439489 'FROM ' => \QueuedNotification::getTable (),
@@ -442,7 +492,7 @@ public function testCreateValidationNotification() {
442492 'items_id ' => $ formAnswerId ,
443493 ]
444494 ])->current ();
445- $ this ->integer ((int ) $ foundNotifications ['cpt ' ])->isEqualTo (2 );
495+ $ this ->integer ((int ) $ foundNotifications ['cpt ' ])->isEqualTo ($ expectedNotificationCount );
446496 }
447497
448498 public function testExport () {
0 commit comments