8686use Glpi \Form \QuestionType \QuestionTypeUrgency ;
8787use Glpi \Form \Section ;
8888use Glpi \Message \MessageType ;
89+ use Glpi \Migration \GenericobjectPluginMigration ;
8990use Glpi \Migration \PluginMigrationResult ;
9091use Glpi \Tests \FormTesterTrait ;
9192use GlpiPlugin \Tester \Form \QuestionTypeIpConverter ;
@@ -112,6 +113,13 @@ public static function setUpBeforeClass(): void
112113 foreach ($ queries as $ query ) {
113114 $ DB ->doQuery ($ query );
114115 }
116+
117+ // Some tests in this file also require generic objects migration so
118+ // we also load its tables.
119+ $ queries = $ DB ->getQueriesFromFile (sprintf ('%s/tests/fixtures/genericobject-migration/genericobject-db.sql ' , GLPI_ROOT ));
120+ foreach ($ queries as $ query ) {
121+ $ DB ->doQuery ($ query );
122+ }
115123 }
116124
117125 public static function tearDownAfterClass (): void
@@ -123,6 +131,11 @@ public static function tearDownAfterClass(): void
123131 $ DB ->dropTable ($ table ['TABLE_NAME ' ]);
124132 }
125133
134+ $ tables = $ DB ->listTables ('glpi\_plugin\_genericobject\_% ' );
135+ foreach ($ tables as $ table ) {
136+ $ DB ->dropTable ($ table ['TABLE_NAME ' ]);
137+ }
138+
126139 parent ::tearDownAfterClass ();
127140 }
128141
@@ -3587,6 +3600,42 @@ public function testVisiblePrivateFormMigration(): void
35873600 );
35883601 }
35893602
3603+ public function testFormWithQuestionReferencingGenericObject (): void
3604+ {
3605+ /** @var \DBmysql $DB */
3606+ global $ DB ;
3607+
3608+ // Arrange: create a form with a reference to generic object assets
3609+ $ this ->createSimpleFormcreatorForm ("With generic object " , [
3610+ [
3611+ 'name ' => 'Generic object ' ,
3612+ 'fieldtype ' => 'glpiselect ' ,
3613+ 'itemtype ' => "PluginGenericobjectSmartphone " ,
3614+ ],
3615+ ]);
3616+ // Migrated asset definition
3617+ $ asset_migrations = new GenericobjectPluginMigration ($ DB );
3618+ $ asset_migrations ->execute ();
3619+
3620+ // Act: try to import the form
3621+ $ migration = new FormMigration ($ DB , FormAccessControlManager::getInstance ());
3622+ $ migration ->execute ();
3623+
3624+ // Assert: make sure the question was imported with the correct type
3625+ $ form = getItemByTypeName (Form::class, "With generic object " );
3626+ $ question_id = $ this ->getQuestionId ($ form , "Generic object " );
3627+ $ question = Question::getById ($ question_id );
3628+
3629+ $ config = $ question ->getExtraDataConfig ();
3630+ if (!$ config instanceof QuestionTypeItemExtraDataConfig) {
3631+ $ this ->fail ("Unexpected config class " );
3632+ }
3633+ $ this ->assertEquals (
3634+ "Glpi\CustomAsset\smartphoneAsset " ,
3635+ $ config ->getItemtype ()
3636+ );
3637+ }
3638+
35903639 public function testNonVisiblePrivateFormMigration (): void
35913640 {
35923641 /** @var \DBmysql $DB */
0 commit comments