|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace PhpMyAdmin\Tests\Controllers\Table; |
| 6 | + |
| 7 | +use PhpMyAdmin\Config; |
| 8 | +use PhpMyAdmin\ConfigStorage\Relation; |
| 9 | +use PhpMyAdmin\Controllers\Table\CreateController; |
| 10 | +use PhpMyAdmin\Template; |
| 11 | +use PhpMyAdmin\Tests\AbstractTestCase; |
| 12 | +use PhpMyAdmin\Tests\Stubs\ResponseRenderer; |
| 13 | +use PhpMyAdmin\Transformations; |
| 14 | + |
| 15 | +use function array_merge; |
| 16 | + |
| 17 | +/** |
| 18 | + * @covers \PhpMyAdmin\Controllers\Table\CreateController |
| 19 | + */ |
| 20 | +class CreateControllerTest extends AbstractTestCase |
| 21 | +{ |
| 22 | + public function testCreateController(): void |
| 23 | + { |
| 24 | + $GLOBALS['db'] = 'test_db'; |
| 25 | + $GLOBALS['table'] = 'new_test_table'; |
| 26 | + $GLOBALS['cfg']['Server'] = $GLOBALS['config']->defaultServer; |
| 27 | + $_POST = ['db' => 'test_db', 'table' => 'new_test_table', 'num_fields' => '2']; |
| 28 | + |
| 29 | + $this->dummyDbi->addSelectDb('test_db'); |
| 30 | + $this->dummyDbi->addResult('SHOW COLUMNS FROM `test_db`.`new_test_table`', false); |
| 31 | + $this->dummyDbi->addResult('SHOW FULL COLUMNS FROM `test_db`.`new_test_table`', false); |
| 32 | + $this->dummyDbi->addResult('SHOW CREATE TABLE `test_db`.`new_test_table`', false); |
| 33 | + |
| 34 | + $contentCell = [ |
| 35 | + 'column_number' => 0, |
| 36 | + 'column_meta' => ['Type' => ''], |
| 37 | + 'type_upper' => '', |
| 38 | + 'default_value' => '', |
| 39 | + 'length_values_input_size' => 8, |
| 40 | + 'length' => '', |
| 41 | + 'extracted_columnspec' => [], |
| 42 | + 'submit_attribute' => null, |
| 43 | + 'comments_map' => [], |
| 44 | + 'fields_meta' => null, |
| 45 | + 'is_backup' => false, |
| 46 | + 'move_columns' => [], |
| 47 | + 'available_mime' => [ |
| 48 | + 'mimetype' => [ |
| 49 | + 'Image/JPEG' => 'Image/JPEG', |
| 50 | + 'Text/Plain' => 'Text/Plain', |
| 51 | + 'Application/Octetstream' => 'Application/Octetstream', |
| 52 | + 'Image/PNG' => 'Image/PNG', |
| 53 | + 'Text/Octetstream' => 'Text/Octetstream', |
| 54 | + ], |
| 55 | + 'input_transformation' => [ |
| 56 | + 'Image/JPEG: Upload', |
| 57 | + 'Text/Plain: FileUpload', |
| 58 | + 'Text/Plain: Iptobinary', |
| 59 | + 'Text/Plain: Iptolong', |
| 60 | + 'Text/Plain: JsonEditor', |
| 61 | + 'Text/Plain: RegexValidation', |
| 62 | + 'Text/Plain: SqlEditor', |
| 63 | + 'Text/Plain: XmlEditor', |
| 64 | + 'Text/Plain: Link', |
| 65 | + 'Text/Plain: Longtoipv4', |
| 66 | + 'Text/Plain: PreApPend', |
| 67 | + 'Text/Plain: Substring', |
| 68 | + ], |
| 69 | + 'input_transformation_file' => [ |
| 70 | + 'Input/Image_JPEG_Upload.php', |
| 71 | + 'Input/Text_Plain_FileUpload.php', |
| 72 | + 'Input/Text_Plain_Iptobinary.php', |
| 73 | + 'Input/Text_Plain_Iptolong.php', |
| 74 | + 'Input/Text_Plain_JsonEditor.php', |
| 75 | + 'Input/Text_Plain_RegexValidation.php', |
| 76 | + 'Input/Text_Plain_SqlEditor.php', |
| 77 | + 'Input/Text_Plain_XmlEditor.php', |
| 78 | + 'Text_Plain_Link.php', |
| 79 | + 'Text_Plain_Longtoipv4.php', |
| 80 | + 'Text_Plain_PreApPend.php', |
| 81 | + 'Text_Plain_Substring.php', |
| 82 | + ], |
| 83 | + 'transformation' => [ |
| 84 | + 'Application/Octetstream: Download', |
| 85 | + 'Application/Octetstream: Hex', |
| 86 | + 'Image/JPEG: Inline', |
| 87 | + 'Image/JPEG: Link', |
| 88 | + 'Image/PNG: Inline', |
| 89 | + 'Text/Octetstream: Sql', |
| 90 | + 'Text/Plain: Binarytoip', |
| 91 | + 'Text/Plain: Bool2Text', |
| 92 | + 'Text/Plain: Dateformat', |
| 93 | + 'Text/Plain: External', |
| 94 | + 'Text/Plain: Formatted', |
| 95 | + 'Text/Plain: Imagelink', |
| 96 | + 'Text/Plain: Json', |
| 97 | + 'Text/Plain: Sql', |
| 98 | + 'Text/Plain: Xml', |
| 99 | + 'Text/Plain: Link', |
| 100 | + 'Text/Plain: Longtoipv4', |
| 101 | + 'Text/Plain: PreApPend', |
| 102 | + 'Text/Plain: Substring', |
| 103 | + ], |
| 104 | + 'transformation_file' => [ |
| 105 | + 'Output/Application_Octetstream_Download.php', |
| 106 | + 'Output/Application_Octetstream_Hex.php', |
| 107 | + 'Output/Image_JPEG_Inline.php', |
| 108 | + 'Output/Image_JPEG_Link.php', |
| 109 | + 'Output/Image_PNG_Inline.php', |
| 110 | + 'Output/Text_Octetstream_Sql.php', |
| 111 | + 'Output/Text_Plain_Binarytoip.php', |
| 112 | + 'Output/Text_Plain_Bool2Text.php', |
| 113 | + 'Output/Text_Plain_Dateformat.php', |
| 114 | + 'Output/Text_Plain_External.php', |
| 115 | + 'Output/Text_Plain_Formatted.php', |
| 116 | + 'Output/Text_Plain_Imagelink.php', |
| 117 | + 'Output/Text_Plain_Json.php', |
| 118 | + 'Output/Text_Plain_Sql.php', |
| 119 | + 'Output/Text_Plain_Xml.php', |
| 120 | + 'Text_Plain_Link.php', |
| 121 | + 'Text_Plain_Longtoipv4.php', |
| 122 | + 'Text_Plain_PreApPend.php', |
| 123 | + 'Text_Plain_Substring.php', |
| 124 | + ], |
| 125 | + 'input_transformation_file_quoted' => [ |
| 126 | + 'Input/Image_JPEG_Upload\\.php', |
| 127 | + 'Input/Text_Plain_FileUpload\\.php', |
| 128 | + 'Input/Text_Plain_Iptobinary\\.php', |
| 129 | + 'Input/Text_Plain_Iptolong\\.php', |
| 130 | + 'Input/Text_Plain_JsonEditor\\.php', |
| 131 | + 'Input/Text_Plain_RegexValidation\\.php', |
| 132 | + 'Input/Text_Plain_SqlEditor\\.php', |
| 133 | + 'Input/Text_Plain_XmlEditor\\.php', |
| 134 | + 'Text_Plain_Link\\.php', |
| 135 | + 'Text_Plain_Longtoipv4\\.php', |
| 136 | + 'Text_Plain_PreApPend\\.php', |
| 137 | + 'Text_Plain_Substring\\.php', |
| 138 | + ], |
| 139 | + 'transformation_file_quoted' => [ |
| 140 | + 'Output/Application_Octetstream_Download\\.php', |
| 141 | + 'Output/Application_Octetstream_Hex\\.php', |
| 142 | + 'Output/Image_JPEG_Inline\\.php', |
| 143 | + 'Output/Image_JPEG_Link\\.php', |
| 144 | + 'Output/Image_PNG_Inline\\.php', |
| 145 | + 'Output/Text_Octetstream_Sql\\.php', |
| 146 | + 'Output/Text_Plain_Binarytoip\\.php', |
| 147 | + 'Output/Text_Plain_Bool2Text\\.php', |
| 148 | + 'Output/Text_Plain_Dateformat\\.php', |
| 149 | + 'Output/Text_Plain_External\\.php', |
| 150 | + 'Output/Text_Plain_Formatted\\.php', |
| 151 | + 'Output/Text_Plain_Imagelink\\.php', |
| 152 | + 'Output/Text_Plain_Json\\.php', |
| 153 | + 'Output/Text_Plain_Sql\\.php', |
| 154 | + 'Output/Text_Plain_Xml\\.php', |
| 155 | + 'Text_Plain_Link\\.php', |
| 156 | + 'Text_Plain_Longtoipv4\\.php', |
| 157 | + 'Text_Plain_PreApPend\\.php', |
| 158 | + 'Text_Plain_Substring\\.php', |
| 159 | + ], |
| 160 | + ], |
| 161 | + 'mime_map' => [], |
| 162 | + ]; |
| 163 | + |
| 164 | + $relation = new Relation($this->dbi); |
| 165 | + $response = new ResponseRenderer(); |
| 166 | + $template = new Template(); |
| 167 | + $expected = $template->render('columns_definitions/column_definitions_form', [ |
| 168 | + 'is_backup' => false, |
| 169 | + 'fields_meta' => null, |
| 170 | + 'relation_parameters' => $relation->getRelationParameters(), |
| 171 | + 'action' => 'index.php?route=/table/create&lang=en', |
| 172 | + 'form_params' => [ |
| 173 | + 'db' => 'test_db', |
| 174 | + 'reload' => 1, |
| 175 | + 'orig_num_fields' => 2, |
| 176 | + 'orig_field_where' => null, |
| 177 | + 'orig_after_field' => null, |
| 178 | + ], |
| 179 | + 'content_cells' => [$contentCell, array_merge($contentCell, ['column_number' => 1])], |
| 180 | + 'partition_details' => [ |
| 181 | + 'partition_by' => null, |
| 182 | + 'partition_expr' => null, |
| 183 | + 'subpartition_by' => null, |
| 184 | + 'subpartition_expr' => null, |
| 185 | + 'partition_count' => 0, |
| 186 | + 'subpartition_count' => 0, |
| 187 | + 'can_have_subpartitions' => false, |
| 188 | + 'value_enabled' => false, |
| 189 | + ], |
| 190 | + 'primary_indexes' => null, |
| 191 | + 'unique_indexes' => null, |
| 192 | + 'indexes' => null, |
| 193 | + 'fulltext_indexes' => null, |
| 194 | + 'spatial_indexes' => null, |
| 195 | + 'table' => 'new_test_table', |
| 196 | + 'comment' => null, |
| 197 | + 'tbl_collation' => null, |
| 198 | + 'charsets' => [ |
| 199 | + [ |
| 200 | + 'name' => 'armscii8', |
| 201 | + 'description' => 'armscii8_general_ci', |
| 202 | + 'collations' => [['name' => 'armscii8_general_ci', 'description' => 'Armenian, case-insensitive']], |
| 203 | + ], |
| 204 | + [ |
| 205 | + 'name' => 'latin1', |
| 206 | + 'description' => 'cp1252 West European', |
| 207 | + 'collations' => [['name' => 'latin1_swedish_ci', 'description' => 'Swedish, case-insensitive']], |
| 208 | + ], |
| 209 | + [ |
| 210 | + 'name' => 'utf8', |
| 211 | + 'description' => 'UTF-8 Unicode', |
| 212 | + 'collations' => [ |
| 213 | + ['name' => 'utf8_bin', 'description' => 'Unicode, binary'], |
| 214 | + ['name' => 'utf8_general_ci', 'description' => 'Unicode, case-insensitive'], |
| 215 | + ], |
| 216 | + ], |
| 217 | + [ |
| 218 | + 'name' => 'utf8mb4', |
| 219 | + 'description' => 'utf8mb4_0900_ai_ci', |
| 220 | + 'collations' => [ |
| 221 | + ['name' => 'utf8mb4_general_ci', 'description' => 'Unicode (UCA 4.0.0), case-insensitive'], |
| 222 | + ], |
| 223 | + ], |
| 224 | + ], |
| 225 | + 'tbl_storage_engine' => null, |
| 226 | + 'storage_engines' => ['dummy' => ['name' => 'dummy', 'comment' => 'dummy comment', 'is_default' => false]], |
| 227 | + 'connection' => null, |
| 228 | + 'change_column' => null, |
| 229 | + 'is_virtual_columns_supported' => true, |
| 230 | + 'is_integers_length_restricted' => false, |
| 231 | + 'browse_mime' => true, |
| 232 | + 'supports_stored_keyword' => false, |
| 233 | + 'server_version' => $this->dbi->getVersion(), |
| 234 | + 'max_rows' => 25, |
| 235 | + 'char_editing' => 'input', |
| 236 | + 'attribute_types' => ['', 'BINARY', 'UNSIGNED', 'UNSIGNED ZEROFILL', 'on update CURRENT_TIMESTAMP'], |
| 237 | + 'privs_available' => false, |
| 238 | + 'max_length' => 1024, |
| 239 | + 'have_partitioning' => true, |
| 240 | + 'dbi' => $this->dbi, |
| 241 | + 'disable_is' => false, |
| 242 | + ]); |
| 243 | + |
| 244 | + (new CreateController( |
| 245 | + $response, |
| 246 | + $template, |
| 247 | + new Transformations(), |
| 248 | + new Config(), |
| 249 | + $relation, |
| 250 | + $this->dbi |
| 251 | + ))(); |
| 252 | + |
| 253 | + $this->assertSame($expected, $response->getHTMLResult()); |
| 254 | + } |
| 255 | +} |
0 commit comments