@@ -39,6 +39,7 @@ public function beforeTestMethod($method) {
3939 parent ::beforeTestMethod ($ method );
4040 switch ($ method ) {
4141 case 'testImport ' :
42+ case 'testCanPurgeItem ' :
4243 self ::login ('glpi ' , 'glpi ' );
4344 }
4445 }
@@ -113,6 +114,19 @@ public function testCanPurge() {
113114 $ this ->boolean ((bool ) $ output )->isFalse ();
114115 }
115116
117+ public function testCanPurgeItem () {
118+ $ form = $ this ->getForm ();
119+ $ output = $ form ->canPurgeItem ();
120+ $ this ->boolean ((boolean ) $ output )->isTrue ();
121+
122+ $ form ->saveForm ([
123+ \PluginFormcreatorForm::getForeignKeyField () => $ form ->getID (),
124+ ]);
125+
126+ $ output = $ form ->canPurgeItem ();
127+ $ this ->boolean ((boolean ) $ output )->isFalse ();
128+ }
129+
116130 protected function formProvider () {
117131 return [
118132 [
@@ -204,18 +218,81 @@ public function testPrepareInputForUpdate($input, $expected, $expectedMessage) {
204218 }
205219 }
206220
207- /**
208- * @dataProvider formProvider
209- */
210- public function testPurgeForm ($ formData ) {
211- $ form = new \PluginFormcreatorForm ();
212- $ form ->add ($ formData );
213- $ this ->boolean ($ form ->isNewItem ())->isFalse ();
221+ public function testDefineTabs () {
222+ $ form = $ this ->getForm ();
223+ $ output = $ form ->defineTabs ();
224+ $ this ->array ($ output )->isEqualTo ([
225+ 'PluginFormcreatorForm$main ' => "Form " ,
226+ 'PluginFormcreatorQuestion$1 ' => "Questions " ,
227+ 'PluginFormcreatorForm_Profile$1 ' => "Access types " ,
228+ 'PluginFormcreatorForm$1 ' => "Targets " ,
229+ 'PluginFormcreatorForm$2 ' => "Preview " ,
230+ 'PluginFormcreatorFormAnswer$1 ' => "Form answers " ,
231+ ]);
232+ }
233+
234+ public function testGetTabNameForItem () {
235+ $ form = $ this ->getForm ();
236+ $ item = new \Central ();
237+ $ output = $ form ->getTabNameForItem ($ item );
238+ $ this ->string ($ output )->isEqualTo ('Forms ' );
239+
240+ $ item = $ form ;
241+ $ output = $ form ->getTabNameForItem ($ item );
242+ $ this ->array ($ output )->isEqualTo ([
243+ 1 => 'Targets ' ,
244+ 2 => 'Preview ' ,
245+ ]);
246+
247+ $ item = new \User ();
248+ $ output = $ form ->getTabNameForItem ($ item );
249+ $ this ->string ($ output )->isEqualTo ('' );
250+ }
251+
252+ public function testPost_purgeItem () {
253+ $ form = $ this ->getForm ([
254+ 'validation_required ' => \PluginFormcreatorForm_Validator::VALIDATION_USER ,
255+ 'users_id ' => 2 , // glpi
256+ ]);
257+ $ section = $ this ->getSection ([
258+ 'plugin_formcreator_forms_id ' => $ form ->getID (),
259+ ]);
260+ $ targetChange = $ this ->getTargetChange ([
261+ 'plugin_formcreator_forms_id ' => $ form ->getID (),
262+ ]);
263+ $ targetTicket = $ this ->getTargetTicket ([
264+ 'plugin_formcreator_forms_id ' => $ form ->getID (),
265+ ]);
266+ $ validator = new \PluginFormcreatorForm_Validator ();
267+ $ validator ->getFromDBByCrit ([
268+ 'plugin_formcreator_forms_id ' => $ form ->getID (),
269+ 'itemtype ' => \User::class,
270+ ]);
214271
215- $ success = $ form ->delete ([
216- 'id ' => $ form ->getID (),
272+ $ formProfile = new \PluginFormcreatorForm_Profile ();
273+ $ formProfile ->add ([
274+ 'plugin_formcreator_forms_id ' => $ form ->getID (),
275+ 'profiles_id ' => 6 // technician
276+ ]);
277+
278+ $ form ->delete ([
279+ 'id ' => $ form ->getID (),
217280 ], 1 );
218- $ this ->boolean ($ success )->isTrue ();
281+
282+ $ output = $ section ->getFromDB ($ section ->getID ()) ;
283+ $ this ->boolean ($ output )->isFalse ();
284+
285+ $ output = $ targetChange ->getFromDB ($ targetChange ->getID ());
286+ $ this ->boolean ($ output )->isFalse ();
287+
288+ $ output = $ targetTicket ->getFromDB ($ targetTicket ->getID ());
289+ $ this ->boolean ($ output )->isFalse ();
290+
291+ $ output = $ validator ->getFromDB ($ validator ->getID ());
292+ $ this ->boolean ($ output )->isFalse ();
293+
294+ $ output = $ formProfile ->getFromDB ($ formProfile ->getID ());
295+ $ this ->boolean ($ output )->isFalse ();
219296 }
220297
221298 public function testCreateValidationNotification () {
0 commit comments