3 declare(strict_types
=1);
5 namespace PhpMyAdmin\Tests
;
8 use PhpMyAdmin\DatabaseInterface
;
10 use PhpMyAdmin\InsertEdit
;
11 use PhpMyAdmin\Message
;
12 use PhpMyAdmin\Response
;
13 use PhpMyAdmin\Scripts
;
16 use ReflectionProperty
;
25 class InsertEditTest
extends AbstractTestCase
27 /** @var InsertEdit */
31 * Setup for test cases
33 protected function setUp(): void
36 parent
::defineVersionConstants();
37 parent
::setLanguage();
38 parent
::setGlobalConfig();
39 parent
::loadDefaultConfig();
41 $GLOBALS['server'] = 1;
42 $GLOBALS['PMA_PHP_SELF'] = 'index.php';
43 $GLOBALS['cfg']['ServerDefault'] = 1;
44 $GLOBALS['text_dir'] = 'ltr';
45 $GLOBALS['db'] = 'db';
46 $GLOBALS['table'] = 'table';
47 $GLOBALS['cfg']['LimitChars'] = 50;
48 $GLOBALS['cfg']['LongtextDoubleTextarea'] = false;
49 $GLOBALS['cfg']['ShowFieldTypesInDataEditView'] = true;
50 $GLOBALS['cfg']['ShowFunctionFields'] = true;
51 $GLOBALS['cfg']['ProtectBinary'] = 'blob';
52 $GLOBALS['cfg']['MaxSizeForInputField'] = 10;
53 $GLOBALS['cfg']['MinSizeForInputField'] = 2;
54 $GLOBALS['cfg']['TextareaRows'] = 5;
55 $GLOBALS['cfg']['TextareaCols'] = 4;
56 $GLOBALS['cfg']['CharTextareaRows'] = 5;
57 $GLOBALS['cfg']['CharTextareaCols'] = 6;
58 $GLOBALS['cfg']['AllowThirdPartyFraming'] = false;
59 $GLOBALS['cfg']['SendErrorReports'] = 'ask';
60 $GLOBALS['cfg']['DefaultTabDatabase'] = 'structure';
61 $GLOBALS['cfg']['ShowDatabasesNavigationAsTree'] = true;
62 $GLOBALS['cfg']['DefaultTabTable'] = 'browse';
63 $GLOBALS['cfg']['NavigationTreeDefaultTabTable'] = 'structure';
64 $GLOBALS['cfg']['NavigationTreeDefaultTabTable2'] = '';
65 $GLOBALS['cfg']['Confirm'] = true;
66 $GLOBALS['cfg']['LoginCookieValidity'] = 1440;
67 $GLOBALS['cfg']['enable_drag_drop_import'] = true;
68 $this->insertEdit
= new InsertEdit($GLOBALS['dbi']);
72 * Teardown all objects
74 protected function tearDown(): void
77 $response = new ReflectionProperty(Response
::class, 'instance');
78 $response->setAccessible(true);
79 $response->setValue(null);
80 $response->setAccessible(false);
84 * Test for getFormParametersForInsertForm
86 public function testGetFormParametersForInsertForm(): void
92 $_POST['clause_is_unique'] = false;
93 $_POST['sql_query'] = 'SELECT a';
94 $GLOBALS['goto'] = 'index.php';
96 $result = $this->insertEdit
->getFormParametersForInsertForm(
107 'table' => 'tablename',
108 'goto' => 'index.php',
109 'err_url' => 'localhost',
110 'sql_query' => 'SELECT a',
111 'where_clause[foo]' => 'bar',
112 'where_clause[1]' => 'test',
113 'clause_is_unique' => false,
120 * Test for getWhereClauseArray
122 public function testGetWhereClauseArray(): void
129 'getWhereClauseArray',
143 'getWhereClauseArray',
153 'getWhereClauseArray',
160 * Test for analyzeWhereClauses
162 public function testAnalyzeWhereClause(): void
169 $dbi = $this->getMockBuilder(DatabaseInterface
::class)
170 ->disableOriginalConstructor()
173 $dbi->expects($this->exactly(2))
175 ->willReturnOnConsecutiveCalls(
180 $dbi->expects($this->exactly(2))
181 ->method('fetchAssoc')
182 ->willReturnOnConsecutiveCalls(
187 $dbi->expects($this->exactly(2))
188 ->method('getFieldsMeta')
189 ->willReturnOnConsecutiveCalls(
194 $GLOBALS['dbi'] = $dbi;
195 $this->insertEdit
= new InsertEdit($GLOBALS['dbi']);
196 $result = $this->callFunction(
199 'analyzeWhereClauses',
228 * Test for showEmptyResultMessageOrSetUniqueCondition
230 public function testShowEmptyResultMessageOrSetUniqueCondition(): void
232 $temp = new stdClass();
233 $temp->orgname
= 'orgname';
234 $temp->table
= 'table';
235 $temp->type
= 'real';
236 $temp->primary_key
= 1;
239 $dbi = $this->getMockBuilder(DatabaseInterface
::class)
240 ->disableOriginalConstructor()
243 $dbi->expects($this->at(0))
244 ->method('getFieldsMeta')
246 ->will($this->returnValue($meta_arr));
248 $GLOBALS['dbi'] = $dbi;
249 $this->insertEdit
= new InsertEdit($GLOBALS['dbi']);
251 $result = $this->callFunction(
254 'showEmptyResultMessageOrSetUniqueCondition',
264 $this->assertTrue($result);
267 $GLOBALS['cfg']['ShowSQL'] = false;
269 $responseMock = $this->getMockBuilder(Response
::class)
270 ->disableOriginalConstructor()
271 ->setMethods(['addHtml'])
274 $restoreInstance = Response
::getInstance();
275 $response = new ReflectionProperty(Response
::class, 'instance');
276 $response->setAccessible(true);
277 $response->setValue($responseMock);
279 $result = $this->callFunction(
282 'showEmptyResultMessageOrSetUniqueCondition',
292 $response->setValue($restoreInstance);
294 $this->assertFalse($result);
298 * Test for loadFirstRow
300 public function testLoadFirstRow(): void
302 $GLOBALS['cfg']['InsertRows'] = 2;
304 $dbi = $this->getMockBuilder(DatabaseInterface
::class)
305 ->disableOriginalConstructor()
308 $dbi->expects($this->at(0))
311 'SELECT * FROM `db`.`table` LIMIT 1;',
312 DatabaseInterface
::CONNECT_USER
,
313 DatabaseInterface
::QUERY_STORE
315 ->will($this->returnValue('result1'));
317 $GLOBALS['dbi'] = $dbi;
318 $this->insertEdit
= new InsertEdit($GLOBALS['dbi']);
320 $result = $this->callFunction(
340 * Test for urlParamsInEditMode
342 public function testUrlParamsInEditMode(): void
344 $where_clause_array = [
348 $_POST['sql_query'] = 'SELECT 1';
350 $result = $this->insertEdit
->urlParamsInEditMode([1], $where_clause_array);
355 'where_clause' => 'bar=2',
356 'sql_query' => 'SELECT 1',
363 * Test for showTypeOrFunction
365 public function testShowTypeOrFunction(): void
367 $GLOBALS['cfg']['ShowFieldTypesInDataEditView'] = true;
368 $GLOBALS['cfg']['ServerDefault'] = 1;
369 $url_params = ['ShowFunctionFields' => 2];
371 $result = $this->insertEdit
->showTypeOrFunction('function', $url_params, false);
373 $this->assertStringContainsString(
374 'index.php?route=/table/change',
377 $this->assertStringContainsString(
378 'ShowFunctionFields=1&ShowFieldTypesInDataEditView=1&goto=index.php%3Froute%3D%2Fsql',
381 $this->assertStringContainsString(
387 $result = $this->insertEdit
->showTypeOrFunction('function', $url_params, true);
389 $this->assertStringContainsString(
390 'index.php?route=/table/change',
393 $this->assertStringContainsString(
394 'ShowFunctionFields=0&ShowFieldTypesInDataEditView=1&goto=index.php%3Froute%3D%2Fsql',
397 $this->assertStringContainsString(
403 $result = $this->insertEdit
->showTypeOrFunction('type', $url_params, false);
405 $this->assertStringContainsString(
406 'index.php?route=/table/change',
409 $this->assertStringContainsString(
410 'ShowFunctionFields=1&ShowFieldTypesInDataEditView=1&goto=index.php%3Froute%3D%2Fsql',
413 $this->assertStringContainsString(
419 $result = $this->insertEdit
->showTypeOrFunction('type', $url_params, true);
421 $this->assertStringContainsString(
422 'index.php?route=/table/change',
425 $this->assertStringContainsString(
426 'ShowFunctionFields=1&ShowFieldTypesInDataEditView=0&goto=index.php%3Froute%3D%2Fsql',
429 $this->assertStringContainsString(
436 * Test for analyzeTableColumnsArray
438 public function testAnalyzeTableColumnsArray(): void
442 'Field_md5' => 'pswd',
443 'Type' => 'float(10, 1)',
446 $result = $this->callFunction(
449 'analyzeTableColumnsArray',
458 $result['Field_html'],
463 $result['Field_md5'],
464 '4342210df36bf2ff2c4e2a997a6d4089'
468 $result['True_Type'],
478 $result['Field_title'],
483 $result['is_binary'],
514 * Test for getColumnTitle
516 public function testGetColumnTitle(): void
519 $column['Field'] = 'f1<';
520 $column['Field_html'] = 'f1<';
536 $comments['f1<'] = 'comment>';
538 $result = $this->callFunction(
548 $this->assertStringContainsString(
549 'title="comment>"',
553 $this->assertStringContainsString(
562 public function testIsColumn(): void
570 $column['Type'] = 'binaryfoo';
571 $this->assertTrue($this->insertEdit
->isColumn($column, $types));
573 $column['Type'] = 'Binaryfoo';
574 $this->assertTrue($this->insertEdit
->isColumn($column, $types));
576 $column['Type'] = 'varbinaryfoo';
577 $this->assertTrue($this->insertEdit
->isColumn($column, $types));
579 $column['Type'] = 'barbinaryfoo';
580 $this->assertFalse($this->insertEdit
->isColumn($column, $types));
587 $column['Type'] = 'char(10)';
588 $this->assertTrue($this->insertEdit
->isColumn($column, $types));
590 $column['Type'] = 'VarChar(20)';
591 $this->assertTrue($this->insertEdit
->isColumn($column, $types));
593 $column['Type'] = 'foochar';
594 $this->assertFalse($this->insertEdit
->isColumn($column, $types));
603 $column['Type'] = 'blob';
604 $this->assertTrue($this->insertEdit
->isColumn($column, $types));
606 $column['Type'] = 'bloB';
607 $this->assertTrue($this->insertEdit
->isColumn($column, $types));
609 $column['Type'] = 'mediumBloB';
610 $this->assertTrue($this->insertEdit
->isColumn($column, $types));
612 $column['Type'] = 'tinyblobabc';
613 $this->assertTrue($this->insertEdit
->isColumn($column, $types));
615 $column['Type'] = 'longblob';
616 $this->assertTrue($this->insertEdit
->isColumn($column, $types));
618 $column['Type'] = 'foolongblobbar';
619 $this->assertFalse($this->insertEdit
->isColumn($column, $types));
623 * Test for getEnumSetAndTimestampColumns
625 public function testGetEnumAndTimestampColumns(): void
628 $column['True_Type'] = 'set';
638 'getEnumSetAndTimestampColumns',
646 $column['True_Type'] = 'enum';
656 'getEnumSetAndTimestampColumns',
664 $column['True_Type'] = 'timestamp';
665 $column['Type'] = 'date';
675 'getEnumSetAndTimestampColumns',
683 $column['True_Type'] = 'timestamp';
684 $column['Type'] = 'date';
694 'getEnumSetAndTimestampColumns',
702 $column['True_Type'] = 'SET';
703 $column['Type'] = 'num';
713 'getEnumSetAndTimestampColumns',
721 $column['True_Type'] = '';
722 $column['Type'] = 'num';
732 'getEnumSetAndTimestampColumns',
742 * Test for getFunctionColumn
744 public function testGetFunctionColumn(): void
746 $GLOBALS['cfg']['ProtectBinary'] = 'blob';
748 $column['is_blob'] = true;
749 $this->assertStringContainsString(
750 '<td class="text-center">Binary</td>',
771 $GLOBALS['cfg']['ProtectBinary'] = 'all';
772 $column['is_binary'] = true;
773 $this->assertStringContainsString(
774 '<td class="text-center">Binary</td>',
795 $GLOBALS['cfg']['ProtectBinary'] = 'noblob';
796 $column['is_blob'] = false;
797 $this->assertStringContainsString(
798 '<td class="text-center">Binary</td>',
819 $GLOBALS['cfg']['ProtectBinary'] = false;
820 $column['True_Type'] = 'enum';
821 $this->assertStringContainsString(
822 '<td class="text-center">--</td>',
843 $column['True_Type'] = 'set';
844 $this->assertStringContainsString(
845 '<td class="text-center">--</td>',
866 $column['True_Type'] = '';
867 $column['pma_type'] = 'int';
868 $this->assertStringContainsString(
869 '<td class="text-center">--</td>',
890 $column['Field'] = 'num';
891 $this->assertStringContainsString(
892 '<select name="funcsa" b tabindex="5" id="field_3_1"',
915 * Test for getNullColumn
917 public function testGetNullColumn(): void
919 $column = ['Field' => ''];
920 $column['Null'] = 'YES';
921 $column['first_timestamp'] = false;
922 $column['True_Type'] = 'enum';
924 $column['Field_md5'] = 'foobar';
926 'foreign_keys_data' => [],
929 $result = $this->callFunction(
947 $this->assertStringContainsString(
948 '<input type="hidden" name="fields_null_preva" value="on">',
952 $this->assertStringContainsString(
953 '<input type="checkbox" class="checkbox_null" tabindex="2" '
954 . 'name="fields_nulla" checked="checked" id="field_1_2"',
958 $this->assertStringContainsString(
959 '<input type="hidden" class="nullify_code" name="nullify_codea" '
964 $this->assertStringContainsString(
965 '<input type="hidden" class="hashed_field" name="hashed_fielda" '
970 $this->assertStringContainsString(
971 '<input type="hidden" class="multi_edit" name="multi_edita" '
972 . 'value="<script>"',
977 $column['Null'] = 'NO';
978 $result = $this->callFunction(
1002 $column['Null'] = 'YES';
1003 $result = $this->callFunction(
1021 $this->assertEquals(
1028 * Test for getNullifyCodeForNullColumn
1030 public function testGetNullifyCodeForNullColumn(): void
1032 $column = $foreignData = [];
1034 'foreign_keys_data' => [],
1036 $column['Field'] = 'f';
1037 $column['True_Type'] = 'enum';
1038 $column['Type'] = 'ababababababababababa';
1039 $this->assertEquals(
1041 $this->callFunction(
1044 'getNullifyCodeForNullColumn',
1053 $column['True_Type'] = 'enum';
1054 $column['Type'] = 'abababababababababab';
1055 $this->assertEquals(
1057 $this->callFunction(
1060 'getNullifyCodeForNullColumn',
1069 $column['True_Type'] = 'set';
1070 $this->assertEquals(
1072 $this->callFunction(
1075 'getNullifyCodeForNullColumn',
1084 $column['True_Type'] = '';
1085 $foreigners['f'] = true;
1086 $foreignData['foreign_link'] = '';
1087 $this->assertEquals(
1089 $this->callFunction(
1092 'getNullifyCodeForNullColumn',
1103 * Test for getForeignLink
1105 public function testGetForeignLink(): void
1108 $column['Field'] = 'f';
1109 $GLOBALS['cfg']['ServerDefault'] = 2;
1110 $result = $this->callFunction(
1132 $this->assertStringContainsString(
1133 '<input type="hidden" name="fields_typeb" value="foreign"',
1137 $this->assertStringContainsString(
1138 '" data-post="db=db&table=tbl&field=f&rownumber=8'
1139 . '&data=abc&server=1&lang=en">',
1142 $this->assertStringContainsString(
1143 '<a class="ajax browse_foreign" href="index.php?route=/browse-foreigners',
1147 $this->assertStringContainsString(
1148 '<input type="text" name="fieldsb" class="textfield" d tabindex="2" '
1149 . 'id="field_1_3" value="abc"',
1155 * Test for dispRowForeignData
1157 public function testDispRowForeignData(): void
1160 $column['is_binary'] = false;
1162 $foreignData['disp_row'] = [];
1163 $foreignData['foreign_field'] = null;
1164 $foreignData['foreign_display'] = null;
1165 $GLOBALS['cfg']['ForeignKeyMaxLimit'] = 1;
1166 $GLOBALS['cfg']['NaturalOrder'] = false;
1167 $result = $this->callFunction(
1170 'dispRowForeignData',
1185 $this->assertStringContainsString(
1190 $this->assertStringContainsString(
1191 '<select name="fieldsb" d class="textfield" tabindex="2" '
1192 . 'id="field_1_3">',
1196 $this->assertStringContainsString(
1197 '<input type="hidden" name="fields_typeb" value="foreign"',
1203 * Test for dispRowForeignData
1205 public function testDispRowForeignDataWithHex(): void
1208 $column['is_binary'] = true;
1210 $foreignData['disp_row'] = [];
1211 $foreignData['foreign_field'] = null;
1212 $foreignData['foreign_display'] = null;
1213 $GLOBALS['cfg']['ForeignKeyMaxLimit'] = 1;
1214 $GLOBALS['cfg']['NaturalOrder'] = false;
1215 $result = $this->callFunction(
1218 'dispRowForeignData',
1233 $this->assertStringContainsString(
1238 $this->assertStringContainsString(
1239 '<select name="fieldsb" d class="textfield" tabindex="2" '
1240 . 'id="field_1_3">',
1244 $this->assertStringContainsString(
1245 '<input type="hidden" name="fields_typeb" value="hex"',
1251 * Test for getTextarea
1253 public function testGetTextarea(): void
1255 $GLOBALS['cfg']['TextareaRows'] = 20;
1256 $GLOBALS['cfg']['TextareaCols'] = 10;
1257 $GLOBALS['cfg']['CharTextareaRows'] = 7;
1258 $GLOBALS['cfg']['CharTextareaCols'] = 1;
1259 $GLOBALS['cfg']['LimitChars'] = 20;
1262 $column['is_char'] = true;
1263 $column['Type'] = 'char(10)';
1264 $column['True_Type'] = 'char';
1265 $result = $this->callFunction(
1284 $this->assertStringContainsString(
1285 '<textarea name="fieldsb" class="char charField" '
1286 . 'data-maxlength="10" rows="7" cols="1" dir="abc/" '
1287 . 'id="field_1_3" tabindex="2" data-type="CHAR">',
1293 * Test for getPmaTypeEnum
1295 public function testGetPmaTypeEnum(): void
1297 $extracted_columnspec = $column = [];
1298 $extracted_columnspec['enum_set_values'] = [];
1299 $column['Type'] = 'abababababababababab';
1300 $column['values'] = [
1306 $result = $this->callFunction(
1314 $extracted_columnspec,
1324 $this->assertStringContainsString(
1325 '<input type="hidden" name="fields_typeb" value="enum">',
1329 $this->assertStringContainsString(
1330 '<input type="radio" name="fieldsb"',
1334 $column['Type'] = 'ababababababababababa';
1335 $result = $this->callFunction(
1343 $extracted_columnspec,
1353 $this->assertStringContainsString(
1354 '<input type="hidden" name="fields_typeb" value="enum"',
1358 $this->assertStringContainsString(
1359 '<select name="fieldsb" d class="textfield" tabindex="2" '
1360 . 'id="field_1_3">',
1366 * Test for getColumnEnumValues
1368 public function testGetColumnEnumValues(): void
1370 $extracted_columnspec = $column = [];
1371 $extracted_columnspec['enum_set_values'] = [
1376 $column['values'] = 'abc';
1378 $result = $this->callFunction(
1381 'getColumnEnumValues',
1384 $extracted_columnspec,
1387 $this->assertEquals(
1391 'html' => '<abc>',
1395 'html' => '"foo"',
1403 * Test for getDropDownDependingOnLength
1405 public function testGetDropDownDependingOnLength(): void
1407 $column_enum_values = [
1418 $result = $this->callFunction(
1421 'getDropDownDependingOnLength',
1430 $column_enum_values,
1435 $this->assertStringContainsString(
1436 '<select name="fieldsa" b class="textfield" tabindex="2" '
1437 . 'id="field_1_3">',
1441 $this->assertStringContainsString(
1442 '<option value="foo" selected="selected">',
1446 $this->assertStringContainsString(
1447 '<option value="bar">',
1452 $column_enum_values = [
1460 $column['Default'] = 'data';
1461 $column['Null'] = 'YES';
1462 $result = $this->callFunction(
1465 'getDropDownDependingOnLength',
1474 $column_enum_values,
1479 $this->assertStringContainsString(
1480 '<option value="foo" selected="selected">',
1486 * Test for getRadioButtonDependingOnLength
1488 public function testGetRadioButtonDependingOnLength(): void
1490 $column_enum_values = [
1501 $result = $this->callFunction(
1504 'getRadioButtonDependingOnLength',
1513 $column_enum_values,
1518 $this->assertStringContainsString(
1519 '<input type="radio" name="fieldsa" class="textfield" value="foo" '
1520 . 'id="field_1_3_0" b checked="checked" tabindex="2">',
1524 $this->assertStringContainsString(
1525 '<label for="field_1_3_0">foo</label>',
1529 $this->assertStringContainsString(
1530 '<input type="radio" name="fieldsa" class="textfield" value="bar" '
1531 . 'id="field_1_3_1" b tabindex="2">',
1535 $this->assertStringContainsString(
1536 '<label for="field_1_3_1">bar</label>',
1541 $column_enum_values = [
1549 $column['Default'] = 'data';
1550 $column['Null'] = 'YES';
1551 $result = $this->callFunction(
1554 'getRadioButtonDependingOnLength',
1563 $column_enum_values,
1568 $this->assertStringContainsString(
1569 '<input type="radio" name="fieldsa" class="textfield" value="foo" '
1570 . 'id="field_1_3_0" b checked="checked" tabindex="2">',
1576 * Test for getPmaTypeSet
1578 public function testGetPmaTypeSet(): void
1581 $column['values'] = [
1588 $column['select_size'] = 1;
1590 $result = $this->callFunction(
1608 $this->assertStringContainsString("a\n", $result);
1610 $this->assertStringContainsString(
1611 '<input type="hidden" name="fields_typeb" value="set">',
1615 $this->assertStringContainsString(
1616 '<option value="<" selected="selected"><</option>',
1620 $this->assertStringContainsString(
1621 '<select name="fieldsb[]" class="textfield" size="1" '
1622 . 'multiple="multiple" c tabindex="2" id="field_1_3">',
1628 * Test for getColumnSetValueAndSelectSize
1630 public function testGetColumnSetValueAndSelectSize(): void
1632 $extracted_columnspec = $column = [];
1633 $extracted_columnspec['enum_set_values'] = [
1637 $result = $this->callFunction(
1640 'getColumnSetValueAndSelectSize',
1643 $extracted_columnspec,
1647 $this->assertEquals(
1664 $column['values'] = [
1668 $column['select_size'] = 3;
1669 $result = $this->callFunction(
1672 'getColumnSetValueAndSelectSize',
1675 $extracted_columnspec,
1679 $this->assertEquals(
1692 * Test for getBinaryAndBlobColumn
1694 public function testGetBinaryAndBlobColumn(): void
1696 $GLOBALS['cfg']['ProtectBinary'] = 'blob';
1697 $GLOBALS['cfg']['ShowFunctionFields'] = true;
1699 $column['is_blob'] = true;
1700 $column['Field_md5'] = '123';
1701 $column['pma_type'] = 'blob';
1702 $column['True_Type'] = 'blob';
1703 $GLOBALS['max_upload_size'] = 65536;
1705 $result = $this->callFunction(
1708 'getBinaryAndBlobColumn',
1728 $this->assertEquals(
1729 'Binary - do not edit (5 B)<input type="hidden" '
1730 . 'name="fieldsb" value=""><input type="hidden" '
1731 . 'name="fields_typeb" value="protected">'
1732 . '<br><input type="file" name="fields_uploadfoo[123]" class="text'
1733 . 'field noDragDrop" id="field_1_3" size="10" c> (Max: 64KiB)' . "\n",
1738 $GLOBALS['cfg']['ProtectBinary'] = 'all';
1739 $column['is_binary'] = true;
1741 $result = $this->callFunction(
1744 'getBinaryAndBlobColumn',
1764 $this->assertEquals(
1765 'Binary - do not edit (4 B)<input type="hidden" '
1766 . 'name="fieldsb" value=""><input type="hidden" '
1767 . 'name="fields_typeb" value="protected">',
1772 $GLOBALS['cfg']['ProtectBinary'] = 'noblob';
1773 $column['is_blob'] = false;
1775 $result = $this->callFunction(
1778 'getBinaryAndBlobColumn',
1798 $this->assertEquals(
1799 'Binary - do not edit (4 B)<input type="hidden" '
1800 . 'name="fieldsb" value=""><input type="hidden" '
1801 . 'name="fields_typeb" value="protected">',
1806 $GLOBALS['cfg']['ProtectBinary'] = false;
1807 $column['is_blob'] = true;
1808 $column['is_char'] = true;
1809 $column['Type'] = 'char(255)';
1810 $GLOBALS['cfg']['TextareaRows'] = 20;
1811 $GLOBALS['cfg']['TextareaCols'] = 10;
1812 $GLOBALS['cfg']['CharTextareaRows'] = 7;
1813 $GLOBALS['cfg']['CharTextareaCols'] = 1;
1814 $GLOBALS['cfg']['LimitChars'] = 100;
1816 $result = $this->callFunction(
1819 'getBinaryAndBlobColumn',
1839 $this->assertEquals(
1841 . '<textarea name="fieldsb" class="char charField" data-maxlength="255" rows="7" '
1842 . 'cols="1" dir="/" id="field_1_3" c tabindex="3" data-type="HEX">'
1843 . '</textarea><input type="hidden" name="fields_typeb" value="hex">'
1844 . '<br><input type="file" name="fields_uploadfoo[123]" class="text'
1845 . 'field noDragDrop" id="field_1_3" size="10" c> (Max: 64KiB)' . "\n",
1850 $GLOBALS['cfg']['ProtectBinary'] = false;
1851 $GLOBALS['cfg']['LongtextDoubleTextarea'] = true;
1852 $GLOBALS['cfg']['LimitChars'] = 100;
1853 $column['is_blob'] = false;
1854 $column['len'] = 255;
1855 $column['is_char'] = false;
1856 $GLOBALS['cfg']['TextareaRows'] = 20;
1857 $GLOBALS['cfg']['TextareaCols'] = 10;
1859 $result = $this->callFunction(
1862 'getBinaryAndBlobColumn',
1882 $this->assertEquals(
1884 . '<textarea name="fieldsb" class="" rows="20" cols="10" dir="/" '
1885 . 'id="field_1_3" c tabindex="3" data-type="HEX">'
1886 . '</textarea><input type="hidden" '
1887 . 'name="fields_typeb" value="hex">',
1892 $column['is_blob'] = false;
1893 $column['len'] = 10;
1894 $GLOBALS['cfg']['LimitChars'] = 40;
1897 * This condition should be tested, however, it gives an undefined function
1898 * PhpMyAdmin\FileListing::getFileSelectOptions error:
1899 * $GLOBALS['cfg']['UploadDir'] = true;
1902 $result = $this->callFunction(
1905 'getBinaryAndBlobColumn',
1925 $this->assertEquals(
1927 . '<input type="text" name="fieldsb" value="" size="10" data-type='
1928 . '"HEX" class="textfield" c tabindex="3" id="field_1_3">'
1929 . '<input type="hidden" name="fields_typeb" value="hex">',
1935 * Test for getHtmlInput
1937 public function testGetHTMLinput(): void
1939 $GLOBALS['cfg']['ShowFunctionFields'] = true;
1941 $column['pma_type'] = 'date';
1942 $column['True_Type'] = 'date';
1943 $result = $this->callFunction(
1961 $this->assertEquals(
1962 '<input type="text" name="fieldsa" value="b" size="30" data-type="DATE"'
1963 . ' class="textfield datefield" c tabindex="25" id="field_0_3">',
1968 $column['pma_type'] = 'datetime';
1969 $column['True_Type'] = 'datetime';
1970 $result = $this->callFunction(
1987 $this->assertEquals(
1988 '<input type="text" name="fieldsa" value="b" size="30" data-type="DATE"'
1989 . ' class="textfield datetimefield" c tabindex="25" id="field_0_3">',
1994 $column['pma_type'] = 'timestamp';
1995 $column['True_Type'] = 'timestamp';
1996 $result = $this->callFunction(
2013 $this->assertEquals(
2014 '<input type="text" name="fieldsa" value="b" size="30" data-type="DATE"'
2015 . ' class="textfield datetimefield" c tabindex="25" id="field_0_3">',
2021 * Test for getMaxUploadSize
2023 public function testGetMaxUploadSize(): void
2025 $GLOBALS['max_upload_size'] = 257;
2027 $column['pma_type'] = 'tinyblob';
2028 $result = $this->callFunction(
2038 $this->assertEquals(
2047 $GLOBALS['max_upload_size'] = 250;
2048 $column['pma_type'] = 'tinyblob';
2049 $result = $this->callFunction(
2059 $this->assertEquals(
2069 * Test for getValueColumnForOtherDatatypes
2071 public function testGetValueColumnForOtherDatatypes(): void
2074 $column['len'] = 20;
2075 $column['is_char'] = true;
2076 $column['Type'] = 'char(25)';
2077 $column['True_Type'] = 'char';
2078 $GLOBALS['cfg']['CharEditing'] = '';
2079 $GLOBALS['cfg']['MaxSizeForInputField'] = 30;
2080 $GLOBALS['cfg']['MinSizeForInputField'] = 10;
2081 $GLOBALS['cfg']['TextareaRows'] = 20;
2082 $GLOBALS['cfg']['TextareaCols'] = 10;
2083 $GLOBALS['cfg']['CharTextareaRows'] = 7;
2084 $GLOBALS['cfg']['CharTextareaCols'] = 1;
2085 $GLOBALS['cfg']['LimitChars'] = 50;
2086 $GLOBALS['cfg']['ShowFunctionFields'] = true;
2088 $extracted_columnspec = [];
2089 $extracted_columnspec['spec_in_brackets'] = 25;
2090 $result = $this->callFunction(
2093 'getValueColumnForOtherDatatypes',
2107 $extracted_columnspec,
2112 $this->assertEquals(
2114 . '<textarea name="fieldsb" class="char charField" '
2115 . 'data-maxlength="25" rows="7" cols="1" dir="/" '
2116 . 'id="field_1_3" c tabindex="34" data-type="CHAR">'
2117 . '<</textarea>',
2122 $column['is_char'] = false;
2123 $column['Extra'] = 'auto_increment';
2124 $column['pma_type'] = 'timestamp';
2125 $column['True_Type'] = 'timestamp';
2126 $result = $this->callFunction(
2129 'getValueColumnForOtherDatatypes',
2143 $extracted_columnspec,
2148 $this->assertEquals(
2150 . '<input type="text" name="fieldsb" value="<" size="20" data-type="'
2151 . 'DATE" class="textfield datetimefield" c tabindex="34" id="field_1_3"'
2152 . '><input type="hidden" name="auto_incrementb" value="1">'
2153 . '<input type="hidden" name="fields_typeb" value="timestamp">',
2157 // case 3: (else -> datetime)
2158 $column['pma_type'] = 'datetime';
2159 $result = $this->callFunction(
2162 'getValueColumnForOtherDatatypes',
2176 $extracted_columnspec,
2181 $this->assertStringContainsString(
2182 '<input type="hidden" name="fields_typeb" value="datetime">',
2188 * Test for getColumnSize
2190 public function testGetColumnSize(): void
2192 $column = $extracted_columnspec = [];
2193 $column['is_char'] = true;
2194 $extracted_columnspec['spec_in_brackets'] = 45;
2195 $GLOBALS['cfg']['MinSizeForInputField'] = 30;
2196 $GLOBALS['cfg']['MaxSizeForInputField'] = 40;
2198 $this->assertEquals(
2200 $this->callFunction(
2206 $extracted_columnspec,
2211 $this->assertEquals(
2213 $GLOBALS['cfg']['CharEditing']
2217 $column['is_char'] = false;
2218 $column['len'] = 20;
2219 $this->assertEquals(
2221 $this->callFunction(
2227 $extracted_columnspec,
2234 * Test for getHtmlForGisDataTypes
2236 public function testGetHTMLforGisDataTypes(): void
2238 $GLOBALS['cfg']['ActionLinksMode'] = 'icons';
2239 $GLOBALS['cfg']['LinkLengthLimit'] = 2;
2240 $this->assertStringContainsString(
2241 '<a href="#" target="_blank"><span class="nowrap"><img src="themes/dot.'
2242 . 'gif" title="Edit/Insert" alt="Edit/Insert" class="icon ic_b_edit">'
2244 $this->callFunction(
2247 'getHtmlForGisDataTypes',
2254 * Test for getContinueInsertionForm
2256 public function testGetContinueInsertionForm(): void
2258 $where_clause_array = ['a<b'];
2259 $GLOBALS['cfg']['InsertRows'] = 1;
2260 $GLOBALS['cfg']['ServerDefault'] = 1;
2261 $GLOBALS['goto'] = 'index.php';
2262 $_POST['where_clause'] = true;
2263 $_POST['sql_query'] = 'SELECT 1';
2265 $result = $this->insertEdit
->getContinueInsertionForm(
2268 $where_clause_array,
2272 $this->assertStringContainsString(
2273 '<form id="continueForm" method="post" action="' . Url
::getFromRoute('/table/replace')
2274 . '" name="continueForm">',
2278 $this->assertStringContainsString(
2279 '<input type="hidden" name="db" value="db">',
2283 $this->assertStringContainsString(
2284 '<input type="hidden" name="table" value="tbl">',
2288 $this->assertStringContainsString(
2289 '<input type="hidden" name="goto" value="index.php">',
2293 $this->assertStringContainsString(
2294 '<input type="hidden" name="err_url" value="localhost">',
2298 $this->assertStringContainsString(
2299 '<input type="hidden" name="sql_query" value="SELECT 1">',
2303 $this->assertStringContainsString(
2304 '<input type="hidden" name="where_clause[0]" value="a<b">',
2310 * Test for getActionsPanel
2312 public function testGetActionsPanel(): void
2314 $GLOBALS['cfg']['ShowHint'] = false;
2315 $result = $this->insertEdit
->getActionsPanel(null, 'back', 2, 1, false);
2317 $this->assertStringContainsString(
2318 '<select name="submit_type" class="control_at_footer" tabindex="4">',
2322 $this->assertStringContainsString(
2323 '<select name="after_insert"',
2327 $this->assertStringContainsString(
2328 '<input type="submit" class="btn btn-primary control_at_footer" value="Go" '
2329 . 'tabindex="11" id="buttonYes"',
2335 * Test for getSubmitTypeDropDown
2337 public function testGetSubmitTypeDropDown(): void
2339 $result = $this->callFunction(
2342 'getSubmitTypeDropDown',
2350 $this->assertStringContainsString(
2351 '<select name="submit_type" class="control_at_footer" tabindex="5">',
2355 $this->assertStringContainsString(
2356 '<option value="save">',
2362 * Test for getAfterInsertDropDown
2364 public function testGetAfterInsertDropDown(): void
2366 $result = $this->callFunction(
2369 'getAfterInsertDropDown',
2377 $this->assertStringContainsString(
2378 '<option value="new_insert" selected="selected">',
2382 $this->assertStringContainsString(
2383 '<option value="same_insert"',
2387 $this->assertStringContainsString(
2388 '<option value="edit_next" >',
2394 * Test for getSubmitAndResetButtonForActionsPanel
2396 public function testGetSubmitAndResetButtonForActionsPanel(): void
2398 $GLOBALS['cfg']['ShowHint'] = false;
2399 $result = $this->callFunction(
2402 'getSubmitAndResetButtonForActionsPanel',
2409 $this->assertStringContainsString(
2410 '<input type="submit" class="btn btn-primary control_at_footer" value="Go" '
2411 . 'tabindex="9" id="buttonYes">',
2415 $this->assertStringContainsString(
2416 '<input type="button" class="btn btn-secondary preview_sql" value="Preview SQL" '
2421 $this->assertStringContainsString(
2422 '<input type="reset" class="btn btn-secondary control_at_footer" value="Reset" '
2429 * Test for getHeadAndFootOfInsertRowTable
2431 public function testGetHeadAndFootOfInsertRowTable(): void
2433 $GLOBALS['cfg']['ShowFieldTypesInDataEditView'] = true;
2434 $GLOBALS['cfg']['ShowFunctionFields'] = true;
2435 $GLOBALS['cfg']['ServerDefault'] = 1;
2436 $url_params = ['ShowFunctionFields' => 2];
2438 $result = $this->callFunction(
2441 'getHeadAndFootOfInsertRowTable',
2445 $this->assertStringContainsString(
2446 'index.php?route=/table/change',
2450 $this->assertStringContainsString(
2451 'ShowFunctionFields=1&ShowFieldTypesInDataEditView=0',
2455 $this->assertStringContainsString(
2456 'ShowFunctionFields=0&ShowFieldTypesInDataEditView=1',
2462 * Test for getSpecialCharsAndBackupFieldForExistingRow
2464 public function testGetSpecialCharsAndBackupFieldForExistingRow(): void
2466 $column = $current_row = $extracted_columnspec = [];
2467 $column['Field'] = 'f';
2468 $current_row['f'] = null;
2469 $_POST['default_action'] = 'insert';
2470 $column['Key'] = 'PRI';
2471 $column['Extra'] = 'fooauto_increment';
2473 $result = $this->callFunction(
2476 'getSpecialCharsAndBackupFieldForExistingRow',
2488 $this->assertEquals(
2494 '<input type="hidden" name="fields_preva" value="">',
2500 unset($_POST['default_action']);
2502 $current_row['f'] = '123';
2503 $extracted_columnspec['spec_in_brackets'] = 20;
2504 $column['True_Type'] = 'bit';
2506 $result = $this->callFunction(
2509 'getSpecialCharsAndBackupFieldForExistingRow',
2513 $extracted_columnspec,
2521 $this->assertEquals(
2525 '00000000000001111011',
2527 '<input type="hidden" name="fields_preva" value="123">',
2532 $current_row['f'] = 'abcd';
2533 $result = $this->callFunction(
2536 'getSpecialCharsAndBackupFieldForExistingRow',
2540 $extracted_columnspec,
2548 $this->assertEquals(
2554 '<input type="hidden" name="fields_preva" value="abcd">',
2560 $dbi = $this->getMockBuilder(DatabaseInterface
::class)
2561 ->disableOriginalConstructor()
2564 $GLOBALS['dbi'] = $dbi;
2565 $this->insertEdit
= new InsertEdit($GLOBALS['dbi']);
2567 $current_row['f'] = '123';
2568 $extracted_columnspec['spec_in_brackets'] = 20;
2569 $column['True_Type'] = 'int';
2571 $result = $this->callFunction(
2574 'getSpecialCharsAndBackupFieldForExistingRow',
2578 $extracted_columnspec,
2586 $this->assertEquals(
2592 '<input type="hidden" name="fields_preva" value="\'\',">',
2598 $column['is_binary'] = false;
2599 $column['is_blob'] = true;
2600 $GLOBALS['cfg']['ProtectBinary'] = false;
2601 $current_row['f'] = '11001';
2602 $extracted_columnspec['spec_in_brackets'] = 20;
2603 $column['True_Type'] = 'char';
2604 $GLOBALS['cfg']['ShowFunctionFields'] = true;
2606 $result = $this->callFunction(
2609 'getSpecialCharsAndBackupFieldForExistingRow',
2613 $extracted_columnspec,
2621 $this->assertEquals(
2627 '<input type="hidden" name="fields_preva" value="3131303031">',
2633 $current_row['f'] = "11001\x00";
2635 $result = $this->callFunction(
2638 'getSpecialCharsAndBackupFieldForExistingRow',
2642 $extracted_columnspec,
2650 $this->assertEquals(
2656 '<input type="hidden" name="fields_preva" value="313130303100">',
2663 * Test for getSpecialCharsAndBackupFieldForInsertingMode
2665 public function testGetSpecialCharsAndBackupFieldForInsertingMode(): void
2668 $column['True_Type'] = 'bit';
2669 $column['Default'] = 'b\'101\'';
2670 $column['is_binary'] = true;
2671 $GLOBALS['cfg']['ProtectBinary'] = false;
2672 $GLOBALS['cfg']['ShowFunctionFields'] = true;
2674 $result = $this->callFunction(
2677 'getSpecialCharsAndBackupFieldForInsertingMode',
2684 $this->assertEquals(
2696 unset($column['Default']);
2697 $column['True_Type'] = 'char';
2699 $result = $this->callFunction(
2702 'getSpecialCharsAndBackupFieldForInsertingMode',
2709 $this->assertEquals(
2722 * Test for getParamsForUpdateOrInsert
2724 public function testGetParamsForUpdateOrInsert(): void
2726 $_POST['where_clause'] = 'LIMIT 1';
2727 $_POST['submit_type'] = 'showinsert';
2729 $result = $this->insertEdit
->getParamsForUpdateOrInsert();
2731 $this->assertEquals(
2742 unset($_POST['where_clause']);
2743 $_POST['fields']['multi_edit'] = [
2747 $result = $this->insertEdit
->getParamsForUpdateOrInsert();
2749 $this->assertEquals(
2764 * Test for isInsertRow
2766 public function testIsInsertRow(): void
2768 $_POST['insert_rows'] = 5;
2769 $GLOBALS['cfg']['InsertRows'] = 2;
2771 $scriptsMock = $this->getMockBuilder(Scripts
::class)
2772 ->disableOriginalConstructor()
2773 ->setMethods(['addFile'])
2776 $scriptsMock->expects($this->exactly(2))
2777 ->method('addFile');
2779 $headerMock = $this->getMockBuilder(Header
::class)
2780 ->disableOriginalConstructor()
2781 ->setMethods(['getScripts'])
2784 $headerMock->expects($this->once())
2785 ->method('getScripts')
2786 ->will($this->returnValue($scriptsMock));
2788 $responseMock = $this->getMockBuilder(Response
::class)
2789 ->disableOriginalConstructor()
2790 ->setMethods(['getHeader'])
2793 $responseMock->expects($this->once())
2794 ->method('getHeader')
2795 ->will($this->returnValue($headerMock));
2797 $restoreInstance = Response
::getInstance();
2798 $response = new ReflectionProperty(Response
::class, 'instance');
2799 $response->setAccessible(true);
2800 $response->setValue($responseMock);
2802 $this->insertEdit
->isInsertRow();
2804 $response->setValue($restoreInstance);
2806 $this->assertEquals(5, $GLOBALS['cfg']['InsertRows']);
2810 * Test for setSessionForEditNext
2812 public function testSetSessionForEditNext(): void
2814 $temp = new stdClass();
2815 $temp->orgname
= 'orgname';
2816 $temp->table
= 'table';
2817 $temp->type
= 'real';
2818 $temp->primary_key
= 1;
2819 $meta_arr = [$temp];
2824 $dbi = $this->getMockBuilder(DatabaseInterface
::class)
2825 ->disableOriginalConstructor()
2828 $dbi->expects($this->at(0))
2830 ->with('SELECT * FROM `db`.`table` WHERE `a` > 2 LIMIT 1;')
2831 ->will($this->returnValue($res));
2833 $dbi->expects($this->at(1))
2834 ->method('fetchRow')
2836 ->will($this->returnValue($row));
2838 $dbi->expects($this->at(2))
2839 ->method('getFieldsMeta')
2841 ->will($this->returnValue($meta_arr));
2843 $GLOBALS['dbi'] = $dbi;
2844 $GLOBALS['db'] = 'db';
2845 $GLOBALS['table'] = 'table';
2846 $this->insertEdit
= new InsertEdit($GLOBALS['dbi']);
2847 $this->insertEdit
->setSessionForEditNext('`a` = 2');
2849 $this->assertEquals(
2850 'CONCAT(`table`.`orgname`) IS NULL',
2851 $_SESSION['edit_next']
2856 * Test for getGotoInclude
2858 public function testGetGotoInclude(): void
2860 $GLOBALS['goto'] = '123.php';
2861 $GLOBALS['table'] = '';
2863 $this->assertEquals(
2865 $this->insertEdit
->getGotoInclude('index')
2868 $GLOBALS['table'] = 'tbl';
2869 $this->assertEquals(
2871 $this->insertEdit
->getGotoInclude('index')
2874 $GLOBALS['goto'] = 'index.php?route=/database/sql';
2876 $this->assertEquals(
2878 $this->insertEdit
->getGotoInclude('index')
2881 $this->assertEquals(
2886 $_POST['after_insert'] = 'new_insert';
2887 $this->assertEquals(
2889 $this->insertEdit
->getGotoInclude('index')
2894 * Test for getErrorUrl
2896 public function testGetErrorUrl(): void
2898 $GLOBALS['cfg']['ServerDefault'] = 1;
2899 $this->assertEquals(
2900 'index.php?route=/table/change&lang=en',
2901 $this->insertEdit
->getErrorUrl([])
2904 $_POST['err_url'] = 'localhost';
2905 $this->assertEquals(
2907 $this->insertEdit
->getErrorUrl([])
2912 * Test for buildSqlQuery
2914 public function testBuildSqlQuery(): void
2916 $GLOBALS['db'] = 'db';
2917 $GLOBALS['table'] = 'table';
2927 $this->assertEquals(
2928 ['INSERT IGNORE INTO `table` (a, b) VALUES (1), (2)'],
2929 $this->insertEdit
->buildSqlQuery(true, $query_fields, $value_sets)
2932 $this->assertEquals(
2933 ['INSERT INTO `table` (a, b) VALUES (1), (2)'],
2934 $this->insertEdit
->buildSqlQuery(false, $query_fields, $value_sets)
2939 * Test for executeSqlQuery
2941 public function testExecuteSqlQuery(): void
2947 $GLOBALS['sql_query'] = 'SELECT';
2948 $GLOBALS['cfg']['IgnoreMultiSubmitErrors'] = false;
2949 $_POST['submit_type'] = '';
2951 $dbi = $this->getMockBuilder(DatabaseInterface
::class)
2952 ->disableOriginalConstructor()
2955 $dbi->expects($this->at(0))
2958 ->will($this->returnValue(true));
2960 $dbi->expects($this->at(1))
2961 ->method('affectedRows')
2962 ->will($this->returnValue(2));
2964 $dbi->expects($this->at(2))
2965 ->method('insertId')
2966 ->will($this->returnValue(1));
2968 $dbi->expects($this->at(5))
2971 ->will($this->returnValue(false));
2973 $dbi->expects($this->once())
2974 ->method('getError')
2975 ->will($this->returnValue('err'));
2977 $dbi->expects($this->exactly(2))
2978 ->method('getWarnings')
2979 ->will($this->returnValue([]));
2981 $GLOBALS['dbi'] = $dbi;
2982 $this->insertEdit
= new InsertEdit($GLOBALS['dbi']);
2984 $result = $this->insertEdit
->executeSqlQuery([], $query);
2986 $this->assertEquals(
2987 ['sql_query' => 'SELECT'],
2991 $this->assertEquals(
2996 $this->assertInstanceOf(
3001 $msg = $result[2][0];
3002 $reflectionMsg = new ReflectionProperty(Message
::class, 'params');
3003 $reflectionMsg->setAccessible(true);
3005 $this->assertEquals(
3007 $reflectionMsg->getValue($msg)
3010 $this->assertEquals(
3015 $this->assertEquals(
3020 $this->assertEquals(
3027 * Test for executeSqlQuery
3029 public function testExecuteSqlQueryWithTryQuery(): void
3035 $GLOBALS['sql_query'] = 'SELECT';
3036 $GLOBALS['cfg']['IgnoreMultiSubmitErrors'] = true;
3037 $_POST['submit_type'] = '';
3039 $dbi = $this->getMockBuilder(DatabaseInterface
::class)
3040 ->disableOriginalConstructor()
3043 $dbi->expects($this->at(0))
3044 ->method('tryQuery')
3046 ->will($this->returnValue(true));
3048 $dbi->expects($this->at(1))
3049 ->method('affectedRows')
3050 ->will($this->returnValue(2));
3052 $dbi->expects($this->at(2))
3053 ->method('insertId')
3054 ->will($this->returnValue(1));
3056 $dbi->expects($this->at(5))
3057 ->method('tryQuery')
3059 ->will($this->returnValue(false));
3061 $dbi->expects($this->once())
3062 ->method('getError')
3063 ->will($this->returnValue('err'));
3065 $dbi->expects($this->exactly(2))
3066 ->method('getWarnings')
3067 ->will($this->returnValue([]));
3069 $GLOBALS['dbi'] = $dbi;
3070 $this->insertEdit
= new InsertEdit($GLOBALS['dbi']);
3072 $result = $this->insertEdit
->executeSqlQuery([], $query);
3074 $this->assertEquals(
3075 ['sql_query' => 'SELECT'],
3079 $this->assertEquals(
3084 $this->assertInstanceOf(
3089 $msg = $result[2][0];
3090 $reflectionMsg = new ReflectionProperty(Message
::class, 'params');
3091 $reflectionMsg->setAccessible(true);
3093 $this->assertEquals(
3095 $reflectionMsg->getValue($msg)
3098 $this->assertEquals(
3103 $this->assertEquals(
3108 $this->assertEquals(
3115 * Test for getWarningMessages
3117 public function testGetWarningMessages(): void
3123 'Message' => 'msg1',
3128 'Message' => 'msg2',
3132 $dbi = $this->getMockBuilder(DatabaseInterface
::class)
3133 ->disableOriginalConstructor()
3136 $dbi->expects($this->once())
3137 ->method('getWarnings')
3138 ->will($this->returnValue($warnings));
3140 $GLOBALS['dbi'] = $dbi;
3141 $this->insertEdit
= new InsertEdit($GLOBALS['dbi']);
3143 $result = $this->callFunction(
3146 'getWarningMessages',
3150 $this->assertEquals(
3160 * Test for getDisplayValueForForeignTableColumn
3162 public function testGetDisplayValueForForeignTableColumn(): void
3165 $map['f']['foreign_db'] = 'information_schema';
3166 $map['f']['foreign_table'] = 'TABLES';
3167 $map['f']['foreign_field'] = 'f';
3169 $dbi = $this->getMockBuilder(DatabaseInterface
::class)
3170 ->disableOriginalConstructor()
3173 $dbi->expects($this->once())
3174 ->method('tryQuery')
3176 'SELECT `TABLE_COMMENT` FROM `information_schema`.`TABLES` WHERE '
3178 DatabaseInterface
::CONNECT_USER
,
3179 DatabaseInterface
::QUERY_STORE
3181 ->will($this->returnValue('r1'));
3183 $dbi->expects($this->once())
3186 ->will($this->returnValue('2'));
3188 $dbi->expects($this->once())
3189 ->method('fetchRow')
3191 ->will($this->returnValue(['2']));
3193 $GLOBALS['dbi'] = $dbi;
3194 $this->insertEdit
= new InsertEdit($GLOBALS['dbi']);
3196 $result = $this->insertEdit
->getDisplayValueForForeignTableColumn('=1', $map, 'f');
3198 $this->assertEquals(2, $result);
3202 * Test for getLinkForRelationalDisplayField
3204 public function testGetLinkForRelationalDisplayField(): void
3206 $GLOBALS['cfg']['ServerDefault'] = 1;
3207 $_SESSION['tmpval']['relational_display'] = 'K';
3209 $map['f']['foreign_db'] = 'information_schema';
3210 $map['f']['foreign_table'] = 'TABLES';
3211 $map['f']['foreign_field'] = 'f';
3213 $result = $this->insertEdit
->getLinkForRelationalDisplayField($map, 'f', '=1', 'a>', 'b<');
3215 $sqlSignature = Core
::signSqlQuery(
3216 'SELECT * FROM `information_schema`.`TABLES` WHERE `f`=1'
3219 $this->assertEquals(
3220 '<a href="index.php?route=/sql&db=information_schema&table=TABLES&pos=0&'
3221 . 'sql_signature=' . $sqlSignature . '&'
3222 . 'sql_query=SELECT+%2A+FROM+%60information_schema%60.%60TABLES%60+WHERE'
3223 . '+%60f%60%3D1&lang=en" title="a>">b<</a>',
3227 $_SESSION['tmpval']['relational_display'] = 'D';
3228 $result = $this->insertEdit
->getLinkForRelationalDisplayField($map, 'f', '=1', 'a>', 'b<');
3230 $this->assertEquals(
3231 '<a href="index.php?route=/sql&db=information_schema&table=TABLES&pos=0&'
3232 . 'sql_signature=' . $sqlSignature . '&'
3233 . 'sql_query=SELECT+%2A+FROM+%60information_schema%60.%60TABLES%60+WHERE'
3234 . '+%60f%60%3D1&lang=en" title="b<">a></a>',
3240 * Test for transformEditedValues
3242 public function testTransformEditedValues(): void
3244 $_SESSION[' HMAC_secret '] = hash('sha1', 'test');
3248 $GLOBALS['cfg']['DefaultTransformations']['PreApPend'] = [
3252 $GLOBALS['cfg']['ServerDefault'] = 1;
3253 $_POST['where_clause'] = '1';
3254 $_POST['where_clause_sign'] = Core
::signSqlQuery($_POST['where_clause']);
3255 $transformation = ['transformation_options' => "'','option ,, quoted',abd"];
3256 $result = $this->insertEdit
->transformEditedValues(
3261 'Text_Plain_PreApPend.php',
3267 $this->assertEquals(
3270 'transformations' => ['cnameoption ,, quoted'],
3277 * Test for getQueryValuesForInsertAndUpdateInMultipleEdit
3279 public function testGetQueryValuesForInsertAndUpdateInMultipleEdit(): void
3281 $multi_edit_columns_name = ['0' => 'fld'];
3283 $result = $this->insertEdit
->getQueryValuesForInsertAndUpdateInMultipleEdit(
3284 $multi_edit_columns_name,
3298 $this->assertEquals(
3312 $result = $this->insertEdit
->getQueryValuesForInsertAndUpdateInMultipleEdit(
3313 $multi_edit_columns_name,
3327 $this->assertEquals(
3338 $result = $this->insertEdit
->getQueryValuesForInsertAndUpdateInMultipleEdit(
3339 $multi_edit_columns_name,
3353 $this->assertEquals(
3361 $result = $this->insertEdit
->getQueryValuesForInsertAndUpdateInMultipleEdit(
3362 $multi_edit_columns_name,
3376 $this->assertEquals(
3389 * Test for getCurrentValueAsAnArrayForMultipleEdit
3391 public function testGetCurrentValueAsAnArrayForMultipleEdit(): void
3393 $result = $this->insertEdit
->getCurrentValueAsAnArrayForMultipleEdit(
3404 $this->assertEquals('currVal', $result);
3407 $multi_edit_funcs = ['UUID'];
3409 $dbi = $this->getMockBuilder(DatabaseInterface
::class)
3410 ->disableOriginalConstructor()
3413 $dbi->expects($this->once())
3414 ->method('fetchValue')
3415 ->with('SELECT UUID()')
3416 ->will($this->returnValue('uuid1234'));
3418 $GLOBALS['dbi'] = $dbi;
3419 $this->insertEdit
= new InsertEdit($GLOBALS['dbi']);
3421 $result = $this->insertEdit
->getCurrentValueAsAnArrayForMultipleEdit(
3432 $this->assertEquals("'uuid1234'", $result);
3435 $multi_edit_funcs = ['AES_ENCRYPT'];
3436 $multi_edit_salt = [''];
3437 $result = $this->insertEdit
->getCurrentValueAsAnArrayForMultipleEdit(
3447 $this->assertEquals("AES_ENCRYPT(''','')", $result);
3450 $multi_edit_funcs = ['func'];
3451 $multi_edit_salt = [];
3452 $result = $this->insertEdit
->getCurrentValueAsAnArrayForMultipleEdit(
3462 $this->assertEquals("func(''')", $result);
3465 $result = $this->insertEdit
->getCurrentValueAsAnArrayForMultipleEdit(
3475 $this->assertEquals('func()', $result);
3479 * Test for getCurrentValueForDifferentTypes
3481 public function testGetCurrentValueForDifferentTypes(): void
3486 $dbi = $this->getMockBuilder(DatabaseInterface
::class)
3487 ->disableOriginalConstructor()
3490 $dbi->expects($this->at(4))
3491 ->method('fetchSingleRow')
3492 ->with('SELECT * FROM `table` WHERE 1;')
3493 ->will($this->returnValue($prow));
3494 $dbi->expects($this->exactly(2))
3495 ->method('escapeString')
3496 ->willReturnOnConsecutiveCalls(
3497 $this->returnArgument(0),
3501 $GLOBALS['dbi'] = $dbi;
3502 $this->insertEdit
= new InsertEdit($GLOBALS['dbi']);
3504 $result = $this->insertEdit
->getCurrentValueForDifferentTypes(
3521 $this->assertEquals(
3527 $result = $this->insertEdit
->getCurrentValueForDifferentTypes(
3544 $this->assertEquals(
3550 $result = $this->insertEdit
->getCurrentValueForDifferentTypes(
3567 $this->assertEquals(
3573 $_POST['fields']['multi_edit'][0][0] = [];
3574 $result = $this->insertEdit
->getCurrentValueForDifferentTypes(
3591 $this->assertEquals(
3597 $result = $this->insertEdit
->getCurrentValueForDifferentTypes(
3614 $this->assertEquals(
3620 $result = $this->insertEdit
->getCurrentValueForDifferentTypes(
3637 $this->assertEquals(
3643 $result = $this->insertEdit
->getCurrentValueForDifferentTypes(
3660 $this->assertEquals(
3666 $result = $this->insertEdit
->getCurrentValueForDifferentTypes(
3683 $this->assertEquals(
3689 $_POST['fields']['multi_edit'][0][0] = [];
3690 $result = $this->insertEdit
->getCurrentValueForDifferentTypes(
3707 $this->assertEquals(
3713 $result = $this->insertEdit
->getCurrentValueForDifferentTypes(
3730 $this->assertEquals(
3737 * Test for verifyWhetherValueCanBeTruncatedAndAppendExtraData
3739 public function testVerifyWhetherValueCanBeTruncatedAndAppendExtraData(): void
3741 $extra_data = ['isNeedToRecheck' => true];
3743 $_POST['where_clause'] = [];
3744 $_POST['where_clause'][0] = 1;
3746 $dbi = $this->getMockBuilder(DatabaseInterface
::class)
3747 ->disableOriginalConstructor()
3750 $dbi->expects($this->at(0))
3751 ->method('tryQuery')
3752 ->with('SELECT `table`.`a` FROM `db`.`table` WHERE 1');
3754 $meta = new stdClass();
3755 $meta->type
= 'int';
3756 $dbi->expects($this->at(1))
3757 ->method('getFieldsMeta')
3758 ->will($this->returnValue([$meta]));
3760 $dbi->expects($this->at(2))
3761 ->method('fetchRow')
3762 ->will($this->returnValue(null));
3764 $dbi->expects($this->at(3))
3765 ->method('freeResult');
3767 $dbi->expects($this->at(4))
3768 ->method('tryQuery')
3769 ->with('SELECT `table`.`a` FROM `db`.`table` WHERE 1');
3771 $meta = new stdClass();
3772 $meta->type
= 'int';
3774 $dbi->expects($this->at(5))
3775 ->method('getFieldsMeta')
3776 ->will($this->returnValue([$meta]));
3778 $dbi->expects($this->at(6))
3779 ->method('fetchRow')
3780 ->will($this->returnValue([0 => '123']));
3782 $dbi->expects($this->at(7))
3783 ->method('freeResult');
3785 $dbi->expects($this->at(8))
3786 ->method('tryQuery')
3787 ->with('SELECT `table`.`a` FROM `db`.`table` WHERE 1');
3789 $meta = new stdClass();
3790 $meta->type
= 'timestamp';
3792 $dbi->expects($this->at(9))
3793 ->method('getFieldsMeta')
3794 ->will($this->returnValue([$meta]));
3796 $dbi->expects($this->at(10))
3797 ->method('fetchRow')
3798 ->will($this->returnValue([0 => '2013-08-28 06:34:14']));
3800 $dbi->expects($this->at(11))
3801 ->method('freeResult');
3803 $GLOBALS['dbi'] = $dbi;
3804 $this->insertEdit
= new InsertEdit($GLOBALS['dbi']);
3806 $this->insertEdit
->verifyWhetherValueCanBeTruncatedAndAppendExtraData(
3813 $this->assertFalse($extra_data['isNeedToRecheck']);
3815 $this->insertEdit
->verifyWhetherValueCanBeTruncatedAndAppendExtraData(
3822 $this->assertEquals('123', $extra_data['truncatableFieldValue']);
3823 $this->assertTrue($extra_data['isNeedToRecheck']);
3825 $this->insertEdit
->verifyWhetherValueCanBeTruncatedAndAppendExtraData(
3832 $this->assertEquals(
3833 '2013-08-28 06:34:14.000000',
3834 $extra_data['truncatableFieldValue']
3836 $this->assertTrue($extra_data['isNeedToRecheck']);
3840 * Test for getTableColumns
3842 public function testGetTableColumns(): void
3844 $dbi = $this->getMockBuilder(DatabaseInterface
::class)
3845 ->disableOriginalConstructor()
3848 $dbi->expects($this->at(0))
3849 ->method('selectDb')
3852 $dbi->expects($this->at(1))
3853 ->method('getColumns')
3854 ->with('db', 'table')
3855 ->will($this->returnValue(['a' => 'b', 'c' => 'd']));
3857 $GLOBALS['dbi'] = $dbi;
3858 $this->insertEdit
= new InsertEdit($GLOBALS['dbi']);
3860 $result = $this->insertEdit
->getTableColumns('db', 'table');
3862 $this->assertEquals(
3872 * Test for determineInsertOrEdit
3874 public function testDetermineInsertOrEdit(): void
3876 $dbi = $this->getMockBuilder(DatabaseInterface
::class)
3877 ->disableOriginalConstructor()
3880 $GLOBALS['dbi'] = $dbi;
3881 $_POST['where_clause'] = '1';
3882 $_SESSION['edit_next'] = '1';
3883 $_POST['ShowFunctionFields'] = true;
3884 $_POST['ShowFieldTypesInDataEditView'] = true;
3885 $_POST['after_insert'] = 'edit_next';
3886 $GLOBALS['cfg']['InsertRows'] = 2;
3887 $GLOBALS['cfg']['ShowSQL'] = false;
3888 $_POST['default_action'] = 'insert';
3890 $responseMock = $this->getMockBuilder(Response
::class)
3891 ->disableOriginalConstructor()
3892 ->setMethods(['addHtml'])
3895 $restoreInstance = Response
::getInstance();
3896 $response = new ReflectionProperty(Response
::class, 'instance');
3897 $response->setAccessible(true);
3898 $response->setValue($responseMock);
3900 $this->insertEdit
= new InsertEdit($GLOBALS['dbi']);
3902 $result = $this->insertEdit
->determineInsertOrEdit('1', 'db', 'table');
3904 $this->assertEquals(
3919 unset($_POST['where_clause']);
3920 unset($_SESSION['edit_next']);
3921 $_POST['default_action'] = '';
3923 $result = $this->insertEdit
->determineInsertOrEdit(null, 'db', 'table');
3925 $response->setValue($restoreInstance);
3927 $this->assertEquals(
3946 * Test for getCommentsMap
3948 public function testGetCommentsMap(): void
3950 $GLOBALS['cfg']['ShowPropertyComments'] = false;
3952 $dbi = $this->getMockBuilder(DatabaseInterface
::class)
3953 ->disableOriginalConstructor()
3956 $dbi->expects($this->once())
3957 ->method('getColumns')
3958 ->with('db', 'table', null, true)
3970 $dbi->expects($this->any())
3971 ->method('getTable')
3974 new Table('table', 'db')
3978 $GLOBALS['dbi'] = $dbi;
3979 $this->insertEdit
= new InsertEdit($GLOBALS['dbi']);
3981 $this->assertEquals(
3983 $this->insertEdit
->getCommentsMap('db', 'table')
3986 $GLOBALS['cfg']['ShowPropertyComments'] = true;
3988 $this->assertEquals(
3990 $this->insertEdit
->getCommentsMap('db', 'table')
3995 * Test for getUrlParameters
3997 public function testGetUrlParameters(): void
4001 $_POST['sql_query'] = 'SELECT';
4002 $goto = 'tbl_sql.php';
4004 $this->assertEquals(
4007 'sql_query' => 'SELECT',
4010 $this->insertEdit
->getUrlParameters('foo', 'bar')
4015 * Test for getHtmlForIgnoreOption
4017 public function testGetHtmlForIgnoreOption(): void
4019 $expected = '<input type="checkbox" %sname="insert_ignore_1"'
4020 . ' id="insert_ignore_1"><label for="insert_ignore_1">'
4021 . 'Ignore</label><br>' . "\n";
4022 $checked = 'checked="checked" ';
4023 $this->assertEquals(
4024 sprintf($expected, $checked),
4025 $this->insertEdit
->getHtmlForIgnoreOption(1)
4028 $this->assertEquals(
4029 sprintf($expected, ''),
4030 $this->insertEdit
->getHtmlForIgnoreOption(1, false)
4035 * Test for getHtmlForInsertEditFormColumn
4037 public function testGetHtmlForInsertEditFormColumn(): void
4039 $_SESSION[' HMAC_secret '] = hash('sha1', 'test');
4042 $GLOBALS['plugin_scripts'] = [];
4046 'Type' => 'varchar(20)',
4048 'Privileges' => 'insert,update,select',
4051 $repopulate = [md5('col') => 'val'];
4053 'input_transformation' => 'Input/Image_JPEG_Upload.php',
4054 'input_transformation_options' => '150',
4057 // Test w/ input transformation
4058 $actual = $this->callFunction(
4061 'getHtmlForInsertEditFormColumn',
4093 $this->assertStringContainsString(
4097 $this->assertStringContainsString(
4098 '<option>AES_ENCRYPT</option>',
4101 $this->assertStringContainsString(
4102 '<span class="column_type" dir="ltr">varchar(20)</span>',
4105 $this->assertStringContainsString(
4106 '<tr class="noclick">',
4109 $this->assertStringContainsString(
4110 '<span class="default_value hide">',
4113 $this->assertStringContainsString(
4114 '<img src="" width="150" height="100" '
4115 . 'alt="Image preview here">',
4118 $this->assertStringContainsString(
4119 '<input type="file" '
4120 . 'name="fields_upload[d89e2ddb530bb8953b290ab0793aecb0]" '
4121 . 'accept="image/*" '
4122 . 'class="image-upload"'
4127 // Test w/o input_transformation
4130 'Field' => 'qwerty',
4131 'Type' => 'datetime',
4136 'Privileges' => 'insert,update,select',
4139 $repopulate = [md5('qwerty') => '12-10-14'];
4140 $actual = $this->callFunction(
4143 'getHtmlForInsertEditFormColumn',
4174 $this->assertStringContainsString(
4178 $this->assertStringContainsString(
4179 '<option>UUID</option>',
4182 $this->assertStringContainsString(
4183 '<span class="column_type" dir="ltr">datetime</span>',
4186 $this->assertStringContainsString(
4187 '<input type="text" '
4188 . 'name="fields[d8578edf8458ce06fbc5bb76a58c5ca4]" '
4189 . 'value="12-10-14.000000"',
4195 * Test for getHtmlForInsertEditRow
4197 public function testGetHtmlForInsertEditRow(): void
4201 $GLOBALS['plugin_scripts'] = [];
4202 $GLOBALS['cfg']['LongtextDoubleTextarea'] = true;
4203 $GLOBALS['cfg']['CharEditing'] = true;
4208 'Type' => 'longtext',
4210 'pma_type' => 'longtext',
4211 'True_Type' => 'longtext',
4212 'Privileges' => 'select,insert,update,references',
4215 $actual = $this->insertEdit
->getHtmlForInsertEditRow(
4242 $this->assertStringContainsString(
4246 $this->assertStringContainsString(
4250 $this->assertStringContainsString(
4254 $this->assertStringContainsString(
4255 '<th class="fillPage">Value</th>',
4258 $this->assertStringContainsString(
4259 '<span class="column_type" dir="ltr">longtext</span>',
4262 $this->assertStringContainsString(
4263 '<textarea name="fields[098f6bcd4621d373cade4e832627b4f6]"',
4269 * Test for getHtmlForInsertEditRow based on the column privilges
4271 public function testGetHtmlForInsertEditRowBasedOnColumnPrivileges(): void
4275 $GLOBALS['plugin_scripts'] = [];
4276 $GLOBALS['cfg']['LongtextDoubleTextarea'] = true;
4277 $GLOBALS['cfg']['CharEditing'] = true;
4283 'Type' => 'longtext',
4286 'pma_type' => 'longtext',
4287 'True_Type' => 'longtext',
4288 'Privileges' => 'select,insert,update,references',
4292 'Type' => 'longtext',
4295 'pma_type' => 'longtext',
4296 'True_Type' => 'longtext',
4297 'Privileges' => 'select,insert,references',
4300 $actual = $this->insertEdit
->getHtmlForInsertEditRow(
4327 $this->assertStringContainsString(
4331 $this->assertStringNotContainsString(
4340 'Type' => 'longtext',
4344 'pma_type' => 'longtext',
4345 'True_Type' => 'longtext',
4346 'Privileges' => 'select,insert,update,references',
4350 'Type' => 'longtext',
4354 'pma_type' => 'longtext',
4355 'True_Type' => 'longtext',
4356 'Privileges' => 'select,update,references',
4359 $actual = $this->insertEdit
->getHtmlForInsertEditRow(
4386 $this->assertStringContainsString(
4390 $this->assertStringContainsString(
4391 '<textarea name="fields[37b51d194a7513e45b56f6524f2d51f2]"',