Translated using Weblate (Slovenian)
[phpmyadmin.git] / test / classes / InsertEditTest.php
blobece97aa8d4a091d979d7b6a5a49e2f9f23be79fd
1 <?php
3 declare(strict_types=1);
5 namespace PhpMyAdmin\Tests;
7 use PhpMyAdmin\Core;
8 use PhpMyAdmin\DatabaseInterface;
9 use PhpMyAdmin\Header;
10 use PhpMyAdmin\InsertEdit;
11 use PhpMyAdmin\Message;
12 use PhpMyAdmin\Response;
13 use PhpMyAdmin\Scripts;
14 use PhpMyAdmin\Table;
15 use PhpMyAdmin\Url;
16 use ReflectionProperty;
17 use stdClass;
18 use function hash;
19 use function md5;
20 use function sprintf;
22 /**
23 * @group medium
25 class InsertEditTest extends AbstractTestCase
27 /** @var InsertEdit */
28 private $insertEdit;
30 /**
31 * Setup for test cases
33 protected function setUp(): void
35 parent::setUp();
36 parent::defineVersionConstants();
37 parent::setLanguage();
38 parent::setGlobalConfig();
39 parent::loadDefaultConfig();
40 parent::setTheme();
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']);
71 /**
72 * Teardown all objects
74 protected function tearDown(): void
76 parent::tearDown();
77 $response = new ReflectionProperty(Response::class, 'instance');
78 $response->setAccessible(true);
79 $response->setValue(null);
80 $response->setAccessible(false);
83 /**
84 * Test for getFormParametersForInsertForm
86 public function testGetFormParametersForInsertForm(): void
88 $where_clause = [
89 'foo' => 'bar ',
90 '1' => ' test',
92 $_POST['clause_is_unique'] = false;
93 $_POST['sql_query'] = 'SELECT a';
94 $GLOBALS['goto'] = 'index.php';
96 $result = $this->insertEdit->getFormParametersForInsertForm(
97 'dbname',
98 'tablename',
99 [],
100 $where_clause,
101 'localhost'
104 $this->assertEquals(
106 'db' => 'dbname',
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,
115 $result
120 * Test for getWhereClauseArray
122 public function testGetWhereClauseArray(): void
124 $this->assertEquals(
126 $this->callFunction(
127 $this->insertEdit,
128 InsertEdit::class,
129 'getWhereClauseArray',
130 [null]
134 $this->assertEquals(
140 $this->callFunction(
141 $this->insertEdit,
142 InsertEdit::class,
143 'getWhereClauseArray',
144 [[1, 2, 3]]
148 $this->assertEquals(
149 ['clause'],
150 $this->callFunction(
151 $this->insertEdit,
152 InsertEdit::class,
153 'getWhereClauseArray',
154 ['clause']
160 * Test for analyzeWhereClauses
162 public function testAnalyzeWhereClause(): void
164 $clauses = [
165 'a=1',
166 'b="fo\o"',
169 $dbi = $this->getMockBuilder(DatabaseInterface::class)
170 ->disableOriginalConstructor()
171 ->getMock();
173 $dbi->expects($this->exactly(2))
174 ->method('query')
175 ->willReturnOnConsecutiveCalls(
176 'result1',
177 'result2'
180 $dbi->expects($this->exactly(2))
181 ->method('fetchAssoc')
182 ->willReturnOnConsecutiveCalls(
183 ['assoc1'],
184 ['assoc2']
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(
197 $this->insertEdit,
198 InsertEdit::class,
199 'analyzeWhereClauses',
201 $clauses,
202 'table',
203 'db',
207 $this->assertEquals(
210 'a=1',
211 'b="fo\\\\o"',
214 'result1',
215 'result2',
218 ['assoc1'],
219 ['assoc2'],
223 $result
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;
237 $meta_arr = [$temp];
239 $dbi = $this->getMockBuilder(DatabaseInterface::class)
240 ->disableOriginalConstructor()
241 ->getMock();
243 $dbi->expects($this->at(0))
244 ->method('getFieldsMeta')
245 ->with('result1')
246 ->will($this->returnValue($meta_arr));
248 $GLOBALS['dbi'] = $dbi;
249 $this->insertEdit = new InsertEdit($GLOBALS['dbi']);
251 $result = $this->callFunction(
252 $this->insertEdit,
253 InsertEdit::class,
254 'showEmptyResultMessageOrSetUniqueCondition',
256 ['1' => ['1' => 1]],
259 'SELECT',
260 ['1' => 'result1'],
264 $this->assertTrue($result);
266 // case 2
267 $GLOBALS['cfg']['ShowSQL'] = false;
269 $responseMock = $this->getMockBuilder(Response::class)
270 ->disableOriginalConstructor()
271 ->setMethods(['addHtml'])
272 ->getMock();
274 $restoreInstance = Response::getInstance();
275 $response = new ReflectionProperty(Response::class, 'instance');
276 $response->setAccessible(true);
277 $response->setValue($responseMock);
279 $result = $this->callFunction(
280 $this->insertEdit,
281 InsertEdit::class,
282 'showEmptyResultMessageOrSetUniqueCondition',
284 [false],
286 ['1'],
287 'SELECT',
288 ['1' => 'result1'],
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()
306 ->getMock();
308 $dbi->expects($this->at(0))
309 ->method('query')
310 ->with(
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(
321 $this->insertEdit,
322 InsertEdit::class,
323 'loadFirstRow',
324 ['table', 'db']
327 $this->assertEquals(
329 'result1',
331 false,
332 false,
335 $result
340 * Test for urlParamsInEditMode
342 public function testUrlParamsInEditMode(): void
344 $where_clause_array = [
345 'foo=1',
346 'bar=2',
348 $_POST['sql_query'] = 'SELECT 1';
350 $result = $this->insertEdit->urlParamsInEditMode([1], $where_clause_array);
352 $this->assertEquals(
354 '0' => 1,
355 'where_clause' => 'bar=2',
356 'sql_query' => 'SELECT 1',
358 $result
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',
375 $result
377 $this->assertStringContainsString(
378 'ShowFunctionFields=1&amp;ShowFieldTypesInDataEditView=1&amp;goto=index.php%3Froute%3D%2Fsql',
379 $result
381 $this->assertStringContainsString(
382 'Function',
383 $result
386 // case 2
387 $result = $this->insertEdit->showTypeOrFunction('function', $url_params, true);
389 $this->assertStringContainsString(
390 'index.php?route=/table/change',
391 $result
393 $this->assertStringContainsString(
394 'ShowFunctionFields=0&amp;ShowFieldTypesInDataEditView=1&amp;goto=index.php%3Froute%3D%2Fsql',
395 $result
397 $this->assertStringContainsString(
398 'Function',
399 $result
402 // case 3
403 $result = $this->insertEdit->showTypeOrFunction('type', $url_params, false);
405 $this->assertStringContainsString(
406 'index.php?route=/table/change',
407 $result
409 $this->assertStringContainsString(
410 'ShowFunctionFields=1&amp;ShowFieldTypesInDataEditView=1&amp;goto=index.php%3Froute%3D%2Fsql',
411 $result
413 $this->assertStringContainsString(
414 'Type',
415 $result
418 // case 4
419 $result = $this->insertEdit->showTypeOrFunction('type', $url_params, true);
421 $this->assertStringContainsString(
422 'index.php?route=/table/change',
423 $result
425 $this->assertStringContainsString(
426 'ShowFunctionFields=1&amp;ShowFieldTypesInDataEditView=0&amp;goto=index.php%3Froute%3D%2Fsql',
427 $result
429 $this->assertStringContainsString(
430 'Type',
431 $result
436 * Test for analyzeTableColumnsArray
438 public function testAnalyzeTableColumnsArray(): void
440 $column = [
441 'Field' => '1<2',
442 'Field_md5' => 'pswd',
443 'Type' => 'float(10, 1)',
446 $result = $this->callFunction(
447 $this->insertEdit,
448 InsertEdit::class,
449 'analyzeTableColumnsArray',
451 $column,
453 false,
457 $this->assertEquals(
458 $result['Field_html'],
459 '1&lt;2'
462 $this->assertEquals(
463 $result['Field_md5'],
464 '4342210df36bf2ff2c4e2a997a6d4089'
467 $this->assertEquals(
468 $result['True_Type'],
469 'float'
472 $this->assertEquals(
473 $result['len'],
477 $this->assertEquals(
478 $result['Field_title'],
479 '1&lt;2'
482 $this->assertEquals(
483 $result['is_binary'],
484 false
487 $this->assertEquals(
488 $result['is_blob'],
489 false
492 $this->assertEquals(
493 $result['is_char'],
494 false
497 $this->assertEquals(
498 $result['pma_type'],
499 'float(10, 1)'
502 $this->assertEquals(
503 $result['wrap'],
504 ' nowrap'
507 $this->assertEquals(
508 $result['Field'],
509 '1<2'
514 * Test for getColumnTitle
516 public function testGetColumnTitle(): void
518 $column = [];
519 $column['Field'] = 'f1<';
520 $column['Field_html'] = 'f1&lt;';
522 $this->assertEquals(
523 $this->callFunction(
524 $this->insertEdit,
525 InsertEdit::class,
526 'getColumnTitle',
528 $column,
532 'f1&lt;'
535 $comments = [];
536 $comments['f1<'] = 'comment>';
538 $result = $this->callFunction(
539 $this->insertEdit,
540 InsertEdit::class,
541 'getColumnTitle',
543 $column,
544 $comments,
548 $this->assertStringContainsString(
549 'title="comment&gt;"',
550 $result
553 $this->assertStringContainsString(
554 'f1&lt;',
555 $result
560 * Test for isColumn
562 public function testIsColumn(): void
564 $column = [];
565 $types = [
566 'binary',
567 'varbinary',
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));
582 $types = [
583 'char',
584 'varchar',
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));
596 $types = [
597 'blob',
598 'tinyblob',
599 'mediumblob',
600 'longblob',
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
627 $column = [];
628 $column['True_Type'] = 'set';
629 $this->assertEquals(
631 'set',
633 false,
635 $this->callFunction(
636 $this->insertEdit,
637 InsertEdit::class,
638 'getEnumSetAndTimestampColumns',
640 $column,
641 false,
646 $column['True_Type'] = 'enum';
647 $this->assertEquals(
649 'enum',
651 false,
653 $this->callFunction(
654 $this->insertEdit,
655 InsertEdit::class,
656 'getEnumSetAndTimestampColumns',
658 $column,
659 false,
664 $column['True_Type'] = 'timestamp';
665 $column['Type'] = 'date';
666 $this->assertEquals(
668 'date',
669 ' nowrap',
670 true,
672 $this->callFunction(
673 $this->insertEdit,
674 InsertEdit::class,
675 'getEnumSetAndTimestampColumns',
677 $column,
678 false,
683 $column['True_Type'] = 'timestamp';
684 $column['Type'] = 'date';
685 $this->assertEquals(
687 'date',
688 ' nowrap',
689 false,
691 $this->callFunction(
692 $this->insertEdit,
693 InsertEdit::class,
694 'getEnumSetAndTimestampColumns',
696 $column,
697 true,
702 $column['True_Type'] = 'SET';
703 $column['Type'] = 'num';
704 $this->assertEquals(
706 'num',
707 ' nowrap',
708 false,
710 $this->callFunction(
711 $this->insertEdit,
712 InsertEdit::class,
713 'getEnumSetAndTimestampColumns',
715 $column,
716 false,
721 $column['True_Type'] = '';
722 $column['Type'] = 'num';
723 $this->assertEquals(
725 'num',
726 ' nowrap',
727 false,
729 $this->callFunction(
730 $this->insertEdit,
731 InsertEdit::class,
732 'getEnumSetAndTimestampColumns',
734 $column,
735 false,
742 * Test for getFunctionColumn
744 public function testGetFunctionColumn(): void
746 $GLOBALS['cfg']['ProtectBinary'] = 'blob';
747 $column = [];
748 $column['is_blob'] = true;
749 $this->assertStringContainsString(
750 '<td class="text-center">Binary</td>',
751 $this->callFunction(
752 $this->insertEdit,
753 InsertEdit::class,
754 'getFunctionColumn',
756 $column,
757 false,
764 false,
765 false,
771 $GLOBALS['cfg']['ProtectBinary'] = 'all';
772 $column['is_binary'] = true;
773 $this->assertStringContainsString(
774 '<td class="text-center">Binary</td>',
775 $this->callFunction(
776 $this->insertEdit,
777 InsertEdit::class,
778 'getFunctionColumn',
780 $column,
781 true,
788 false,
789 false,
795 $GLOBALS['cfg']['ProtectBinary'] = 'noblob';
796 $column['is_blob'] = false;
797 $this->assertStringContainsString(
798 '<td class="text-center">Binary</td>',
799 $this->callFunction(
800 $this->insertEdit,
801 InsertEdit::class,
802 'getFunctionColumn',
804 $column,
805 true,
812 false,
813 false,
819 $GLOBALS['cfg']['ProtectBinary'] = false;
820 $column['True_Type'] = 'enum';
821 $this->assertStringContainsString(
822 '<td class="text-center">--</td>',
823 $this->callFunction(
824 $this->insertEdit,
825 InsertEdit::class,
826 'getFunctionColumn',
828 $column,
829 true,
836 false,
837 false,
843 $column['True_Type'] = 'set';
844 $this->assertStringContainsString(
845 '<td class="text-center">--</td>',
846 $this->callFunction(
847 $this->insertEdit,
848 InsertEdit::class,
849 'getFunctionColumn',
851 $column,
852 true,
859 false,
860 false,
866 $column['True_Type'] = '';
867 $column['pma_type'] = 'int';
868 $this->assertStringContainsString(
869 '<td class="text-center">--</td>',
870 $this->callFunction(
871 $this->insertEdit,
872 InsertEdit::class,
873 'getFunctionColumn',
875 $column,
876 true,
879 ['int'],
883 false,
884 false,
890 $column['Field'] = 'num';
891 $this->assertStringContainsString(
892 '<select name="funcsa" b tabindex="5" id="field_3_1"',
893 $this->callFunction(
894 $this->insertEdit,
895 InsertEdit::class,
896 'getFunctionColumn',
898 $column,
899 true,
900 'a',
901 'b',
906 false,
907 false,
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';
923 $column['Type'] = 0;
924 $column['Field_md5'] = 'foobar';
925 $foreigners = [
926 'foreign_keys_data' => [],
929 $result = $this->callFunction(
930 $this->insertEdit,
931 InsertEdit::class,
932 'getNullColumn',
934 $column,
935 'a',
936 true,
940 '<script>',
941 $foreigners,
943 false,
947 $this->assertStringContainsString(
948 '<input type="hidden" name="fields_null_preva" value="on">',
949 $result
952 $this->assertStringContainsString(
953 '<input type="checkbox" class="checkbox_null" tabindex="2" '
954 . 'name="fields_nulla" checked="checked" id="field_1_2"',
955 $result
958 $this->assertStringContainsString(
959 '<input type="hidden" class="nullify_code" name="nullify_codea" '
960 . 'value="2"',
961 $result
964 $this->assertStringContainsString(
965 '<input type="hidden" class="hashed_field" name="hashed_fielda" '
966 . 'value="foobar">',
967 $result
970 $this->assertStringContainsString(
971 '<input type="hidden" class="multi_edit" name="multi_edita" '
972 . 'value="<script>"',
973 $result
976 // case 2
977 $column['Null'] = 'NO';
978 $result = $this->callFunction(
979 $this->insertEdit,
980 InsertEdit::class,
981 'getNullColumn',
983 $column,
984 'a',
985 true,
989 '<script>',
992 false,
996 $this->assertEquals(
997 "<td></td>\n",
998 $result
1001 // case 3
1002 $column['Null'] = 'YES';
1003 $result = $this->callFunction(
1004 $this->insertEdit,
1005 InsertEdit::class,
1006 'getNullColumn',
1008 $column,
1009 'a',
1010 true,
1014 '<script>',
1017 true,
1021 $this->assertEquals(
1022 "<td></td>\n",
1023 $result
1028 * Test for getNullifyCodeForNullColumn
1030 public function testGetNullifyCodeForNullColumn(): void
1032 $column = $foreignData = [];
1033 $foreigners = [
1034 'foreign_keys_data' => [],
1036 $column['Field'] = 'f';
1037 $column['True_Type'] = 'enum';
1038 $column['Type'] = 'ababababababababababa';
1039 $this->assertEquals(
1040 '1',
1041 $this->callFunction(
1042 $this->insertEdit,
1043 InsertEdit::class,
1044 'getNullifyCodeForNullColumn',
1046 $column,
1047 $foreigners,
1053 $column['True_Type'] = 'enum';
1054 $column['Type'] = 'abababababababababab';
1055 $this->assertEquals(
1056 '2',
1057 $this->callFunction(
1058 $this->insertEdit,
1059 InsertEdit::class,
1060 'getNullifyCodeForNullColumn',
1062 $column,
1063 $foreigners,
1069 $column['True_Type'] = 'set';
1070 $this->assertEquals(
1071 '3',
1072 $this->callFunction(
1073 $this->insertEdit,
1074 InsertEdit::class,
1075 'getNullifyCodeForNullColumn',
1077 $column,
1078 $foreigners,
1084 $column['True_Type'] = '';
1085 $foreigners['f'] = true;
1086 $foreignData['foreign_link'] = '';
1087 $this->assertEquals(
1088 '4',
1089 $this->callFunction(
1090 $this->insertEdit,
1091 InsertEdit::class,
1092 'getNullifyCodeForNullColumn',
1094 $column,
1095 $foreigners,
1096 $foreignData,
1103 * Test for getForeignLink
1105 public function testGetForeignLink(): void
1107 $column = [];
1108 $column['Field'] = 'f';
1109 $GLOBALS['cfg']['ServerDefault'] = 2;
1110 $result = $this->callFunction(
1111 $this->insertEdit,
1112 InsertEdit::class,
1113 'getForeignLink',
1115 $column,
1116 'a',
1117 'b',
1118 'd',
1122 'abc',
1124 'tbl',
1125 'db',
1128 false,
1132 $this->assertStringContainsString(
1133 '<input type="hidden" name="fields_typeb" value="foreign"',
1134 $result
1137 $this->assertStringContainsString(
1138 '" data-post="db=db&amp;table=tbl&amp;field=f&amp;rownumber=8'
1139 . '&amp;data=abc&amp;server=1&amp;lang=en">',
1140 $result
1142 $this->assertStringContainsString(
1143 '<a class="ajax browse_foreign" href="index.php?route=/browse-foreigners',
1144 $result
1147 $this->assertStringContainsString(
1148 '<input type="text" name="fieldsb" class="textfield" d tabindex="2" '
1149 . 'id="field_1_3" value="abc"',
1150 $result
1155 * Test for dispRowForeignData
1157 public function testDispRowForeignData(): void
1159 $column = [];
1160 $column['is_binary'] = false;
1161 $foreignData = [];
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(
1168 $this->insertEdit,
1169 InsertEdit::class,
1170 'dispRowForeignData',
1172 $column,
1173 'a',
1174 'b',
1175 'd',
1179 '<s>',
1180 $foreignData,
1181 false,
1185 $this->assertStringContainsString(
1186 "a\n",
1187 $result
1190 $this->assertStringContainsString(
1191 '<select name="fieldsb" d class="textfield" tabindex="2" '
1192 . 'id="field_1_3">',
1193 $result
1196 $this->assertStringContainsString(
1197 '<input type="hidden" name="fields_typeb" value="foreign"',
1198 $result
1203 * Test for dispRowForeignData
1205 public function testDispRowForeignDataWithHex(): void
1207 $column = [];
1208 $column['is_binary'] = true;
1209 $foreignData = [];
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(
1216 $this->insertEdit,
1217 InsertEdit::class,
1218 'dispRowForeignData',
1220 $column,
1221 'a',
1222 'b',
1223 'd',
1227 '<s>',
1228 $foreignData,
1229 false,
1233 $this->assertStringContainsString(
1234 "a\n",
1235 $result
1238 $this->assertStringContainsString(
1239 '<select name="fieldsb" d class="textfield" tabindex="2" '
1240 . 'id="field_1_3">',
1241 $result
1244 $this->assertStringContainsString(
1245 '<input type="hidden" name="fields_typeb" value="hex"',
1246 $result
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;
1261 $column = [];
1262 $column['is_char'] = true;
1263 $column['Type'] = 'char(10)';
1264 $column['True_Type'] = 'char';
1265 $result = $this->callFunction(
1266 $this->insertEdit,
1267 InsertEdit::class,
1268 'getTextarea',
1270 $column,
1271 'a',
1272 'b',
1277 'abc/',
1278 'foobar',
1279 'CHAR',
1280 false,
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">',
1288 $result
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'] = [
1302 'html' => 'foo',
1303 'plain' => 'data',
1306 $result = $this->callFunction(
1307 $this->insertEdit,
1308 InsertEdit::class,
1309 'getPmaTypeEnum',
1311 $column,
1312 'a',
1313 'b',
1314 $extracted_columnspec,
1315 'd',
1319 'foobar',
1320 false,
1324 $this->assertStringContainsString(
1325 '<input type="hidden" name="fields_typeb" value="enum">',
1326 $result
1329 $this->assertStringContainsString(
1330 '<input type="radio" name="fieldsb"',
1331 $result
1334 $column['Type'] = 'ababababababababababa';
1335 $result = $this->callFunction(
1336 $this->insertEdit,
1337 InsertEdit::class,
1338 'getPmaTypeEnum',
1340 $column,
1341 'a',
1342 'b',
1343 $extracted_columnspec,
1344 'd',
1348 'foobar',
1349 false,
1353 $this->assertStringContainsString(
1354 '<input type="hidden" name="fields_typeb" value="enum"',
1355 $result
1358 $this->assertStringContainsString(
1359 '<select name="fieldsb" d class="textfield" tabindex="2" '
1360 . 'id="field_1_3">',
1361 $result
1366 * Test for getColumnEnumValues
1368 public function testGetColumnEnumValues(): void
1370 $extracted_columnspec = $column = [];
1371 $extracted_columnspec['enum_set_values'] = [
1372 '<abc>',
1373 '"foo"',
1376 $column['values'] = 'abc';
1378 $result = $this->callFunction(
1379 $this->insertEdit,
1380 InsertEdit::class,
1381 'getColumnEnumValues',
1383 $column,
1384 $extracted_columnspec,
1387 $this->assertEquals(
1390 'plain' => '<abc>',
1391 'html' => '&lt;abc&gt;',
1394 'plain' => '"foo"',
1395 'html' => '&quot;foo&quot;',
1398 $result
1403 * Test for getDropDownDependingOnLength
1405 public function testGetDropDownDependingOnLength(): void
1407 $column_enum_values = [
1409 'html' => 'foo',
1410 'plain' => 'data',
1413 'html' => 'bar',
1414 'plain' => '',
1418 $result = $this->callFunction(
1419 $this->insertEdit,
1420 InsertEdit::class,
1421 'getDropDownDependingOnLength',
1424 'a',
1425 'b',
1429 'data',
1430 $column_enum_values,
1431 false,
1435 $this->assertStringContainsString(
1436 '<select name="fieldsa" b class="textfield" tabindex="2" '
1437 . 'id="field_1_3">',
1438 $result
1441 $this->assertStringContainsString(
1442 '<option value="foo" selected="selected">',
1443 $result
1446 $this->assertStringContainsString(
1447 '<option value="bar">',
1448 $result
1451 // case 2
1452 $column_enum_values = [
1454 'html' => 'foo',
1455 'plain' => 'data',
1459 $column = [];
1460 $column['Default'] = 'data';
1461 $column['Null'] = 'YES';
1462 $result = $this->callFunction(
1463 $this->insertEdit,
1464 InsertEdit::class,
1465 'getDropDownDependingOnLength',
1467 $column,
1468 'a',
1469 'b',
1474 $column_enum_values,
1475 false,
1479 $this->assertStringContainsString(
1480 '<option value="foo" selected="selected">',
1481 $result
1486 * Test for getRadioButtonDependingOnLength
1488 public function testGetRadioButtonDependingOnLength(): void
1490 $column_enum_values = [
1492 'html' => 'foo',
1493 'plain' => 'data',
1496 'html' => 'bar',
1497 'plain' => '',
1501 $result = $this->callFunction(
1502 $this->insertEdit,
1503 InsertEdit::class,
1504 'getRadioButtonDependingOnLength',
1506 'a',
1507 'b',
1512 'data',
1513 $column_enum_values,
1514 false,
1518 $this->assertStringContainsString(
1519 '<input type="radio" name="fieldsa" class="textfield" value="foo" '
1520 . 'id="field_1_3_0" b checked="checked" tabindex="2">',
1521 $result
1524 $this->assertStringContainsString(
1525 '<label for="field_1_3_0">foo</label>',
1526 $result
1529 $this->assertStringContainsString(
1530 '<input type="radio" name="fieldsa" class="textfield" value="bar" '
1531 . 'id="field_1_3_1" b tabindex="2">',
1532 $result
1535 $this->assertStringContainsString(
1536 '<label for="field_1_3_1">bar</label>',
1537 $result
1540 // case 2
1541 $column_enum_values = [
1543 'html' => 'foo',
1544 'plain' => 'data',
1548 $column = [];
1549 $column['Default'] = 'data';
1550 $column['Null'] = 'YES';
1551 $result = $this->callFunction(
1552 $this->insertEdit,
1553 InsertEdit::class,
1554 'getRadioButtonDependingOnLength',
1556 'a',
1557 'b',
1559 $column,
1563 $column_enum_values,
1564 false,
1568 $this->assertStringContainsString(
1569 '<input type="radio" name="fieldsa" class="textfield" value="foo" '
1570 . 'id="field_1_3_0" b checked="checked" tabindex="2">',
1571 $result
1576 * Test for getPmaTypeSet
1578 public function testGetPmaTypeSet(): void
1580 $column = [];
1581 $column['values'] = [
1583 'html' => '&lt;',
1584 'plain' => '<',
1588 $column['select_size'] = 1;
1590 $result = $this->callFunction(
1591 $this->insertEdit,
1592 InsertEdit::class,
1593 'getPmaTypeSet',
1595 $column,
1597 'a',
1598 'b',
1599 'c',
1603 'data,<',
1604 false,
1608 $this->assertStringContainsString("a\n", $result);
1610 $this->assertStringContainsString(
1611 '<input type="hidden" name="fields_typeb" value="set">',
1612 $result
1615 $this->assertStringContainsString(
1616 '<option value="&lt;" selected="selected">&lt;</option>',
1617 $result
1620 $this->assertStringContainsString(
1621 '<select name="fieldsb[]" class="textfield" size="1" '
1622 . 'multiple="multiple" c tabindex="2" id="field_1_3">',
1623 $result
1628 * Test for getColumnSetValueAndSelectSize
1630 public function testGetColumnSetValueAndSelectSize(): void
1632 $extracted_columnspec = $column = [];
1633 $extracted_columnspec['enum_set_values'] = [
1634 'a',
1635 '<',
1637 $result = $this->callFunction(
1638 $this->insertEdit,
1639 InsertEdit::class,
1640 'getColumnSetValueAndSelectSize',
1643 $extracted_columnspec,
1647 $this->assertEquals(
1651 'plain' => 'a',
1652 'html' => 'a',
1655 'plain' => '<',
1656 'html' => '&lt;',
1661 $result
1664 $column['values'] = [
1668 $column['select_size'] = 3;
1669 $result = $this->callFunction(
1670 $this->insertEdit,
1671 InsertEdit::class,
1672 'getColumnSetValueAndSelectSize',
1674 $column,
1675 $extracted_columnspec,
1679 $this->assertEquals(
1687 $result
1692 * Test for getBinaryAndBlobColumn
1694 public function testGetBinaryAndBlobColumn(): void
1696 $GLOBALS['cfg']['ProtectBinary'] = 'blob';
1697 $GLOBALS['cfg']['ShowFunctionFields'] = true;
1698 $column = [];
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(
1706 $this->insertEdit,
1707 InsertEdit::class,
1708 'getBinaryAndBlobColumn',
1710 $column,
1711 '12\\"23',
1712 null,
1714 'a',
1715 'b',
1716 'c',
1720 '/',
1721 null,
1722 'foo',
1723 true,
1724 false,
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>&nbsp;(Max: 64KiB)' . "\n",
1734 $result
1737 // case 2
1738 $GLOBALS['cfg']['ProtectBinary'] = 'all';
1739 $column['is_binary'] = true;
1741 $result = $this->callFunction(
1742 $this->insertEdit,
1743 InsertEdit::class,
1744 'getBinaryAndBlobColumn',
1746 $column,
1747 '1223',
1748 null,
1750 'a',
1751 'b',
1752 'c',
1756 '/',
1757 null,
1758 'foo',
1759 false,
1760 false,
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">',
1768 $result
1771 // case 3
1772 $GLOBALS['cfg']['ProtectBinary'] = 'noblob';
1773 $column['is_blob'] = false;
1775 $result = $this->callFunction(
1776 $this->insertEdit,
1777 InsertEdit::class,
1778 'getBinaryAndBlobColumn',
1780 $column,
1781 '1223',
1782 null,
1784 'a',
1785 'b',
1786 'c',
1790 '/',
1791 null,
1792 'foo',
1793 true,
1794 false,
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">',
1802 $result
1805 // case 4
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(
1817 $this->insertEdit,
1818 InsertEdit::class,
1819 'getBinaryAndBlobColumn',
1821 $column,
1822 '1223',
1823 null,
1825 'a',
1826 'b',
1827 'c',
1831 '/',
1832 null,
1833 'foo',
1834 true,
1835 false,
1839 $this->assertEquals(
1840 "\na\n"
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>&nbsp;(Max: 64KiB)' . "\n",
1846 $result
1849 // case 5
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(
1860 $this->insertEdit,
1861 InsertEdit::class,
1862 'getBinaryAndBlobColumn',
1864 $column,
1865 '1223',
1866 null,
1868 'a',
1869 'b',
1870 'c',
1874 '/',
1875 null,
1876 'foo',
1877 true,
1878 false,
1882 $this->assertEquals(
1883 "\na\n"
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">',
1888 $result
1891 // case 6
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(
1903 $this->insertEdit,
1904 InsertEdit::class,
1905 'getBinaryAndBlobColumn',
1907 $column,
1908 '1223',
1909 null,
1911 'a',
1912 'b',
1913 'c',
1917 '/',
1918 null,
1919 'foo',
1920 true,
1921 false,
1925 $this->assertEquals(
1926 "\na\n"
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">',
1930 $result
1935 * Test for getHtmlInput
1937 public function testGetHTMLinput(): void
1939 $GLOBALS['cfg']['ShowFunctionFields'] = true;
1940 $column = [];
1941 $column['pma_type'] = 'date';
1942 $column['True_Type'] = 'date';
1943 $result = $this->callFunction(
1944 $this->insertEdit,
1945 InsertEdit::class,
1946 'getHtmlInput',
1948 $column,
1949 'a',
1950 'b',
1952 'c',
1956 'DATE',
1957 false,
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">',
1964 $result
1967 // case 2 datetime
1968 $column['pma_type'] = 'datetime';
1969 $column['True_Type'] = 'datetime';
1970 $result = $this->callFunction(
1971 $this->insertEdit,
1972 InsertEdit::class,
1973 'getHtmlInput',
1975 $column,
1976 'a',
1977 'b',
1979 'c',
1983 'DATE',
1984 false,
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">',
1990 $result
1993 // case 3 timestamp
1994 $column['pma_type'] = 'timestamp';
1995 $column['True_Type'] = 'timestamp';
1996 $result = $this->callFunction(
1997 $this->insertEdit,
1998 InsertEdit::class,
1999 'getHtmlInput',
2001 $column,
2002 'a',
2003 'b',
2005 'c',
2009 'DATE',
2010 false,
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">',
2016 $result
2021 * Test for getMaxUploadSize
2023 public function testGetMaxUploadSize(): void
2025 $GLOBALS['max_upload_size'] = 257;
2026 $column = [];
2027 $column['pma_type'] = 'tinyblob';
2028 $result = $this->callFunction(
2029 $this->insertEdit,
2030 InsertEdit::class,
2031 'getMaxUploadSize',
2033 $column,
2034 256,
2038 $this->assertEquals(
2040 "(Max: 256B)\n",
2041 256,
2043 $result
2046 // case 2
2047 $GLOBALS['max_upload_size'] = 250;
2048 $column['pma_type'] = 'tinyblob';
2049 $result = $this->callFunction(
2050 $this->insertEdit,
2051 InsertEdit::class,
2052 'getMaxUploadSize',
2054 $column,
2059 $this->assertEquals(
2061 "(Max: 250B)\n",
2062 250,
2064 $result
2069 * Test for getValueColumnForOtherDatatypes
2071 public function testGetValueColumnForOtherDatatypes(): void
2073 $column = [];
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(
2091 $this->insertEdit,
2092 InsertEdit::class,
2093 'getValueColumnForOtherDatatypes',
2095 $column,
2096 'defchar',
2097 'a',
2098 'b',
2099 'c',
2101 '&lt;',
2104 '/',
2105 '&lt;',
2106 "foo\nbar",
2107 $extracted_columnspec,
2108 false,
2112 $this->assertEquals(
2113 "a\n\na\n"
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 . '&lt;</textarea>',
2118 $result
2121 // case 2: (else)
2122 $column['is_char'] = false;
2123 $column['Extra'] = 'auto_increment';
2124 $column['pma_type'] = 'timestamp';
2125 $column['True_Type'] = 'timestamp';
2126 $result = $this->callFunction(
2127 $this->insertEdit,
2128 InsertEdit::class,
2129 'getValueColumnForOtherDatatypes',
2131 $column,
2132 'defchar',
2133 'a',
2134 'b',
2135 'c',
2137 '&lt;',
2140 '/',
2141 '&lt;',
2142 "foo\nbar",
2143 $extracted_columnspec,
2144 false,
2148 $this->assertEquals(
2149 "a\n"
2150 . '<input type="text" name="fieldsb" value="&lt;" 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">',
2154 $result
2157 // case 3: (else -> datetime)
2158 $column['pma_type'] = 'datetime';
2159 $result = $this->callFunction(
2160 $this->insertEdit,
2161 InsertEdit::class,
2162 'getValueColumnForOtherDatatypes',
2164 $column,
2165 'defchar',
2166 'a',
2167 'b',
2168 'c',
2170 '&lt;',
2173 '/',
2174 '&lt;',
2175 "foo\nbar",
2176 $extracted_columnspec,
2177 false,
2181 $this->assertStringContainsString(
2182 '<input type="hidden" name="fields_typeb" value="datetime">',
2183 $result
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(
2201 $this->insertEdit,
2202 InsertEdit::class,
2203 'getColumnSize',
2205 $column,
2206 $extracted_columnspec,
2211 $this->assertEquals(
2212 'textarea',
2213 $GLOBALS['cfg']['CharEditing']
2216 // case 2
2217 $column['is_char'] = false;
2218 $column['len'] = 20;
2219 $this->assertEquals(
2221 $this->callFunction(
2222 $this->insertEdit,
2223 InsertEdit::class,
2224 'getColumnSize',
2226 $column,
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">'
2243 . '</span></a>',
2244 $this->callFunction(
2245 $this->insertEdit,
2246 InsertEdit::class,
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(
2266 'tbl',
2267 'db',
2268 $where_clause_array,
2269 'localhost'
2272 $this->assertStringContainsString(
2273 '<form id="continueForm" method="post" action="' . Url::getFromRoute('/table/replace')
2274 . '" name="continueForm">',
2275 $result
2278 $this->assertStringContainsString(
2279 '<input type="hidden" name="db" value="db">',
2280 $result
2283 $this->assertStringContainsString(
2284 '<input type="hidden" name="table" value="tbl">',
2285 $result
2288 $this->assertStringContainsString(
2289 '<input type="hidden" name="goto" value="index.php">',
2290 $result
2293 $this->assertStringContainsString(
2294 '<input type="hidden" name="err_url" value="localhost">',
2295 $result
2298 $this->assertStringContainsString(
2299 '<input type="hidden" name="sql_query" value="SELECT 1">',
2300 $result
2303 $this->assertStringContainsString(
2304 '<input type="hidden" name="where_clause[0]" value="a&lt;b">',
2305 $result
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">',
2319 $result
2322 $this->assertStringContainsString(
2323 '<select name="after_insert"',
2324 $result
2327 $this->assertStringContainsString(
2328 '<input type="submit" class="btn btn-primary control_at_footer" value="Go" '
2329 . 'tabindex="11" id="buttonYes"',
2330 $result
2335 * Test for getSubmitTypeDropDown
2337 public function testGetSubmitTypeDropDown(): void
2339 $result = $this->callFunction(
2340 $this->insertEdit,
2341 InsertEdit::class,
2342 'getSubmitTypeDropDown',
2350 $this->assertStringContainsString(
2351 '<select name="submit_type" class="control_at_footer" tabindex="5">',
2352 $result
2355 $this->assertStringContainsString(
2356 '<option value="save">',
2357 $result
2362 * Test for getAfterInsertDropDown
2364 public function testGetAfterInsertDropDown(): void
2366 $result = $this->callFunction(
2367 $this->insertEdit,
2368 InsertEdit::class,
2369 'getAfterInsertDropDown',
2371 '`t`.`f` = 2',
2372 'new_insert',
2373 true,
2377 $this->assertStringContainsString(
2378 '<option value="new_insert" selected="selected">',
2379 $result
2382 $this->assertStringContainsString(
2383 '<option value="same_insert"',
2384 $result
2387 $this->assertStringContainsString(
2388 '<option value="edit_next" >',
2389 $result
2394 * Test for getSubmitAndResetButtonForActionsPanel
2396 public function testGetSubmitAndResetButtonForActionsPanel(): void
2398 $GLOBALS['cfg']['ShowHint'] = false;
2399 $result = $this->callFunction(
2400 $this->insertEdit,
2401 InsertEdit::class,
2402 'getSubmitAndResetButtonForActionsPanel',
2409 $this->assertStringContainsString(
2410 '<input type="submit" class="btn btn-primary control_at_footer" value="Go" '
2411 . 'tabindex="9" id="buttonYes">',
2412 $result
2415 $this->assertStringContainsString(
2416 '<input type="button" class="btn btn-secondary preview_sql" value="Preview SQL" '
2417 . 'tabindex="7">',
2418 $result
2421 $this->assertStringContainsString(
2422 '<input type="reset" class="btn btn-secondary control_at_footer" value="Reset" '
2423 . 'tabindex="8">',
2424 $result
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(
2439 $this->insertEdit,
2440 InsertEdit::class,
2441 'getHeadAndFootOfInsertRowTable',
2442 [$url_params]
2445 $this->assertStringContainsString(
2446 'index.php?route=/table/change',
2447 $result
2450 $this->assertStringContainsString(
2451 'ShowFunctionFields=1&amp;ShowFieldTypesInDataEditView=0',
2452 $result
2455 $this->assertStringContainsString(
2456 'ShowFunctionFields=0&amp;ShowFieldTypesInDataEditView=1',
2457 $result
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(
2474 $this->insertEdit,
2475 InsertEdit::class,
2476 'getSpecialCharsAndBackupFieldForExistingRow',
2478 $current_row,
2479 $column,
2481 false,
2483 'a',
2484 false,
2488 $this->assertEquals(
2490 true,
2491 null,
2492 null,
2493 null,
2494 '<input type="hidden" name="fields_preva" value="">',
2496 $result
2499 // Case 2 (bit)
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(
2507 $this->insertEdit,
2508 InsertEdit::class,
2509 'getSpecialCharsAndBackupFieldForExistingRow',
2511 $current_row,
2512 $column,
2513 $extracted_columnspec,
2514 false,
2516 'a',
2517 false,
2521 $this->assertEquals(
2523 false,
2525 '00000000000001111011',
2526 null,
2527 '<input type="hidden" name="fields_preva" value="123">',
2529 $result
2532 $current_row['f'] = 'abcd';
2533 $result = $this->callFunction(
2534 $this->insertEdit,
2535 InsertEdit::class,
2536 'getSpecialCharsAndBackupFieldForExistingRow',
2538 $current_row,
2539 $column,
2540 $extracted_columnspec,
2541 false,
2543 'a',
2544 true,
2548 $this->assertEquals(
2550 false,
2552 'abcd',
2553 null,
2554 '<input type="hidden" name="fields_preva" value="abcd">',
2556 $result
2559 // Case 3 (bit)
2560 $dbi = $this->getMockBuilder(DatabaseInterface::class)
2561 ->disableOriginalConstructor()
2562 ->getMock();
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(
2572 $this->insertEdit,
2573 InsertEdit::class,
2574 'getSpecialCharsAndBackupFieldForExistingRow',
2576 $current_row,
2577 $column,
2578 $extracted_columnspec,
2579 false,
2580 ['int'],
2581 'a',
2582 false,
2586 $this->assertEquals(
2588 false,
2590 "'',",
2591 null,
2592 '<input type="hidden" name="fields_preva" value="\'\',">',
2594 $result
2597 // Case 4 (else)
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(
2607 $this->insertEdit,
2608 InsertEdit::class,
2609 'getSpecialCharsAndBackupFieldForExistingRow',
2611 $current_row,
2612 $column,
2613 $extracted_columnspec,
2614 false,
2615 ['int'],
2616 'a',
2617 false,
2621 $this->assertEquals(
2623 false,
2624 '3131303031',
2625 '3131303031',
2626 '3131303031',
2627 '<input type="hidden" name="fields_preva" value="3131303031">',
2629 $result
2632 // Case 5
2633 $current_row['f'] = "11001\x00";
2635 $result = $this->callFunction(
2636 $this->insertEdit,
2637 InsertEdit::class,
2638 'getSpecialCharsAndBackupFieldForExistingRow',
2640 $current_row,
2641 $column,
2642 $extracted_columnspec,
2643 false,
2644 ['int'],
2645 'a',
2646 false,
2650 $this->assertEquals(
2652 false,
2653 '313130303100',
2654 '313130303100',
2655 '313130303100',
2656 '<input type="hidden" name="fields_preva" value="313130303100">',
2658 $result
2663 * Test for getSpecialCharsAndBackupFieldForInsertingMode
2665 public function testGetSpecialCharsAndBackupFieldForInsertingMode(): void
2667 $column = [];
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(
2675 $this->insertEdit,
2676 InsertEdit::class,
2677 'getSpecialCharsAndBackupFieldForInsertingMode',
2679 $column,
2680 false,
2684 $this->assertEquals(
2686 false,
2687 'b\'101\'',
2688 '101',
2690 '101',
2692 $result
2695 // case 2
2696 unset($column['Default']);
2697 $column['True_Type'] = 'char';
2699 $result = $this->callFunction(
2700 $this->insertEdit,
2701 InsertEdit::class,
2702 'getSpecialCharsAndBackupFieldForInsertingMode',
2704 $column,
2705 false,
2709 $this->assertEquals(
2711 true,
2717 $result
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(
2733 ['LIMIT 1'],
2734 true,
2735 true,
2736 false,
2738 $result
2741 // case 2 (else)
2742 unset($_POST['where_clause']);
2743 $_POST['fields']['multi_edit'] = [
2744 'a' => 'b',
2745 'c' => 'd',
2747 $result = $this->insertEdit->getParamsForUpdateOrInsert();
2749 $this->assertEquals(
2752 'a',
2753 'c',
2755 false,
2756 true,
2757 false,
2759 $result
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'])
2774 ->getMock();
2776 $scriptsMock->expects($this->exactly(2))
2777 ->method('addFile');
2779 $headerMock = $this->getMockBuilder(Header::class)
2780 ->disableOriginalConstructor()
2781 ->setMethods(['getScripts'])
2782 ->getMock();
2784 $headerMock->expects($this->once())
2785 ->method('getScripts')
2786 ->will($this->returnValue($scriptsMock));
2788 $responseMock = $this->getMockBuilder(Response::class)
2789 ->disableOriginalConstructor()
2790 ->setMethods(['getHeader'])
2791 ->getMock();
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];
2821 $row = ['1' => 1];
2822 $res = 'foobar';
2824 $dbi = $this->getMockBuilder(DatabaseInterface::class)
2825 ->disableOriginalConstructor()
2826 ->getMock();
2828 $dbi->expects($this->at(0))
2829 ->method('query')
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')
2835 ->with($res)
2836 ->will($this->returnValue($row));
2838 $dbi->expects($this->at(2))
2839 ->method('getFieldsMeta')
2840 ->with($res)
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(
2864 '/database/sql',
2865 $this->insertEdit->getGotoInclude('index')
2868 $GLOBALS['table'] = 'tbl';
2869 $this->assertEquals(
2870 '/table/sql',
2871 $this->insertEdit->getGotoInclude('index')
2874 $GLOBALS['goto'] = 'index.php?route=/database/sql';
2876 $this->assertEquals(
2877 '/database/sql',
2878 $this->insertEdit->getGotoInclude('index')
2881 $this->assertEquals(
2883 $GLOBALS['table']
2886 $_POST['after_insert'] = 'new_insert';
2887 $this->assertEquals(
2888 '/table/change',
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&amp;lang=en',
2901 $this->insertEdit->getErrorUrl([])
2904 $_POST['err_url'] = 'localhost';
2905 $this->assertEquals(
2906 'localhost',
2907 $this->insertEdit->getErrorUrl([])
2912 * Test for buildSqlQuery
2914 public function testBuildSqlQuery(): void
2916 $GLOBALS['db'] = 'db';
2917 $GLOBALS['table'] = 'table';
2918 $query_fields = [
2919 'a',
2920 'b',
2922 $value_sets = [
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
2943 $query = [
2944 'SELECT 1',
2945 'SELECT 2',
2947 $GLOBALS['sql_query'] = 'SELECT';
2948 $GLOBALS['cfg']['IgnoreMultiSubmitErrors'] = false;
2949 $_POST['submit_type'] = '';
2951 $dbi = $this->getMockBuilder(DatabaseInterface::class)
2952 ->disableOriginalConstructor()
2953 ->getMock();
2955 $dbi->expects($this->at(0))
2956 ->method('query')
2957 ->with('SELECT 1')
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))
2969 ->method('query')
2970 ->with('SELECT 2')
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'],
2988 $result[0]
2991 $this->assertEquals(
2993 $result[1]
2996 $this->assertInstanceOf(
2997 Message::class,
2998 $result[2][0]
3001 $msg = $result[2][0];
3002 $reflectionMsg = new ReflectionProperty(Message::class, 'params');
3003 $reflectionMsg->setAccessible(true);
3005 $this->assertEquals(
3006 [2],
3007 $reflectionMsg->getValue($msg)
3010 $this->assertEquals(
3012 $result[3]
3015 $this->assertEquals(
3016 ['err'],
3017 $result[4]
3020 $this->assertEquals(
3021 'SELECT',
3022 $result[5]
3027 * Test for executeSqlQuery
3029 public function testExecuteSqlQueryWithTryQuery(): void
3031 $query = [
3032 'SELECT 1',
3033 'SELECT 2',
3035 $GLOBALS['sql_query'] = 'SELECT';
3036 $GLOBALS['cfg']['IgnoreMultiSubmitErrors'] = true;
3037 $_POST['submit_type'] = '';
3039 $dbi = $this->getMockBuilder(DatabaseInterface::class)
3040 ->disableOriginalConstructor()
3041 ->getMock();
3043 $dbi->expects($this->at(0))
3044 ->method('tryQuery')
3045 ->with('SELECT 1')
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')
3058 ->with('SELECT 2')
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'],
3076 $result[0]
3079 $this->assertEquals(
3081 $result[1]
3084 $this->assertInstanceOf(
3085 Message::class,
3086 $result[2][0]
3089 $msg = $result[2][0];
3090 $reflectionMsg = new ReflectionProperty(Message::class, 'params');
3091 $reflectionMsg->setAccessible(true);
3093 $this->assertEquals(
3094 [2],
3095 $reflectionMsg->getValue($msg)
3098 $this->assertEquals(
3100 $result[3]
3103 $this->assertEquals(
3104 ['err'],
3105 $result[4]
3108 $this->assertEquals(
3109 'SELECT',
3110 $result[5]
3115 * Test for getWarningMessages
3117 public function testGetWarningMessages(): void
3119 $warnings = [
3121 'Level' => 1,
3122 'Code' => 42,
3123 'Message' => 'msg1',
3126 'Level' => 2,
3127 'Code' => 43,
3128 'Message' => 'msg2',
3132 $dbi = $this->getMockBuilder(DatabaseInterface::class)
3133 ->disableOriginalConstructor()
3134 ->getMock();
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(
3144 $this->insertEdit,
3145 InsertEdit::class,
3146 'getWarningMessages',
3150 $this->assertEquals(
3152 '1: #42 msg1',
3153 '2: #43 msg2',
3155 $result
3160 * Test for getDisplayValueForForeignTableColumn
3162 public function testGetDisplayValueForForeignTableColumn(): void
3164 $map = [];
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()
3171 ->getMock();
3173 $dbi->expects($this->once())
3174 ->method('tryQuery')
3175 ->with(
3176 'SELECT `TABLE_COMMENT` FROM `information_schema`.`TABLES` WHERE '
3177 . '`f`=1',
3178 DatabaseInterface::CONNECT_USER,
3179 DatabaseInterface::QUERY_STORE
3181 ->will($this->returnValue('r1'));
3183 $dbi->expects($this->once())
3184 ->method('numRows')
3185 ->with('r1')
3186 ->will($this->returnValue('2'));
3188 $dbi->expects($this->once())
3189 ->method('fetchRow')
3190 ->with('r1')
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';
3208 $map = [];
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&amp;db=information_schema&amp;table=TABLES&amp;pos=0&amp;'
3221 . 'sql_signature=' . $sqlSignature . '&amp;'
3222 . 'sql_query=SELECT+%2A+FROM+%60information_schema%60.%60TABLES%60+WHERE'
3223 . '+%60f%60%3D1&amp;lang=en" title="a&gt;">b&lt;</a>',
3224 $result
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&amp;db=information_schema&amp;table=TABLES&amp;pos=0&amp;'
3232 . 'sql_signature=' . $sqlSignature . '&amp;'
3233 . 'sql_query=SELECT+%2A+FROM+%60information_schema%60.%60TABLES%60+WHERE'
3234 . '+%60f%60%3D1&amp;lang=en" title="b&lt;">a&gt;</a>',
3235 $result
3240 * Test for transformEditedValues
3242 public function testTransformEditedValues(): void
3244 $_SESSION[' HMAC_secret '] = hash('sha1', 'test');
3245 $edited_values = [
3246 ['c' => 'cname'],
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(
3257 'db',
3258 'table',
3259 $transformation,
3260 $edited_values,
3261 'Text_Plain_PreApPend.php',
3262 'c',
3263 ['a' => 'b'],
3264 'transformation'
3267 $this->assertEquals(
3269 'a' => 'b',
3270 'transformations' => ['cnameoption ,, quoted'],
3272 $result
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,
3289 true,
3290 [1],
3291 [2],
3292 'foo',
3294 '0',
3298 $this->assertEquals(
3302 'foo',
3306 '`fld`',
3309 $result
3312 $result = $this->insertEdit->getQueryValuesForInsertAndUpdateInMultipleEdit(
3313 $multi_edit_columns_name,
3318 false,
3319 [1],
3320 [2],
3321 'foo',
3323 '0',
3324 ['a']
3327 $this->assertEquals(
3331 '`fld` = foo',
3333 [2],
3335 $result
3338 $result = $this->insertEdit->getQueryValuesForInsertAndUpdateInMultipleEdit(
3339 $multi_edit_columns_name,
3340 ['b'],
3341 "'`c`'",
3342 ['c'],
3344 false,
3345 [1],
3346 [2],
3347 'foo',
3349 '0',
3350 ['a']
3353 $this->assertEquals(
3355 [1],
3356 [2],
3358 $result
3361 $result = $this->insertEdit->getQueryValuesForInsertAndUpdateInMultipleEdit(
3362 $multi_edit_columns_name,
3363 ['b'],
3364 "'`c`'",
3365 ['c'],
3366 [3],
3367 false,
3368 [1],
3369 [2],
3370 'foo',
3376 $this->assertEquals(
3380 '`fld` = foo',
3382 [2],
3384 $result
3389 * Test for getCurrentValueAsAnArrayForMultipleEdit
3391 public function testGetCurrentValueAsAnArrayForMultipleEdit(): void
3393 $result = $this->insertEdit->getCurrentValueAsAnArrayForMultipleEdit(
3397 'currVal',
3404 $this->assertEquals('currVal', $result);
3406 // case 2
3407 $multi_edit_funcs = ['UUID'];
3409 $dbi = $this->getMockBuilder(DatabaseInterface::class)
3410 ->disableOriginalConstructor()
3411 ->getMock();
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(
3422 $multi_edit_funcs,
3425 'currVal',
3432 $this->assertEquals("'uuid1234'", $result);
3434 // case 3
3435 $multi_edit_funcs = ['AES_ENCRYPT'];
3436 $multi_edit_salt = [''];
3437 $result = $this->insertEdit->getCurrentValueAsAnArrayForMultipleEdit(
3438 $multi_edit_funcs,
3439 $multi_edit_salt,
3441 "'''",
3443 ['func'],
3444 ['func'],
3447 $this->assertEquals("AES_ENCRYPT(''','')", $result);
3449 // case 4
3450 $multi_edit_funcs = ['func'];
3451 $multi_edit_salt = [];
3452 $result = $this->insertEdit->getCurrentValueAsAnArrayForMultipleEdit(
3453 $multi_edit_funcs,
3454 $multi_edit_salt,
3456 "'''",
3458 ['func'],
3459 ['func'],
3462 $this->assertEquals("func(''')", $result);
3464 // case 5
3465 $result = $this->insertEdit->getCurrentValueAsAnArrayForMultipleEdit(
3466 $multi_edit_funcs,
3467 $multi_edit_salt,
3469 "''",
3471 ['func'],
3472 ['func'],
3475 $this->assertEquals('func()', $result);
3479 * Test for getCurrentValueForDifferentTypes
3481 public function testGetCurrentValueForDifferentTypes(): void
3483 $prow = [];
3484 $prow['a'] = '101';
3486 $dbi = $this->getMockBuilder(DatabaseInterface::class)
3487 ->disableOriginalConstructor()
3488 ->getMock();
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),
3498 "20\'12"
3501 $GLOBALS['dbi'] = $dbi;
3502 $this->insertEdit = new InsertEdit($GLOBALS['dbi']);
3504 $result = $this->insertEdit->getCurrentValueForDifferentTypes(
3505 '123',
3506 '0',
3514 true,
3515 true,
3516 '1',
3517 'table',
3521 $this->assertEquals(
3522 '123',
3523 $result
3526 // case 2
3527 $result = $this->insertEdit->getCurrentValueForDifferentTypes(
3528 false,
3529 '0',
3530 ['test'],
3532 [1],
3537 true,
3538 true,
3539 '1',
3540 'table',
3544 $this->assertEquals(
3545 'NULL',
3546 $result
3549 // case 3
3550 $result = $this->insertEdit->getCurrentValueForDifferentTypes(
3551 false,
3552 '0',
3553 ['test'],
3560 true,
3561 true,
3562 '1',
3563 'table',
3567 $this->assertEquals(
3568 "''",
3569 $result
3572 // case 4
3573 $_POST['fields']['multi_edit'][0][0] = [];
3574 $result = $this->insertEdit->getCurrentValueForDifferentTypes(
3575 false,
3576 '0',
3577 ['set'],
3584 true,
3585 true,
3586 '1',
3587 'table',
3591 $this->assertEquals(
3592 "''",
3593 $result
3596 // case 5
3597 $result = $this->insertEdit->getCurrentValueForDifferentTypes(
3598 false,
3599 '0',
3600 ['protected'],
3604 ['a'],
3607 true,
3608 true,
3609 '1',
3610 'table',
3614 $this->assertEquals(
3615 '0x313031',
3616 $result
3619 // case 6
3620 $result = $this->insertEdit->getCurrentValueForDifferentTypes(
3621 false,
3622 '0',
3623 ['protected'],
3627 ['a'],
3630 true,
3631 true,
3632 '1',
3633 'table',
3637 $this->assertEquals(
3639 $result
3642 // case 7
3643 $result = $this->insertEdit->getCurrentValueForDifferentTypes(
3644 false,
3645 '0',
3646 ['bit'],
3647 '20\'12',
3650 ['a'],
3653 true,
3654 true,
3655 '1',
3656 'table',
3660 $this->assertEquals(
3661 "b'00010'",
3662 $result
3665 // case 7
3666 $result = $this->insertEdit->getCurrentValueForDifferentTypes(
3667 false,
3668 '0',
3669 ['date'],
3670 '20\'12',
3673 ['a'],
3676 true,
3677 true,
3678 '1',
3679 'table',
3683 $this->assertEquals(
3684 "'20\\'12'",
3685 $result
3688 // case 8
3689 $_POST['fields']['multi_edit'][0][0] = [];
3690 $result = $this->insertEdit->getCurrentValueForDifferentTypes(
3691 false,
3692 '0',
3693 ['set'],
3698 [1],
3700 true,
3701 true,
3702 '1',
3703 'table',
3707 $this->assertEquals(
3708 'NULL',
3709 $result
3712 // case 9
3713 $result = $this->insertEdit->getCurrentValueForDifferentTypes(
3714 false,
3715 '0',
3716 ['protected'],
3720 ['a'],
3722 [1],
3723 true,
3724 true,
3725 '1',
3726 'table',
3730 $this->assertEquals(
3731 "''",
3732 $result
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()
3748 ->getMock();
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';
3773 $meta->flags = '';
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';
3791 $meta->flags = '';
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(
3807 'db',
3808 'table',
3809 'a',
3810 $extra_data
3813 $this->assertFalse($extra_data['isNeedToRecheck']);
3815 $this->insertEdit->verifyWhetherValueCanBeTruncatedAndAppendExtraData(
3816 'db',
3817 'table',
3818 'a',
3819 $extra_data
3822 $this->assertEquals('123', $extra_data['truncatableFieldValue']);
3823 $this->assertTrue($extra_data['isNeedToRecheck']);
3825 $this->insertEdit->verifyWhetherValueCanBeTruncatedAndAppendExtraData(
3826 'db',
3827 'table',
3828 'a',
3829 $extra_data
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()
3846 ->getMock();
3848 $dbi->expects($this->at(0))
3849 ->method('selectDb')
3850 ->with('db');
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(
3864 'b',
3865 'd',
3867 $result
3872 * Test for determineInsertOrEdit
3874 public function testDetermineInsertOrEdit(): void
3876 $dbi = $this->getMockBuilder(DatabaseInterface::class)
3877 ->disableOriginalConstructor()
3878 ->getMock();
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'])
3893 ->getMock();
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(
3906 false,
3907 null,
3908 [1],
3909 null,
3910 [null],
3911 [null],
3912 false,
3913 'edit_next',
3915 $result
3918 // case 2
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(
3929 true,
3930 null,
3932 null,
3933 null,
3935 false,
3936 false,
3938 false,
3939 'edit_next',
3941 $result
3946 * Test for getCommentsMap
3948 public function testGetCommentsMap(): void
3950 $GLOBALS['cfg']['ShowPropertyComments'] = false;
3952 $dbi = $this->getMockBuilder(DatabaseInterface::class)
3953 ->disableOriginalConstructor()
3954 ->getMock();
3956 $dbi->expects($this->once())
3957 ->method('getColumns')
3958 ->with('db', 'table', null, true)
3959 ->will(
3960 $this->returnValue(
3963 'Comment' => 'b',
3964 'Field' => 'd',
3970 $dbi->expects($this->any())
3971 ->method('getTable')
3972 ->will(
3973 $this->returnValue(
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(
3989 ['d' => 'b'],
3990 $this->insertEdit->getCommentsMap('db', 'table')
3995 * Test for getUrlParameters
3997 public function testGetUrlParameters(): void
3999 global $goto;
4001 $_POST['sql_query'] = 'SELECT';
4002 $goto = 'tbl_sql.php';
4004 $this->assertEquals(
4006 'db' => 'foo',
4007 'sql_query' => 'SELECT',
4008 'table' => 'bar',
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');
4040 $o_rows = 0;
4041 $tabindex = 0;
4042 $GLOBALS['plugin_scripts'] = [];
4043 $table_columns = [
4045 'Field' => 'col',
4046 'Type' => 'varchar(20)',
4047 'Null' => 'Yes',
4048 'Privileges' => 'insert,update,select',
4051 $repopulate = [md5('col') => 'val'];
4052 $column_mime = [
4053 'input_transformation' => 'Input/Image_JPEG_Upload.php',
4054 'input_transformation_options' => '150',
4057 // Test w/ input transformation
4058 $actual = $this->callFunction(
4059 $this->insertEdit,
4060 InsertEdit::class,
4061 'getHtmlForInsertEditFormColumn',
4063 $table_columns,
4066 false,
4071 false,
4073 &$o_rows,
4074 &$tabindex,
4076 false,
4081 'table',
4082 'db',
4087 $repopulate,
4088 $column_mime,
4093 $this->assertStringContainsString(
4094 'col',
4095 $actual
4097 $this->assertStringContainsString(
4098 '<option>AES_ENCRYPT</option>',
4099 $actual
4101 $this->assertStringContainsString(
4102 '<span class="column_type" dir="ltr">varchar(20)</span>',
4103 $actual
4105 $this->assertStringContainsString(
4106 '<tr class="noclick">',
4107 $actual
4109 $this->assertStringContainsString(
4110 '<span class="default_value hide">',
4111 $actual
4113 $this->assertStringContainsString(
4114 '<img src="" width="150" height="100" '
4115 . 'alt="Image preview here">',
4116 $actual
4118 $this->assertStringContainsString(
4119 '<input type="file" '
4120 . 'name="fields_upload[d89e2ddb530bb8953b290ab0793aecb0]" '
4121 . 'accept="image/*" '
4122 . 'class="image-upload"'
4123 . '>',
4124 $actual
4127 // Test w/o input_transformation
4128 $table_columns = [
4130 'Field' => 'qwerty',
4131 'Type' => 'datetime',
4132 'Null' => 'Yes',
4133 'Key' => '',
4134 'Extra' => '',
4135 'Default' => null,
4136 'Privileges' => 'insert,update,select',
4139 $repopulate = [md5('qwerty') => '12-10-14'];
4140 $actual = $this->callFunction(
4141 $this->insertEdit,
4142 InsertEdit::class,
4143 'getHtmlForInsertEditFormColumn',
4145 $table_columns,
4148 false,
4153 true,
4155 &$o_rows,
4156 &$tabindex,
4158 false,
4163 'table',
4164 'db',
4169 $repopulate,
4174 $this->assertStringContainsString(
4175 'qwerty',
4176 $actual
4178 $this->assertStringContainsString(
4179 '<option>UUID</option>',
4180 $actual
4182 $this->assertStringContainsString(
4183 '<span class="column_type" dir="ltr">datetime</span>',
4184 $actual
4186 $this->assertStringContainsString(
4187 '<input type="text" '
4188 . 'name="fields[d8578edf8458ce06fbc5bb76a58c5ca4]" '
4189 . 'value="12-10-14.000000"',
4190 $actual
4195 * Test for getHtmlForInsertEditRow
4197 public function testGetHtmlForInsertEditRow(): void
4199 $o_rows = 0;
4200 $tabindex = 0;
4201 $GLOBALS['plugin_scripts'] = [];
4202 $GLOBALS['cfg']['LongtextDoubleTextarea'] = true;
4203 $GLOBALS['cfg']['CharEditing'] = true;
4204 $table_columns = [
4206 'Field' => 'test',
4207 'Extra' => '',
4208 'Type' => 'longtext',
4209 'Null' => 'Yes',
4210 'pma_type' => 'longtext',
4211 'True_Type' => 'longtext',
4212 'Privileges' => 'select,insert,update,references',
4215 $actual = $this->insertEdit->getHtmlForInsertEditRow(
4217 $table_columns,
4219 false,
4224 false,
4226 $o_rows,
4227 $tabindex,
4229 false,
4234 'table',
4235 'db',
4240 ['wc']
4242 $this->assertStringContainsString(
4243 'test',
4244 $actual
4246 $this->assertStringContainsString(
4247 '<th>Column</th>',
4248 $actual
4250 $this->assertStringContainsString(
4251 '<a',
4252 $actual
4254 $this->assertStringContainsString(
4255 '<th class="fillPage">Value</th>',
4256 $actual
4258 $this->assertStringContainsString(
4259 '<span class="column_type" dir="ltr">longtext</span>',
4260 $actual
4262 $this->assertStringContainsString(
4263 '<textarea name="fields[098f6bcd4621d373cade4e832627b4f6]"',
4264 $actual
4269 * Test for getHtmlForInsertEditRow based on the column privilges
4271 public function testGetHtmlForInsertEditRowBasedOnColumnPrivileges(): void
4273 $o_rows = 0;
4274 $tabindex = 0;
4275 $GLOBALS['plugin_scripts'] = [];
4276 $GLOBALS['cfg']['LongtextDoubleTextarea'] = true;
4277 $GLOBALS['cfg']['CharEditing'] = true;
4279 // edit
4280 $table_columns = [
4282 'Field' => 'foo',
4283 'Type' => 'longtext',
4284 'Extra' => '',
4285 'Null' => 'Yes',
4286 'pma_type' => 'longtext',
4287 'True_Type' => 'longtext',
4288 'Privileges' => 'select,insert,update,references',
4291 'Field' => 'bar',
4292 'Type' => 'longtext',
4293 'Extra' => '',
4294 'Null' => 'Yes',
4295 'pma_type' => 'longtext',
4296 'True_Type' => 'longtext',
4297 'Privileges' => 'select,insert,references',
4300 $actual = $this->insertEdit->getHtmlForInsertEditRow(
4302 $table_columns,
4304 false,
4309 false,
4311 $o_rows,
4312 $tabindex,
4314 false,
4319 'table',
4320 'db',
4325 ['wc']
4327 $this->assertStringContainsString(
4328 'foo',
4329 $actual
4331 $this->assertStringNotContainsString(
4332 'bar',
4333 $actual
4336 // insert
4337 $table_columns = [
4339 'Field' => 'foo',
4340 'Type' => 'longtext',
4341 'Extra' => '',
4342 'Null' => 'Yes',
4343 'Key' => '',
4344 'pma_type' => 'longtext',
4345 'True_Type' => 'longtext',
4346 'Privileges' => 'select,insert,update,references',
4349 'Field' => 'bar',
4350 'Type' => 'longtext',
4351 'Extra' => '',
4352 'Null' => 'Yes',
4353 'Key' => '',
4354 'pma_type' => 'longtext',
4355 'True_Type' => 'longtext',
4356 'Privileges' => 'select,update,references',
4359 $actual = $this->insertEdit->getHtmlForInsertEditRow(
4361 $table_columns,
4363 false,
4368 true,
4370 $o_rows,
4371 $tabindex,
4373 false,
4378 'table',
4379 'db',
4384 ['wc']
4386 $this->assertStringContainsString(
4387 'foo',
4388 $actual
4390 $this->assertStringContainsString(
4391 '<textarea name="fields[37b51d194a7513e45b56f6524f2d51f2]"',
4392 $actual