@@ -741,4 +741,48 @@ public function testSetTargetCategory() {
741
741
// $output = $instance->publicSetTargetCategory($data, $formAnswer);
742
742
// $this->integer((int) $output['itilcategories_id'])->isEqualTo($expected['itilcategories_id']);
743
743
}
744
+
745
+ public function testSetTargetAssociatedItem () {
746
+ $ instance = new PluginFormcreatorTargetTicketDummy ();
747
+ $ question = $ this ->getQuestion ([
748
+ 'fieldtype ' => 'glpiselect ' ,
749
+ 'values ' => \Computer::class,
750
+ ]);
751
+ $ form = new \PluginFormcreatorForm ();
752
+ $ form ->getByQuestionId ($ question ->getID ());
753
+
754
+ $ computer = new \Computer ();
755
+ $ computer ->add ([
756
+ 'name ' => $ this ->getUniqueString (),
757
+ 'entities_id ' => '0 ' ,
758
+ ]);
759
+ $ this ->boolean ($ computer ->isNewItem ())->isFalse ();
760
+ $ formAnswer = new \PluginFormcreatorFormAnswer ;
761
+ $ formAnswer ->add ([
762
+ \PluginFormcreatorForm::getForeignKeyField () => $ form ->getID (),
763
+ 'name ' => $ form ->fields ['name ' ],
764
+ 'requester_d ' => 2 , // glpi user id
765
+ 'status ' => '101 ' ,
766
+ ]);
767
+ $ this ->boolean ($ formAnswer ->isNewItem ())->isFalse ();
768
+ $ answer = new \PluginFormcreatorAnswer ();
769
+ $ answer ->add ([
770
+ \PluginFormcreatorFormAnswer::getForeignKeyField () => $ formAnswer ->getID (),
771
+ \PluginFormcreatorQuestion::getForeignKeyField () => $ question ->getID (),
772
+ 'answer ' => $ computer ->getID (),
773
+ ]);
774
+ $ this ->boolean ($ answer ->isNewItem ())->isFalse ();
775
+ $ instance ->add ([
776
+ 'name ' => '' ,
777
+ 'target_name ' => '' ,
778
+ \PluginFormcreatorForm::getForeignKeyField () => $ form ->getID (),
779
+ 'content ' => '##FULLFORM ' ,
780
+ 'associate_rule ' => \PluginFormcreatorTargetTicket::ASSOCIATE_RULE_ANSWER ,
781
+ 'associate_question ' => $ question ->getID (),
782
+ ]);
783
+ $ this ->boolean ($ instance ->isNewItem ())->isFalse ();
784
+ $ output = $ instance ->publicSetTargetAssociatedItem ([], $ formAnswer );
785
+ $ this ->array ($ output ['items_id ' ]['Computer ' ])->hasSize (1 );
786
+ $ this ->integer ((int ) $ output ['items_id ' ]['Computer ' ][$ computer ->getID ()])->isEqualTo ($ computer ->getID ());
787
+ }
744
788
}
0 commit comments