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 ;
@@ -111,6 +112,13 @@ public static function setUpBeforeClass(): void
111112 foreach ($ queries as $ query ) {
112113 $ DB ->doQuery ($ query );
113114 }
115+
116+ // Some tests in this file also require generic objects migration so
117+ // we also load its tables.
118+ $ queries = $ DB ->getQueriesFromFile (sprintf ('%s/tests/fixtures/genericobject-migration/genericobject-db.sql ' , GLPI_ROOT ));
119+ foreach ($ queries as $ query ) {
120+ $ DB ->doQuery ($ query );
121+ }
114122 }
115123
116124 public static function tearDownAfterClass (): void
@@ -122,6 +130,11 @@ public static function tearDownAfterClass(): void
122130 $ DB ->dropTable ($ table ['TABLE_NAME ' ]);
123131 }
124132
133+ $ tables = $ DB ->listTables ('glpi\_plugin\_genericobject\_% ' );
134+ foreach ($ tables as $ table ) {
135+ $ DB ->dropTable ($ table ['TABLE_NAME ' ]);
136+ }
137+
125138 parent ::tearDownAfterClass ();
126139 }
127140
@@ -3453,6 +3466,42 @@ public function testFormWithConditionOnCategories(): void
34533466 ], $ condition_data ->getValue ());
34543467 }
34553468
3469+ public function testFormWithQuestionReferencingGenericObject (): void
3470+ {
3471+ /** @var \DBmysql $DB */
3472+ global $ DB ;
3473+
3474+ // Arrange: create a form with a reference to generic object assets
3475+ $ this ->createSimpleFormcreatorForm ("With generic object " , [
3476+ [
3477+ 'name ' => 'Generic object ' ,
3478+ 'fieldtype ' => 'glpiselect ' ,
3479+ 'itemtype ' => "PluginGenericobjectSmartphone " ,
3480+ ],
3481+ ]);
3482+ // Migrated asset definition
3483+ $ asset_migrations = new GenericobjectPluginMigration ($ DB );
3484+ $ asset_migrations ->execute ();
3485+
3486+ // Act: try to import the form
3487+ $ migration = new FormMigration ($ DB , FormAccessControlManager::getInstance ());
3488+ $ migration ->execute ();
3489+
3490+ // Assert: make sure the question was imported with the correct type
3491+ $ form = getItemByTypeName (Form::class, "With generic object " );
3492+ $ question_id = $ this ->getQuestionId ($ form , "Generic object " );
3493+ $ question = Question::getById ($ question_id );
3494+
3495+ $ config = $ question ->getExtraDataConfig ();
3496+ if (!$ config instanceof QuestionTypeItemExtraDataConfig) {
3497+ $ this ->fail ("Unexpected config class " );
3498+ }
3499+ $ this ->assertEquals (
3500+ "Glpi\CustomAsset\smartphoneAsset " ,
3501+ $ config ->getItemtype ()
3502+ );
3503+ }
3504+
34563505 protected function createSimpleFormcreatorForm (
34573506 string $ name ,
34583507 array $ questions ,
0 commit comments