3535use GlpiPlugin \Field \Tests \QuestionTypeTestCase ;
3636use LogicException ;
3737use PluginFieldsContainer ;
38+ use PluginFieldsDropdown ;
3839use PluginFieldsField ;
3940use PluginFieldsQuestionType ;
4041use PluginFieldsQuestionTypeCategory ;
@@ -117,7 +118,7 @@ public function testFieldsQuestionEditorRendering(): void
117118 $ builder ->addQuestion (
118119 "My question " ,
119120 PluginFieldsQuestionType::class,
120- extra_data: json_encode ($ this ->getFieldExtraDataConfig ()),
121+ extra_data: json_encode ($ this ->getFieldExtraDataConfig (' glpi_item ' )),
121122 );
122123 $ form = $ this ->createForm ($ builder );
123124
@@ -137,7 +138,7 @@ public function testFieldsQuestionHelpdeskRendering(): void
137138 $ builder ->addQuestion (
138139 "My question " ,
139140 PluginFieldsQuestionType::class,
140- extra_data: json_encode ($ this ->getFieldExtraDataConfig ()),
141+ extra_data: json_encode ($ this ->getFieldExtraDataConfig (' glpi_item ' )),
141142 );
142143 $ form = $ this ->createForm ($ builder );
143144
@@ -148,12 +149,40 @@ public function testFieldsQuestionHelpdeskRendering(): void
148149 $ this ->assertNotEmpty ($ crawler ->filter ('[data-glpi-form-renderer-fields-question-type-specific-container] ' ));
149150 }
150151
151- private function getFieldExtraDataConfig (): PluginFieldsQuestionTypeExtraDataConfig
152+ public function testFieldsQuestionSubmitEmptyDropdown (): void
152153 {
153- if (!$ this ->block instanceof PluginFieldsContainer || !$ this ->field instanceof PluginFieldsField) {
154+ $ this ->login ();
155+
156+ /** @var CommonDBTM $dropdown_item */
157+ $ dropdown_item = getItemForItemtype (PluginFieldsDropdown::getClassname ($ this ->fields ['dropdown ' ]->fields ['name ' ]));
158+ $ dropdown_ids = [];
159+ for ($ i = 1 ; $ i <= 3 ; $ i ++) {
160+ $ dropdown_ids [] = $ dropdown_item ->add ([
161+ 'name ' => 'Option ' . $ i ,
162+ ]);
163+ }
164+
165+ // Arrange: create form with Field question
166+ $ builder = new FormBuilder ("My form " );
167+ $ builder ->addQuestion (
168+ "Dropdown field question " ,
169+ PluginFieldsQuestionType::class,
170+ extra_data: json_encode ($ this ->getFieldExtraDataConfig ('dropdown ' )),
171+ );
172+ $ form = $ this ->createForm ($ builder );
173+
174+ // Act: submit form
175+ $ this ->sendFormAndGetCreatedTicket ($ form , [
176+ "Dropdown field question " => '0 ' ,
177+ ]);
178+ }
179+
180+ private function getFieldExtraDataConfig (string $ field_name ): PluginFieldsQuestionTypeExtraDataConfig
181+ {
182+ if (!$ this ->block instanceof PluginFieldsContainer || !$ this ->fields [$ field_name ] instanceof PluginFieldsField) {
154183 throw new LogicException ("Field and container must be created before getting extra data config " );
155184 }
156185
157- return new PluginFieldsQuestionTypeExtraDataConfig ($ this ->block ->getID (), $ this ->field ->getID ());
186+ return new PluginFieldsQuestionTypeExtraDataConfig ($ this ->block ->getID (), $ this ->fields [ $ field_name ] ->getID ());
158187 }
159188}
0 commit comments