2929 * ---------------------------------------------------------------------
3030 */
3131namespace tests \units ;
32+ use Config ;
3233use GlpiPlugin \Formcreator \Tests \CommonTestCase ;
34+ use PluginFormcreatorSection ;
35+ use PluginFormcreatorQuestion ;
36+ use PluginFormcreatorForm_Language ;
3337
3438class PluginFormcreatorForm extends CommonTestCase {
3539
@@ -49,7 +53,7 @@ public function beforeTestMethod($method) {
4953
5054 switch ($ method ) {
5155 case 'testCreateValidationNotification ' :
52- \ Config::setConfigurationValues (
56+ Config::setConfigurationValues (
5357 'core ' ,
5458 ['use_notifications ' => 1 , 'notifications_mailing ' => 1 ]
5559 );
@@ -60,7 +64,7 @@ public function afterTestMethod($method) {
6064 parent ::afterTestMethod ($ method );
6165 switch ($ method ) {
6266 case 'testCreateValidationNotification ' :
63- \ Config::setConfigurationValues (
67+ Config::setConfigurationValues (
6468 'core ' ,
6569 ['use_notifications ' => 0 , 'notifications_mailing ' => 0 ]
6670 );
@@ -626,32 +630,61 @@ public function testIsPublicAcess($input, $expected) {
626630 }
627631
628632 public function providerGetByItem () {
633+ $ testedClassName = $ this ->getTestedClassName ();
634+ $ formFk = $ testedClassName ::getForeignKeyField ();
629635 $ section = $ this ->getSection ();
636+
637+ $ expected_id = $ section ->fields ['plugin_formcreator_forms_id ' ];
638+ yield [
639+ 'item ' => $ section ,
640+ 'expectedType ' => $ testedClassName ,
641+ 'expected ' => $ expected_id ,
642+ ];
643+
644+ yield [
645+ 'item ' => new PluginFormcreatorSection (),
646+ 'expectedType ' => $ testedClassName ,
647+ 'expected ' => false ,
648+ ];
649+
630650 $ question = $ this ->getQuestion ();
651+ $ section = PluginFormcreatorSection::getById ($ question ->fields ['plugin_formcreator_sections_id ' ]);
652+ $ expected_id = $ section ->fields ['plugin_formcreator_forms_id ' ];
653+ yield [
654+ 'item ' => $ question ,
655+ 'expectedType ' => $ testedClassName ,
656+ 'expected ' => $ expected_id ,
657+ ];
631658
632- $ dataset = [
633- [
634- 'item ' => $ section ,
635- 'expectedType ' => \PluginFormcreatorForm::getType (),
636- 'expected ' => true ,
637- ],
638- [
639- 'item ' => new \PluginFormcreatorSection (),
640- 'expectedType ' => \PluginFormcreatorForm::getType (),
641- 'expected ' => false ,
642- ],
643- [
644- 'item ' => $ question ,
645- 'expectedType ' => \PluginFormcreatorForm::getType (),
646- 'expected ' => true ,
647- ],
648- [
649- 'item ' => new \PluginFormcreatorQuestion (),
650- 'expectedType ' => \PluginFormcreatorForm::getType (),
651- 'expected ' => false ,
652- ],
659+ yield [
660+ 'item ' => new PluginFormcreatorQuestion (),
661+ 'expectedType ' => $ testedClassName ,
662+ 'expected ' => false ,
663+ ];
664+
665+ $ form = $ this ->getForm ();
666+ $ formAnswer = $ this ->getFormAnswer ([
667+ $ formFk => $ form ->getID (),
668+ ]);
669+
670+ yield [
671+ 'item ' => $ formAnswer ,
672+ 'expectedType ' => $ testedClassName ,
673+ 'expected ' => $ formAnswer ->fields [$ formFk ],
674+ ];
675+
676+ $ form_language = new PluginFormcreatorForm_Language ();
677+ $ form_language ->add ([
678+ $ formFk => $ form ->getID (),
679+ 'name ' => 'fr_FR ' ,
680+ ]);
681+ $ this ->boolean ($ form_language ->isNewItem ())->isFalse ();
682+
683+ yield [
684+ 'item ' => $ form_language ,
685+ 'expectedType ' => $ testedClassName ,
686+ 'expected ' => $ form_language ->fields [$ formFk ],
653687 ];
654- return $ dataset ;
655688 }
656689
657690 /**
@@ -898,9 +931,9 @@ public function testDuplicate() {
898931 $ this ->string ($ new_form ->getField ('uuid ' ))->isNotEqualTo ($ form ->getField ('uuid ' ));
899932
900933 // check sections
901- $ all_sections = (new \ PluginFormcreatorSection ())->getSectionsFromForm ($ form ->getID ());
934+ $ all_sections = (new PluginFormcreatorSection ())->getSectionsFromForm ($ form ->getID ());
902935 $ this ->integer (count ($ all_sections ))->isEqualTo (count ($ section_ids ));
903- $ all_new_sections = (new \ PluginFormcreatorSection ())->getSectionsFromForm ($ new_form ->getID ());
936+ $ all_new_sections = (new PluginFormcreatorSection ())->getSectionsFromForm ($ new_form ->getID ());
904937 $ this ->integer (count ($ all_sections ))->isEqualTo (count ($ section_ids ));
905938
906939 // check that all sections uuid are new
@@ -1349,14 +1382,14 @@ public function testAdd() {
13491382 ]);
13501383
13511384 $ this ->boolean ($ instance ->isNewItem ())->isFalse ();
1352- $ section = new \ PluginFormcreatorSection ();
1385+ $ section = new PluginFormcreatorSection ();
13531386 $ rows = $ section ->find ([
13541387 'plugin_formcreator_forms_id ' => $ instance ->getID (),
13551388 ]);
13561389
13571390 $ this ->array ($ rows )->hasSize (1 );
13581391 $ row = array_shift ($ rows );
1359- $ this ->string ($ row ['name ' ])->isEqualTo (\ PluginFormcreatorSection::getTypeName (1 ));
1392+ $ this ->string ($ row ['name ' ])->isEqualTo (PluginFormcreatorSection::getTypeName (1 ));
13601393 }
13611394
13621395 /**
0 commit comments