@@ -882,4 +882,68 @@ public function testGetFromDbByTicket() {
882
882
$ this ->boolean ($ output )->isTrue ();
883
883
$ this ->integer ($ instance ->getID ())->isEqualTo ($ expected ->getID ());
884
884
}
885
+
886
+ public function providerParseTags () {
887
+ // Test a single text
888
+ $ question = $ this ->getQuestion ([
889
+ 'fieldtype ' => 'textarea ' ,
890
+ ]);
891
+ $ form = PluginFormcreatorForm::getByItem ($ question );
892
+ // Text as received in prepareInputForAdd (GLPI 10.0.6)
893
+ $ text = '<p> </p>\r\n<p> </p> ' ;
894
+
895
+ $ fieldKey = 'formcreator_field_ ' . $ question ->getID ();
896
+ $ formAnswer = $ this ->getFormAnswer ([
897
+ 'plugin_formcreator_forms_id ' => $ form ->getID (),
898
+ $ fieldKey => $ text ,
899
+ ]);
900
+
901
+ yield [
902
+ 'instance ' => $ formAnswer ,
903
+ 'template ' => '<p>##answer_ ' . $ question ->getID () . '##</p> ' ,
904
+ 'expected ' => '<p> ' . $ text . '</p> ' ,
905
+ ];
906
+
907
+ // Test a text with an embeddd image
908
+ $ question = $ this ->getQuestion ([
909
+ 'fieldtype ' => 'textarea ' ,
910
+ ]);
911
+ $ form = PluginFormcreatorForm::getByItem ($ question );
912
+ // Text as received in prepareInputForAdd (GLPI 10.0.6)
913
+ $ text = '<p><img id=\"20a8c58a-761764d0-63e0ff1245d9f4.97274571\" src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAMAAAACCAIAAAASFvFNAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAAEUlEQVQImWP8v5QBApgYYAAAHsMBqH3ykQkAAAAASUVORK5CYII=\" data-upload_id=\"0.7092882231779103\"></p> ' ;
914
+
915
+ $ fieldKey = 'formcreator_field_ ' . $ question ->getID ();
916
+ $ filename = '5e5e92ffd9bd91.44444444upload55555555.txt ' ;
917
+ $ tag = '3e29dffe-0237ea21-5e5e7034b1d1a1.33333333 ' ;
918
+ copy (dirname (__DIR__ ) . '/fixture/upload.txt ' , GLPI_TMP_DIR . '/ ' . $ filename );
919
+ $ formAnswer = $ this ->getFormAnswer ([
920
+ 'plugin_formcreator_forms_id ' => $ form ->getID (),
921
+ $ fieldKey => $ text ,
922
+ "_ {$ fieldKey }" => [
923
+ $ filename ,
924
+ ],
925
+ "_prefix_ {$ fieldKey }" => [
926
+ '5e5e92ffd9bd91.44444444 ' ,
927
+ ],
928
+ "_tag_ {$ fieldKey }" => [
929
+ $ tag ,
930
+ ],
931
+ ]);
932
+
933
+ yield [
934
+ 'instance ' => $ formAnswer ,
935
+ 'template ' => '<p>##answer_ ' . $ question ->getID () . '##</p> ' ,
936
+ 'expected ' => '<p> ' . $ text . '</p> ' ,
937
+ ];
938
+ }
939
+
940
+ /**
941
+ * @dataProvider providerParseTags
942
+ */
943
+ public function testParseTags ($ instance , $ template , $ expected ) {
944
+ $ ticket = new PluginFormcreatorTargetTicket ();
945
+
946
+ $ output = $ instance ->parseTags ($ template , $ ticket , true );
947
+ $ this ->string ($ output )->isEqualTo ($ expected );
948
+ }
885
949
}
0 commit comments