3131namespace tests \units ;
3232use Config ;
3333use GlpiPlugin \Formcreator \Tests \CommonTestCase ;
34+ use Group ;
35+ use PluginFormcreatorFormAnswer ;
3436use PluginFormcreatorSection ;
3537use PluginFormcreatorQuestion ;
3638use PluginFormcreatorForm_Language ;
39+ use PluginFormcreatorForm_Profile ;
40+ use PluginFormcreatorForm_Validator ;
41+ use Central ;
42+ use User ;
43+ use UserEmail ;
3744
3845class PluginFormcreatorForm extends CommonTestCase {
3946
@@ -102,78 +109,84 @@ public function testGetTypeName($nb, $expected) {
102109 }
103110
104111 public function testGetEnumAccessType () {
112+ $ testedClassName = $ this ->getTestedClassName ();
105113 $ output = \PluginFormcreatorForm::getEnumAccessType ();
106114 $ this ->array ($ output )->isEqualTo ([
107- \PluginFormcreatorForm ::ACCESS_PUBLIC => __ ('Public access ' , 'formcreator ' ),
108- \PluginFormcreatorForm ::ACCESS_PRIVATE => __ ('Private access ' , 'formcreator ' ),
109- \PluginFormcreatorForm ::ACCESS_RESTRICTED => __ ('Restricted access ' , 'formcreator ' ),
115+ $ testedClassName ::ACCESS_PUBLIC => __ ('Public access ' , 'formcreator ' ),
116+ $ testedClassName ::ACCESS_PRIVATE => __ ('Private access ' , 'formcreator ' ),
117+ $ testedClassName ::ACCESS_RESTRICTED => __ ('Restricted access ' , 'formcreator ' ),
110118 ]);
111119 }
112120
113121 public function testCanCreate () {
122+ $ testedClassName = $ this ->getTestedClassName ();
114123 $ this ->login ('glpi ' , 'glpi ' );
115- $ output = \PluginFormcreatorForm ::canCreate ();
124+ $ output = $ testedClassName ::canCreate ();
116125 $ this ->boolean ((bool ) $ output )->isTrue ();
117126
118127 $ this ->login ('normal ' , 'normal ' );
119- $ output = \PluginFormcreatorForm ::canCreate ();
128+ $ output = $ testedClassName ::canCreate ();
120129 $ this ->boolean ((bool ) $ output )->isFalse ();
121130
122131 $ this ->login ('post-only ' , 'postonly ' );
123- $ output = \PluginFormcreatorForm ::canCreate ();
132+ $ output = $ testedClassName ::canCreate ();
124133 $ this ->boolean ((bool ) $ output )->isFalse ();
125134 }
126135
127136 public function testCanView () {
137+ $ testedClassName = $ this ->getTestedClassName ();
128138 $ this ->login ('glpi ' , 'glpi ' );
129- $ output = \PluginFormcreatorForm ::canView ();
139+ $ output = $ testedClassName ::canView ();
130140 $ this ->boolean ((bool ) $ output )->isTrue ();
131141
132142 $ this ->login ('normal ' , 'normal ' );
133- $ output = \PluginFormcreatorForm ::canView ();
143+ $ output = $ testedClassName ::canView ();
134144 $ this ->boolean ((bool ) $ output )->isTrue ();
135145
136146 $ this ->login ('post-only ' , 'postonly ' );
137- $ output = \PluginFormcreatorForm ::canView ();
147+ $ output = $ testedClassName ::canView ();
138148 $ this ->boolean ((bool ) $ output )->isTrue ();
139149 }
140150
141151 public function testCanDelete () {
152+ $ testedClassName = $ this ->getTestedClassName ();
142153 $ this ->login ('glpi ' , 'glpi ' );
143- $ output = \PluginFormcreatorForm ::canDelete ();
154+ $ output = $ testedClassName ::canDelete ();
144155 $ this ->boolean ((bool ) $ output )->isTrue ();
145156
146157 $ this ->login ('normal ' , 'normal ' );
147- $ output = \PluginFormcreatorForm ::canDelete ();
158+ $ output = $ testedClassName ::canDelete ();
148159 $ this ->boolean ((bool ) $ output )->isFalse ();
149160
150161 $ this ->login ('post-only ' , 'postonly ' );
151- $ output = \PluginFormcreatorForm ::canCreate ();
162+ $ output = $ testedClassName ::canCreate ();
152163 $ this ->boolean ((bool ) $ output )->isFalse ();
153164 }
154165
155166 public function testCanPurge () {
167+ $ testedClassName = $ this ->getTestedClassName ();
156168 $ this ->login ('glpi ' , 'glpi ' );
157- $ output = \PluginFormcreatorForm ::canPurge ();
169+ $ output = $ testedClassName ::canPurge ();
158170 $ this ->boolean ((bool ) $ output )->isTrue ();
159171
160172 $ this ->login ('normal ' , 'normal ' );
161- $ output = \PluginFormcreatorForm ::canPurge ();
173+ $ output = $ testedClassName ::canPurge ();
162174 $ this ->boolean ((bool ) $ output )->isFalse ();
163175 $ this ->login ('post-only ' , 'postonly ' );
164- $ output = \PluginFormcreatorForm ::canCreate ();
176+ $ output = $ testedClassName ::canCreate ();
165177 $ this ->boolean ((bool ) $ output )->isFalse ();
166178 }
167179
168180 public function testCanPurgeItem () {
181+ $ testedClassName = $ this ->getTestedClassName ();
169182 $ form = $ this ->getForm ();
170183 $ output = $ form ->canPurgeItem ();
171184 $ this ->boolean ((boolean ) $ output )->isTrue ();
172185
173186 $ this ->disableDebug ();
174- $ formAnswer = new \ PluginFormcreatorFormAnswer ();
187+ $ formAnswer = new PluginFormcreatorFormAnswer ();
175188 $ formAnswer ->add ([
176- \PluginFormcreatorForm ::getForeignKeyField () => $ form ->getID (),
189+ $ testedClassName ::getForeignKeyField () => $ form ->getID (),
177190 ]);
178191 $ this ->restoreDebug ();
179192
@@ -305,7 +318,7 @@ public function testDefineTabs() {
305318
306319 public function testGetTabNameForItem () {
307320 $ form = $ this ->getForm ();
308- $ item = new \ Central ();
321+ $ item = new Central ();
309322 $ output = $ form ->getTabNameForItem ($ item );
310323 $ this ->string ($ output )->isEqualTo ('Forms ' );
311324
@@ -324,7 +337,7 @@ public function testGetTabNameForItem() {
324337
325338 public function testPost_purgeItem () {
326339 $ form = $ this ->getForm ([
327- 'validation_required ' => \ PluginFormcreatorForm_Validator::VALIDATION_USER ,
340+ 'validation_required ' => PluginFormcreatorForm_Validator::VALIDATION_USER ,
328341 'users_id ' => 2 , // glpi
329342 ]);
330343 $ section = $ this ->getSection ([
@@ -336,13 +349,13 @@ public function testPost_purgeItem() {
336349 $ targetTicket = $ this ->getTargetTicket ([
337350 'plugin_formcreator_forms_id ' => $ form ->getID (),
338351 ]);
339- $ validator = new \ PluginFormcreatorForm_Validator ();
352+ $ validator = new PluginFormcreatorForm_Validator ();
340353 $ validator ->getFromDBByCrit ([
341354 'plugin_formcreator_forms_id ' => $ form ->getID (),
342- 'itemtype ' => \ User::class,
355+ 'itemtype ' => User::class,
343356 ]);
344357
345- $ formProfile = new \ PluginFormcreatorForm_Profile ();
358+ $ formProfile = new PluginFormcreatorForm_Profile ();
346359 $ formProfile ->add ([
347360 'plugin_formcreator_forms_id ' => $ form ->getID (),
348361 'profiles_id ' => 6 // technician
@@ -371,14 +384,14 @@ public function testPost_purgeItem() {
371384 public function testUpdateValidators () {
372385 $ form = $ this ->getForm ();
373386
374- $ formValidator = new \ PluginFormcreatorForm_Validator ();
387+ $ formValidator = new PluginFormcreatorForm_Validator ();
375388 $ rows = $ formValidator ->find ([
376389 'plugin_formcreator_forms_id ' => $ form ->getID (),
377390 ]);
378391 $ this ->array ($ rows )->hasSize (0 );
379392
380393 $ form = $ this ->getForm ([
381- 'validation_required ' => \ PluginFormcreatorForm_Validator::VALIDATION_USER ,
394+ 'validation_required ' => PluginFormcreatorForm_Validator::VALIDATION_USER ,
382395 '_validator_users ' => ['2 ' ], // glpi account
383396 ]);
384397
@@ -392,7 +405,7 @@ public function testUpdateValidators() {
392405 $ this ->integer ((int ) $ formValidator ->fields ['plugin_formcreator_forms_id ' ])->isEqualTo ($ form ->getID ());
393406
394407 $ form = $ this ->getForm ([
395- 'validation_required ' => \ PluginFormcreatorForm_Validator::VALIDATION_GROUP ,
408+ 'validation_required ' => PluginFormcreatorForm_Validator::VALIDATION_GROUP ,
396409 '_validator_groups ' => ['1 ' ], // a group ID (not created in this test)
397410 ]);
398411 $ rows = $ formValidator ->find ([
@@ -401,7 +414,7 @@ public function testUpdateValidators() {
401414 $ this ->array ($ rows )->hasSize (1 );
402415 $ formValidator ->getFromResultSet (array_pop ($ rows ));
403416 $ this ->integer ((int ) $ formValidator ->fields ['items_id ' ])->isEqualTo (1 );
404- $ this ->string ( $ formValidator ->fields ['itemtype ' ])->isEqualTo (\ Group::class);
417+ $ this ->string ( $ formValidator ->fields ['itemtype ' ])->isEqualTo (Group::class);
405418 $ this ->integer ((int ) $ formValidator ->fields ['plugin_formcreator_forms_id ' ])->isEqualTo ($ form ->getID ());
406419 }
407420
@@ -415,9 +428,9 @@ public function testIncreateUsageCount() {
415428
416429 public function providerCreateValidationNotification () {
417430 // give email address to users
418- $ validator = new \ User ();
431+ $ validator = new User ();
419432 $ validator ->getFromDBbyName ('tech ' );
420- $ useremail = new \ UserEmail ();
433+ $ useremail = new UserEmail ();
421434 $ useremail ->deleteByCriteria ([
422435 'users_id ' => $ validator ->getID (),
423436 ]);
@@ -428,9 +441,9 @@ public function providerCreateValidationNotification() {
428441 ]
429442 ]);
430443
431- $ requester = new \ User ();
444+ $ requester = new User ();
432445 $ requester ->getFromDBbyName ('normal ' );
433- $ useremail = new \ UserEmail ();
446+ $ useremail = new UserEmail ();
434447 $ useremail ->deleteByCriteria ([
435448 'users_id ' => $ requester ->getID (),
436449 ]);
@@ -457,7 +470,7 @@ public function providerCreateValidationNotification() {
457470 /**
458471 * @dataProvider providerCreateValidationNotification
459472 */
460- public function testCreateValidationNotification (\ User $ requester , \ User $ validator , $ expectedNotificationCount ) {
473+ public function testCreateValidationNotification (User $ requester , User $ validator , $ expectedNotificationCount ) {
461474 global $ DB , $ CFG_GLPI ;
462475
463476 // Enable notifications in GLPI
@@ -908,6 +921,7 @@ public function testDuplicate() {
908921 'plugin_formcreator_forms_id ' => $ form ->getID (),
909922 ]);
910923
924+
911925 $ targetTicket_ids = [];
912926 $ targetChange_ids = [];
913927
0 commit comments