File tree Expand file tree Collapse file tree 2 files changed +25
-1
lines changed
src/Glpi/Form/QuestionType
tests/functional/Glpi/Form/Export Expand file tree Collapse file tree 2 files changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -675,7 +675,7 @@ public function exportDynamicExtraData(
675675 // Stop here if value is invalid or empty
676676 $ itemtype = $ extra_data_config [QuestionTypeItemExtraDataConfig::ITEMTYPE ] ?? "" ;
677677 $ root_id = $ extra_data_config [QuestionTypeItemDropdownExtraDataConfig::ROOT_ITEMS_ID ] ?? 0 ;
678- if ($ root_id = = 0 || !is_a ($ itemtype , CommonDBTM::class, true )) {
678+ if ($ root_id < = 0 || !is_a ($ itemtype , CommonDBTM::class, true )) {
679679 return $ fallback ;
680680 }
681681
@@ -708,6 +708,9 @@ public static function prepareDynamicExtraDataForImport(
708708 if (
709709 !(getItemForItemtype ($ itemtype ) instanceof CommonDBTM)
710710 || empty ($ name )
711+ // Both these values represent the root entity, no need to map it
712+ || $ name == 0
713+ || $ name == -1
711714 ) {
712715 return $ fallback ;
713716 }
Original file line number Diff line number Diff line change 9090use Ramsey \Uuid \Uuid ;
9191use Session ;
9292
93+ use function Safe \json_encode ;
94+
9395final class FormSerializerTest extends \DbTestCase
9496{
9597 use FormTesterTrait;
@@ -1682,6 +1684,25 @@ public function testTagsAreUpdatedWhenImporting(): void
16821684 );
16831685 }
16841686
1687+ public function testWithFormWithSpecialNegativeIdForRootEntity (): void
1688+ {
1689+ // Arrange: create a form with a -1 value for root_items_id
1690+ $ builder = new FormBuilder ("My form " );
1691+ $ extra_data = new QuestionTypeItemExtraDataConfig (
1692+ itemtype: Entity::class,
1693+ root_items_id: -1 ,
1694+ );
1695+ $ builder ->addQuestion (
1696+ name: "Entity " ,
1697+ type: QuestionTypeItem::class,
1698+ extra_data: json_encode ($ extra_data )
1699+ );
1700+ $ form = $ this ->createForm ($ builder );
1701+
1702+ // Act: export the form, no error should happen
1703+ $ this ->exportAndImportForm ($ form );
1704+ }
1705+
16851706 private function compareValuesForRelations (
16861707 $ relations ,
16871708 $ ids_for_default_form ,
You can’t perform that action at this time.
0 commit comments