@@ -465,4 +465,48 @@ public function testGetColumnCreationQuery(string $expected, array $request): vo
465465 $ sqlQuery = $ this ->createAddField ->getColumnCreationQuery ('my_table ' );
466466 self ::assertSame ($ expected , $ sqlQuery );
467467 }
468+
469+ /**
470+ * Adding a column must not fail when the request does not contain the index
471+ * arrays (primary_indexes, indexes, unique_indexes, fulltext_indexes and
472+ * spatial_indexes). This happens for instance when a primary key column is
473+ * added from the normalization page, which does not submit those fields.
474+ *
475+ * Regression test for https://github.com/phpmyadmin/phpmyadmin/issues/18304
476+ */
477+ public function testGetColumnCreationQueryWithoutIndexPostVariables (): void
478+ {
479+ $ _POST = [
480+ 'db ' => '2fa ' ,
481+ 'field_where ' => 'after ' ,
482+ 'after_field ' => 'd ' ,
483+ 'table ' => 'aes ' ,
484+ 'orig_num_fields ' => '1 ' ,
485+ 'orig_field_where ' => 'after ' ,
486+ 'orig_after_field ' => 'd ' ,
487+ 'field_name ' => ['dd ' ],
488+ 'field_type ' => ['INT ' ],
489+ 'field_length ' => ['' ],
490+ 'field_default_type ' => ['NONE ' ],
491+ 'field_default_value ' => ['' ],
492+ 'field_collation ' => ['' ],
493+ 'field_attribute ' => ['' ],
494+ 'field_key ' => ['none_0 ' ],
495+ 'field_comments ' => ['' ],
496+ 'field_virtuality ' => ['' ],
497+ 'field_expression ' => ['' ],
498+ 'field_move_to ' => ['' ],
499+ 'field_mimetype ' => ['' ],
500+ 'field_transformation ' => ['' ],
501+ 'field_transformation_options ' => ['' ],
502+ 'field_input_transformation ' => ['' ],
503+ 'field_input_transformation_options ' => ['' ],
504+ 'do_save_data ' => '1 ' ,
505+ 'preview_sql ' => '1 ' ,
506+ 'ajax_request ' => '1 ' ,
507+ ];
508+
509+ $ sqlQuery = $ this ->createAddField ->getColumnCreationQuery ('my_table ' );
510+ self ::assertSame ('ALTER TABLE `my_table` ADD `dd` INT NOT NULL AFTER `d`; ' , $ sqlQuery );
511+ }
468512}
0 commit comments