8585use Glpi \Form \QuestionType \QuestionTypeUrgency ;
8686use Glpi \Form \Section ;
8787use Glpi \Message \MessageType ;
88+ use Glpi \Migration \GenericobjectPluginMigration ;
8889use Glpi \Migration \PluginMigrationResult ;
8990use Glpi \Tests \FormTesterTrait ;
9091use GlpiPlugin \Tester \Form \QuestionTypeIpConverter ;
@@ -110,6 +111,13 @@ public static function setUpBeforeClass(): void
110111 foreach ($ queries as $ query ) {
111112 $ DB ->doQuery ($ query );
112113 }
114+
115+ // Some tests in this file also require generic objects migration so
116+ // we also load its tables.
117+ $ queries = $ DB ->getQueriesFromFile (sprintf ('%s/tests/fixtures/genericobject-migration/genericobject-db.sql ' , GLPI_ROOT ));
118+ foreach ($ queries as $ query ) {
119+ $ DB ->doQuery ($ query );
120+ }
113121 }
114122
115123 public static function tearDownAfterClass (): void
@@ -121,6 +129,11 @@ public static function tearDownAfterClass(): void
121129 $ DB ->dropTable ($ table ['TABLE_NAME ' ]);
122130 }
123131
132+ $ tables = $ DB ->listTables ('glpi\_plugin\_genericobject\_% ' );
133+ foreach ($ tables as $ table ) {
134+ $ DB ->dropTable ($ table ['TABLE_NAME ' ]);
135+ }
136+
124137 parent ::tearDownAfterClass ();
125138 }
126139
@@ -3384,6 +3397,42 @@ public function testFormWithConditionsOnInvalidQuestionForSubmitButton(): void
33843397 $ this ->assertTrue ($ result ->isFullyProcessed ());
33853398 }
33863399
3400+ public function testFormWithQuestionReferencingGenericObject (): void
3401+ {
3402+ /** @var \DBmysql $DB */
3403+ global $ DB ;
3404+
3405+ // Arrange: create a form with a reference to generic object assets
3406+ $ this ->createSimpleFormcreatorForm ("With generic object " , [
3407+ [
3408+ 'name ' => 'Generic object ' ,
3409+ 'fieldtype ' => 'glpiselect ' ,
3410+ 'itemtype ' => "PluginGenericobjectSmartphone " ,
3411+ ],
3412+ ]);
3413+ // Migrated asset definition
3414+ $ asset_migrations = new GenericobjectPluginMigration ($ DB );
3415+ $ asset_migrations ->execute ();
3416+
3417+ // Act: try to import the form
3418+ $ migration = new FormMigration ($ DB , FormAccessControlManager::getInstance ());
3419+ $ migration ->execute ();
3420+
3421+ // Assert: make sure the question was imported with the correct type
3422+ $ form = getItemByTypeName (Form::class, "With generic object " );
3423+ $ question_id = $ this ->getQuestionId ($ form , "Generic object " );
3424+ $ question = Question::getById ($ question_id );
3425+
3426+ $ config = $ question ->getExtraDataConfig ();
3427+ if (!$ config instanceof QuestionTypeItemExtraDataConfig) {
3428+ $ this ->fail ("Unexpected config class " );
3429+ }
3430+ $ this ->assertEquals (
3431+ "Glpi\CustomAsset\smartphoneAsset " ,
3432+ $ config ->getItemtype ()
3433+ );
3434+ }
3435+
33873436 protected function createSimpleFormcreatorForm (
33883437 string $ name ,
33893438 array $ questions ,
0 commit comments