3 declare(strict_types
=1);
5 namespace PhpMyAdmin\Tests\ConfigStorage
;
7 use PhpMyAdmin\ConfigStorage\Relation
;
8 use PhpMyAdmin\ConfigStorage\RelationParameters
;
9 use PhpMyAdmin\DatabaseInterface
;
10 use PhpMyAdmin\Tests\AbstractTestCase
;
15 * @covers \PhpMyAdmin\ConfigStorage\Relation
18 class RelationTest
extends AbstractTestCase
24 * Sets up the fixture, for example, opens a network connection.
25 * This method is called before a test is executed.
27 protected function setUp(): void
31 $GLOBALS['server'] = 1;
32 $GLOBALS['db'] = 'db';
33 $GLOBALS['cfg']['Server']['user'] = 'root';
34 $GLOBALS['cfg']['Server']['pmadb'] = 'phpmyadmin';
35 $GLOBALS['cfg']['Server']['DisableIS'] = false;
36 $GLOBALS['cfg']['ZeroConf'] = true;
37 $GLOBALS['cfg']['ServerDefault'] = 0;
38 $_SESSION['relation'] = [];
40 $this->relation
= new Relation($GLOBALS['dbi']);
44 * Test for queryAsControlUser
46 public function testPMAQueryAsControlUser(): void
48 $dbi = $this->getMockBuilder(DatabaseInterface
::class)
49 ->disableOriginalConstructor()
52 $dbi->expects($this->once())
54 ->will($this->returnValue('executeResult1'));
56 $dbi->expects($this->once())
58 ->will($this->returnValue('executeResult2'));
60 $GLOBALS['dbi'] = $dbi;
61 $this->relation
->dbi
= $GLOBALS['dbi'];
63 $sql = 'insert into PMA_bookmark A,B values(1, 2)';
66 $this->relation
->queryAsControlUser($sql)
70 $this->relation
->queryAsControlUser($sql, false)
75 * Test for getDisplayField
77 public function testPMAGetDisplayField(): void
79 $this->dummyDbi
->addSelectDb('phpmyadmin');
80 $db = 'information_schema';
81 $table = 'CHARACTER_SETS';
84 $this->relation
->getDisplayField($db, $table)
86 $this->assertAllSelectsConsumed();
88 $db = 'information_schema';
92 $this->relation
->getDisplayField($db, $table)
95 $db = 'information_schema';
98 $this->relation
->getDisplayField($db, $table)
103 * Test for getComments
105 public function testPMAGetComments(): void
107 $GLOBALS['cfg']['ServerDefault'] = 0;
109 $dbi = $this->getMockBuilder(DatabaseInterface
::class)
110 ->disableOriginalConstructor()
113 $getColumnsResult = [
117 'Comment' => 'Comment1',
122 'Comment' => 'Comment1',
125 $dbi->expects($this->any())->method('getColumns')
126 ->will($this->returnValue($getColumnsResult));
128 $GLOBALS['dbi'] = $dbi;
129 $this->relation
->dbi
= $GLOBALS['dbi'];
131 $db = 'information_schema';
134 $this->relation
->getComments($db)
137 $db = 'information_schema';
141 'field1' => 'Comment1',
142 'field2' => 'Comment1',
144 $this->relation
->getComments($db, $table)
149 * Test for tryUpgradeTransformations
151 public function testPMATryUpgradeTransformations(): void
153 $dbi = $this->getMockBuilder(DatabaseInterface
::class)
154 ->disableOriginalConstructor()
156 $dbi->expects($this->any())
158 ->will($this->returnValue(true));
159 $dbi->expects($this->any())
161 ->will($this->returnValue(0));
162 $dbi->expects($this->any())
164 ->will($this->onConsecutiveCalls(true, false));
165 $GLOBALS['dbi'] = $dbi;
166 $this->relation
->dbi
= $GLOBALS['dbi'];
168 $GLOBALS['cfg']['Server']['pmadb'] = 'pmadb';
169 $GLOBALS['cfg']['Server']['column_info'] = 'column_info';
172 $actual = $this->relation
->tryUpgradeTransformations();
173 $this->assertFalse($actual);
176 $actual = $this->relation
->tryUpgradeTransformations();
177 $this->assertTrue($actual);
180 public function testSearchColumnInForeignersError(): void
182 $this->assertFalse($this->relation
->searchColumnInForeigners([], 'id'));
186 * Test for searchColumnInForeigners
188 public function testPMASearchColumnInForeigners(): void
192 'master_field' => 'value',
193 'foreign_db' => 'GSoC14',
194 'foreign_table' => 'test',
195 'foreign_field' => 'value',
197 'foreign_keys_data' => [
199 'constraint' => 'ad',
204 'ref_db_name' => 'GSoC14',
205 'ref_table_name' => 'table_1',
206 'ref_index_list' => [
210 'on_delete' => 'CASCADE',
211 'on_update' => 'CASCADE',
216 $foreigner = $this->relation
->searchColumnInForeigners($foreigners, 'id');
218 $expected['foreign_field'] = 'id';
219 $expected['foreign_db'] = 'GSoC14';
220 $expected['foreign_table'] = 'table_1';
221 $expected['constraint'] = 'ad';
222 $expected['on_delete'] = 'CASCADE';
223 $expected['on_update'] = 'CASCADE';
225 $this->assertEquals($expected, $foreigner);
228 public function testFixPmaTablesNothingWorks(): void
230 parent
::setGlobalDbi();
232 $this->relation
= new Relation($this->dbi
);
234 $this->dummyDbi
->removeDefaultResults();
235 $this->dummyDbi
->addResult('SHOW TABLES FROM `db_pma`;', false);
237 $this->relation
->fixPmaTables('db_pma', false);
238 $this->assertAllQueriesConsumed();
241 public function testFixPmaTablesNormal(): void
243 parent
::setGlobalDbi();
246 $GLOBALS['server'] = 1;
247 $GLOBALS['cfg']['Server']['user'] = '';
248 $GLOBALS['cfg']['Server']['pmadb'] = '';
249 $GLOBALS['cfg']['Server']['bookmarktable'] = '';
250 $GLOBALS['cfg']['Server']['relation'] = '';
251 $GLOBALS['cfg']['Server']['table_info'] = '';
252 $GLOBALS['cfg']['Server']['table_coords'] = '';
253 $GLOBALS['cfg']['Server']['column_info'] = '';
254 $GLOBALS['cfg']['Server']['pdf_pages'] = '';
255 $GLOBALS['cfg']['Server']['history'] = '';
256 $GLOBALS['cfg']['Server']['recent'] = '';
257 $GLOBALS['cfg']['Server']['favorite'] = '';
258 $GLOBALS['cfg']['Server']['table_uiprefs'] = '';
259 $GLOBALS['cfg']['Server']['tracking'] = '';
260 $GLOBALS['cfg']['Server']['userconfig'] = '';
261 $GLOBALS['cfg']['Server']['users'] = '';
262 $GLOBALS['cfg']['Server']['usergroups'] = '';
263 $GLOBALS['cfg']['Server']['navigationhiding'] = '';
264 $GLOBALS['cfg']['Server']['savedsearches'] = '';
265 $GLOBALS['cfg']['Server']['central_columns'] = '';
266 $GLOBALS['cfg']['Server']['designer_settings'] = '';
267 $GLOBALS['cfg']['Server']['export_templates'] = '';
269 $this->relation
= new Relation($this->dbi
);
271 $this->dummyDbi
->removeDefaultResults();
272 $this->dummyDbi
->addResult(
273 'SHOW TABLES FROM `db_pma`;',
280 $this->dummyDbi
->addResult(
281 'SHOW TABLES FROM `db_pma`',
288 $this->dummyDbi
->addResult(
289 'SELECT NULL FROM `pma__userconfig` LIMIT 0',
292 $this->dummyDbi
->addSelectDb('db_pma');
294 $_SESSION['relation'] = [];
296 $this->relation
->fixPmaTables('db_pma', false);
298 $this->assertArrayHasKey($GLOBALS['server'], $_SESSION['relation'], 'The cache is expected to be filled');
299 /** @psalm-suppress EmptyArrayAccess */
300 $this->assertIsArray($_SESSION['relation'][$GLOBALS['server']]);
302 $relationParameters = RelationParameters
::fromArray([
304 'userconfigwork' => true,
305 'userconfig' => 'pma__userconfig',
307 $this->assertSame($relationParameters->toArray(), $_SESSION['relation'][$GLOBALS['server']]);
309 $this->assertAllQueriesConsumed();
310 $this->assertAllSelectsConsumed();
313 public function testFixPmaTablesNormalFixTables(): void
315 parent
::setGlobalDbi();
318 $GLOBALS['server'] = 1;
319 $GLOBALS['cfg']['Server']['user'] = '';
320 $GLOBALS['cfg']['Server']['pmadb'] = '';
321 $GLOBALS['cfg']['Server']['bookmarktable'] = '';
322 $GLOBALS['cfg']['Server']['relation'] = '';
323 $GLOBALS['cfg']['Server']['table_info'] = '';
324 $GLOBALS['cfg']['Server']['table_coords'] = '';
325 $GLOBALS['cfg']['Server']['column_info'] = '';
326 $GLOBALS['cfg']['Server']['pdf_pages'] = '';
327 $GLOBALS['cfg']['Server']['history'] = '';
328 $GLOBALS['cfg']['Server']['recent'] = '';
329 $GLOBALS['cfg']['Server']['favorite'] = '';
330 $GLOBALS['cfg']['Server']['table_uiprefs'] = '';
331 $GLOBALS['cfg']['Server']['tracking'] = '';
332 $GLOBALS['cfg']['Server']['userconfig'] = '';
333 $GLOBALS['cfg']['Server']['users'] = '';
334 $GLOBALS['cfg']['Server']['usergroups'] = '';
335 $GLOBALS['cfg']['Server']['navigationhiding'] = '';
336 $GLOBALS['cfg']['Server']['savedsearches'] = '';
337 $GLOBALS['cfg']['Server']['central_columns'] = '';
338 $GLOBALS['cfg']['Server']['designer_settings'] = '';
339 $GLOBALS['cfg']['Server']['export_templates'] = '';
341 $this->relation
= new Relation($this->dbi
);
343 $this->dummyDbi
->removeDefaultResults();
344 $this->dummyDbi
->addResult(
345 'SHOW TABLES FROM `db_pma`;',
352 $this->dummyDbi
->addResult(
353 'SHOW TABLES FROM `db_pma`',
360 $this->dummyDbi
->addResult(
361 'SELECT NULL FROM `pma__userconfig` LIMIT 0',
364 $this->dummyDbi
->addSelectDb('db_pma');
365 $this->dummyDbi
->addSelectDb('db_pma');
367 $this->dummyDbi
->addResult(
368 '-- -------------------------------------------------------- -- --'
369 . ' Table structure for table `pma__bookmark` '
370 . '-- CREATE TABLE IF NOT EXISTS `pma__bookmark` ( '
371 . '`id` int(10) unsigned NOT NULL auto_increment,'
372 . ' `dbase` varchar(255) NOT NULL default \'\','
373 . ' `user` varchar(255) NOT NULL default \'\','
374 . ' `label` varchar(255) COLLATE utf8_general_ci NOT NULL default \'\','
375 . ' `query` text NOT NULL, PRIMARY KEY (`id`) )'
376 . ' COMMENT=\'Bookmarks\' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
379 $this->dummyDbi
->addResult(
380 '-- -------------------------------------------------------- -- --'
381 . ' Table structure for table `pma__relation` '
382 . '-- CREATE TABLE IF NOT EXISTS `pma__relation` ( '
383 . '`master_db` varchar(64) NOT NULL default \'\', `master_table` varchar(64) NOT NULL default \'\','
384 . ' `master_field` varchar(64) NOT NULL default \'\', `foreign_db` varchar(64) NOT NULL default \'\','
385 . ' `foreign_table` varchar(64) NOT NULL default \'\','
386 . ' `foreign_field` varchar(64) NOT NULL default \'\','
387 . ' PRIMARY KEY (`master_db`,`master_table`,`master_field`),'
388 . ' KEY `foreign_field` (`foreign_db`,`foreign_table`) ) COMMENT=\'Relation table\''
389 . ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
392 $this->dummyDbi
->addResult(
393 '-- -------------------------------------------------------- -- --'
394 . ' Table structure for table `pma__table_info`'
395 . ' -- CREATE TABLE IF NOT EXISTS `pma__table_info` ( '
396 . '`db_name` varchar(64) NOT NULL default \'\', `table_name` varchar(64) NOT NULL default \'\','
397 . ' `display_field` varchar(64) NOT NULL default \'\', PRIMARY KEY (`db_name`,`table_name`) )'
398 . ' COMMENT=\'Table information for phpMyAdmin\' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
402 $this->dummyDbi
->addResult(
403 '-- -------------------------------------------------------- -- --'
404 . ' Table structure for table `pma__table_coords`'
405 . ' -- CREATE TABLE IF NOT EXISTS `pma__table_coords` ( '
406 . '`db_name` varchar(64) NOT NULL default \'\', `table_name` varchar(64) NOT NULL default \'\','
407 . ' `pdf_page_number` int(11) NOT NULL default \'0\', `x` float unsigned NOT NULL default \'0\','
408 . ' `y` float unsigned NOT NULL default \'0\','
409 . ' PRIMARY KEY (`db_name`,`table_name`,`pdf_page_number`) )'
410 . ' COMMENT=\'Table coordinates for phpMyAdmin PDF output\''
411 . ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
414 $this->dummyDbi
->addResult(
415 '-- -------------------------------------------------------- -- --'
416 . ' Table structure for table `pma__pdf_pages`'
417 . ' -- CREATE TABLE IF NOT EXISTS `pma__pdf_pages` ( '
418 . '`db_name` varchar(64) NOT NULL default \'\', `page_nr` int(10) unsigned NOT NULL auto_increment,'
419 . ' `page_descr` varchar(50) COLLATE utf8_general_ci NOT NULL default \'\', PRIMARY KEY (`page_nr`),'
420 . ' KEY `db_name` (`db_name`) ) COMMENT=\'PDF relation pages for phpMyAdmin\''
421 . ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
424 $this->dummyDbi
->addResult(
425 '-- -------------------------------------------------------- -- --'
426 . ' Table structure for table `pma__column_info`'
427 . ' -- CREATE TABLE IF NOT EXISTS `pma__column_info` ( '
428 . '`id` int(5) unsigned NOT NULL auto_increment, `db_name` varchar(64) NOT NULL default \'\','
429 . ' `table_name` varchar(64) NOT NULL default \'\', `column_name` varchar(64) NOT NULL default \'\','
430 . ' `comment` varchar(255) COLLATE utf8_general_ci NOT NULL default \'\','
431 . ' `mimetype` varchar(255) COLLATE utf8_general_ci NOT NULL default \'\','
432 . ' `transformation` varchar(255) NOT NULL default \'\','
433 . ' `transformation_options` varchar(255) NOT NULL default \'\','
434 . ' `input_transformation` varchar(255) NOT NULL default \'\','
435 . ' `input_transformation_options` varchar(255) NOT NULL default \'\','
436 . ' PRIMARY KEY (`id`), UNIQUE KEY `db_name` (`db_name`,`table_name`,`column_name`) )'
437 . ' COMMENT=\'Column information for phpMyAdmin\' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
440 $this->dummyDbi
->addResult(
441 '-- -------------------------------------------------------- -- --'
442 . ' Table structure for table `pma__history` '
443 . '-- CREATE TABLE IF NOT EXISTS `pma__history` ( '
444 . '`id` bigint(20) unsigned NOT NULL auto_increment, `username` varchar(64) NOT NULL default \'\','
445 . ' `db` varchar(64) NOT NULL default \'\', `table` varchar(64) NOT NULL default \'\','
446 . ' `timevalue` timestamp NOT NULL default CURRENT_TIMESTAMP, `sqlquery` text NOT NULL,'
447 . ' PRIMARY KEY (`id`), KEY `username` (`username`,`db`,`table`,`timevalue`) )'
448 . ' COMMENT=\'SQL history for phpMyAdmin\' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
451 $this->dummyDbi
->addResult(
452 '-- -------------------------------------------------------- -- --'
453 . ' Table structure for table `pma__recent` '
454 . '-- CREATE TABLE IF NOT EXISTS `pma__recent` ( '
455 . '`username` varchar(64) NOT NULL, `tables` text NOT NULL, PRIMARY KEY (`username`) )'
456 . ' COMMENT=\'Recently accessed tables\' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
459 $this->dummyDbi
->addResult(
460 '-- -------------------------------------------------------- -- --'
461 . ' Table structure for table `pma__favorite` '
462 . '-- CREATE TABLE IF NOT EXISTS `pma__favorite` ( '
463 . '`username` varchar(64) NOT NULL, `tables` text NOT NULL, PRIMARY KEY (`username`) )'
464 . ' COMMENT=\'Favorite tables\' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
467 $this->dummyDbi
->addResult(
468 '-- -------------------------------------------------------- -- --'
469 . ' Table structure for table `pma__table_uiprefs`'
470 . ' -- CREATE TABLE IF NOT EXISTS `pma__table_uiprefs` ( '
471 . '`username` varchar(64) NOT NULL, `db_name` varchar(64) NOT NULL,'
472 . ' `table_name` varchar(64) NOT NULL, `prefs` text NOT NULL,'
473 . ' `last_update` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,'
474 . ' PRIMARY KEY (`username`,`db_name`,`table_name`) ) COMMENT=\'Tables\'\' UI preferences\''
475 . ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
478 $this->dummyDbi
->addResult(
479 '-- -------------------------------------------------------- -- --'
480 . ' Table structure for table `pma__tracking` '
481 . '-- CREATE TABLE IF NOT EXISTS `pma__tracking` ( '
482 . '`db_name` varchar(64) NOT NULL, `table_name` varchar(64) NOT NULL,'
483 . ' `version` int(10) unsigned NOT NULL, `date_created` datetime NOT NULL,'
484 . ' `date_updated` datetime NOT NULL, `schema_snapshot` text NOT NULL,'
485 . ' `schema_sql` text, `data_sql` longtext, `tracking`'
486 . ' set(\'UPDATE\',\'REPLACE\',\'INSERT\',\'DELETE\','
487 . '\'TRUNCATE\',\'CREATE DATABASE\',\'ALTER DATABASE\','
488 . '\'DROP DATABASE\',\'CREATE TABLE\',\'ALTER TABLE\','
489 . '\'RENAME TABLE\',\'DROP TABLE\',\'CREATE INDEX\','
490 . '\'DROP INDEX\',\'CREATE VIEW\',\'ALTER VIEW\',\'DROP VIEW\')'
491 . ' default NULL, `tracking_active` int(1) unsigned NOT NULL'
492 . ' default \'1\', PRIMARY KEY (`db_name`,`table_name`,`version`) )'
493 . ' COMMENT=\'Database changes tracking for phpMyAdmin\''
494 . ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
497 $this->dummyDbi
->addResult(
498 '-- -------------------------------------------------------- -- --'
499 . ' Table structure for table `pma__users` '
500 . '-- CREATE TABLE IF NOT EXISTS `pma__users` ( '
501 . '`username` varchar(64) NOT NULL, `usergroup` varchar(64) NOT NULL,'
502 . ' PRIMARY KEY (`username`,`usergroup`) )'
503 . ' COMMENT=\'Users and their assignments to user groups\''
504 . ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
507 $this->dummyDbi
->addResult(
508 '-- -------------------------------------------------------- -- --'
509 . ' Table structure for table `pma__usergroups`'
510 . ' -- CREATE TABLE IF NOT EXISTS `pma__usergroups` ( '
511 . '`usergroup` varchar(64) NOT NULL, `tab` varchar(64) NOT NULL,'
512 . ' `allowed` enum(\'Y\',\'N\') NOT NULL DEFAULT \'N\','
513 . ' PRIMARY KEY (`usergroup`,`tab`,`allowed`) )'
514 . ' COMMENT=\'User groups with configured menu items\''
515 . ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
518 $this->dummyDbi
->addResult(
519 '-- -------------------------------------------------------- -- --'
520 . ' Table structure for table `pma__navigationhiding`'
521 . ' -- CREATE TABLE IF NOT EXISTS `pma__navigationhiding` ( '
522 . '`username` varchar(64) NOT NULL, `item_name` varchar(64)'
523 . ' NOT NULL, `item_type` varchar(64) NOT NULL, `db_name` varchar(64) NOT NULL,'
524 . ' `table_name` varchar(64) NOT NULL,'
525 . ' PRIMARY KEY (`username`,`item_name`,`item_type`,`db_name`,`table_name`) )'
526 . ' COMMENT=\'Hidden items of navigation tree\' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
529 $this->dummyDbi
->addResult(
530 '-- -------------------------------------------------------- -- --'
531 . ' Table structure for table `pma__savedsearches`'
532 . ' -- CREATE TABLE IF NOT EXISTS `pma__savedsearches` ( '
533 . '`id` int(5) unsigned NOT NULL auto_increment, `username` varchar(64) NOT NULL default \'\','
534 . ' `db_name` varchar(64) NOT NULL default \'\', `search_name` varchar(64) NOT NULL default \'\','
535 . ' `search_data` text NOT NULL, PRIMARY KEY (`id`),'
536 . ' UNIQUE KEY `u_savedsearches_username_dbname` (`username`,`db_name`,`search_name`) )'
537 . ' COMMENT=\'Saved searches\' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
540 $this->dummyDbi
->addResult(
541 '-- -------------------------------------------------------- -- --'
542 . ' Table structure for table `pma__central_columns`'
543 . ' -- CREATE TABLE IF NOT EXISTS `pma__central_columns` ( '
544 . '`db_name` varchar(64) NOT NULL, `col_name` varchar(64) NOT NULL, `col_type` varchar(64) NOT NULL,'
545 . ' `col_length` text, `col_collation` varchar(64) NOT NULL, `col_isNull` boolean NOT NULL,'
546 . ' `col_extra` varchar(255) default \'\', `col_default` text,'
547 . ' PRIMARY KEY (`db_name`,`col_name`) )'
548 . ' COMMENT=\'Central list of columns\' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
551 $this->dummyDbi
->addResult(
552 '-- -------------------------------------------------------- -- --'
553 . ' Table structure for table `pma__designer_settings`'
554 . ' -- CREATE TABLE IF NOT EXISTS `pma__designer_settings` ( '
555 . '`username` varchar(64) NOT NULL, `settings_data` text NOT NULL,'
556 . ' PRIMARY KEY (`username`) )'
557 . ' COMMENT=\'Settings related to Designer\' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
560 $this->dummyDbi
->addResult(
561 '-- -------------------------------------------------------- -- --'
562 . ' Table structure for table `pma__export_templates`'
563 . ' -- CREATE TABLE IF NOT EXISTS `pma__export_templates` ( '
564 . '`id` int(5) unsigned NOT NULL AUTO_INCREMENT, `username` varchar(64) NOT NULL,'
565 . ' `export_type` varchar(10) NOT NULL, `template_name` varchar(64) NOT NULL,'
566 . ' `template_data` text NOT NULL, PRIMARY KEY (`id`),'
567 . ' UNIQUE KEY `u_user_type_template` (`username`,`export_type`,`template_name`) )'
568 . ' COMMENT=\'Saved export templates\' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
572 $this->assertSame('', $GLOBALS['cfg']['Server']['pmadb']);
574 $_SESSION['relation'] = [];
576 $this->relation
->fixPmaTables('db_pma', true);
577 $this->assertArrayNotHasKey('message', $GLOBALS);
578 $this->assertArrayHasKey($GLOBALS['server'], $_SESSION['relation'], 'The cache is expected to be filled');
579 /** @psalm-suppress EmptyArrayAccess */
580 $this->assertIsArray($_SESSION['relation'][$GLOBALS['server']]);
581 $this->assertSame('db_pma', $GLOBALS['cfg']['Server']['pmadb']);
583 $relationParameters = RelationParameters
::fromArray([
585 'userconfigwork' => true,
586 'userconfig' => 'pma__userconfig',
588 $this->assertSame($relationParameters->toArray(), $_SESSION['relation'][$GLOBALS['server']]);
590 $this->assertAllQueriesConsumed();
591 $this->assertAllSelectsConsumed();
594 public function testFixPmaTablesNormalFixTablesWithCustomOverride(): void
596 parent
::setGlobalDbi();
599 $GLOBALS['server'] = 1;
600 $GLOBALS['cfg']['Server']['user'] = '';
601 $GLOBALS['cfg']['Server']['pmadb'] = 'db_pma';
602 $GLOBALS['cfg']['Server']['bookmarktable'] = '';
603 $GLOBALS['cfg']['Server']['relation'] = 'custom_relation_pma';
604 $GLOBALS['cfg']['Server']['table_info'] = '';
605 $GLOBALS['cfg']['Server']['table_coords'] = '';
606 $GLOBALS['cfg']['Server']['column_info'] = '';
607 $GLOBALS['cfg']['Server']['pdf_pages'] = '';
608 $GLOBALS['cfg']['Server']['history'] = '';
609 $GLOBALS['cfg']['Server']['recent'] = '';
610 $GLOBALS['cfg']['Server']['favorite'] = '';
611 $GLOBALS['cfg']['Server']['table_uiprefs'] = '';
612 $GLOBALS['cfg']['Server']['tracking'] = '';
613 $GLOBALS['cfg']['Server']['userconfig'] = '';
614 $GLOBALS['cfg']['Server']['users'] = '';
615 $GLOBALS['cfg']['Server']['usergroups'] = '';
616 $GLOBALS['cfg']['Server']['navigationhiding'] = '';
617 $GLOBALS['cfg']['Server']['savedsearches'] = '';
618 $GLOBALS['cfg']['Server']['central_columns'] = '';
619 $GLOBALS['cfg']['Server']['designer_settings'] = '';
620 $GLOBALS['cfg']['Server']['export_templates'] = '';
622 $this->relation
= new Relation($this->dbi
);
624 $this->dummyDbi
->removeDefaultResults();
625 $this->dummyDbi
->addResult(
626 'SHOW TABLES FROM `db_pma`;',
629 // This is important as it tricks default existing table detection
630 // If the check does not consider the custom name it will skip the table
636 $this->dummyDbi
->addResult(
637 'SHOW TABLES FROM `db_pma`',
640 // This is important as it tricks default existing table detection
641 // If the check does not consider the custom name it will skip the table
647 $this->dummyDbi
->addResult(
648 'SELECT NULL FROM `pma__userconfig` LIMIT 0',
652 $this->dummyDbi
->addResult(
653 '-- -------------------------------------------------------- -- --'
654 . ' Table structure for table `pma__bookmark` '
655 . '-- CREATE TABLE IF NOT EXISTS `pma__bookmark` ( '
656 . '`id` int(10) unsigned NOT NULL auto_increment,'
657 . ' `dbase` varchar(255) NOT NULL default \'\','
658 . ' `user` varchar(255) NOT NULL default \'\','
659 . ' `label` varchar(255) COLLATE utf8_general_ci NOT NULL default \'\','
660 . ' `query` text NOT NULL, PRIMARY KEY (`id`) )'
661 . ' COMMENT=\'Bookmarks\' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
664 $this->dummyDbi
->addResult(
665 '-- -------------------------------------------------------- -- --'
666 . ' Table structure for table `custom_relation_pma` '
667 . '-- CREATE TABLE IF NOT EXISTS `custom_relation_pma` ( '
668 . '`master_db` varchar(64) NOT NULL default \'\', `master_table` varchar(64) NOT NULL default \'\','
669 . ' `master_field` varchar(64) NOT NULL default \'\', `foreign_db` varchar(64) NOT NULL default \'\','
670 . ' `foreign_table` varchar(64) NOT NULL default \'\','
671 . ' `foreign_field` varchar(64) NOT NULL default \'\','
672 . ' PRIMARY KEY (`master_db`,`master_table`,`master_field`),'
673 . ' KEY `foreign_field` (`foreign_db`,`foreign_table`) ) COMMENT=\'Relation table\''
674 . ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
677 $this->dummyDbi
->addResult(
678 '-- -------------------------------------------------------- -- --'
679 . ' Table structure for table `pma__table_info`'
680 . ' -- CREATE TABLE IF NOT EXISTS `pma__table_info` ( '
681 . '`db_name` varchar(64) NOT NULL default \'\', `table_name` varchar(64) NOT NULL default \'\','
682 . ' `display_field` varchar(64) NOT NULL default \'\', PRIMARY KEY (`db_name`,`table_name`) )'
683 . ' COMMENT=\'Table information for phpMyAdmin\' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
687 $this->dummyDbi
->addResult(
688 '-- -------------------------------------------------------- -- --'
689 . ' Table structure for table `pma__table_coords`'
690 . ' -- CREATE TABLE IF NOT EXISTS `pma__table_coords` ( '
691 . '`db_name` varchar(64) NOT NULL default \'\', `table_name` varchar(64) NOT NULL default \'\','
692 . ' `pdf_page_number` int(11) NOT NULL default \'0\', `x` float unsigned NOT NULL default \'0\','
693 . ' `y` float unsigned NOT NULL default \'0\','
694 . ' PRIMARY KEY (`db_name`,`table_name`,`pdf_page_number`) )'
695 . ' COMMENT=\'Table coordinates for phpMyAdmin PDF output\''
696 . ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
699 $this->dummyDbi
->addResult(
700 '-- -------------------------------------------------------- -- --'
701 . ' Table structure for table `pma__pdf_pages`'
702 . ' -- CREATE TABLE IF NOT EXISTS `pma__pdf_pages` ( '
703 . '`db_name` varchar(64) NOT NULL default \'\', `page_nr` int(10) unsigned NOT NULL auto_increment,'
704 . ' `page_descr` varchar(50) COLLATE utf8_general_ci NOT NULL default \'\', PRIMARY KEY (`page_nr`),'
705 . ' KEY `db_name` (`db_name`) ) COMMENT=\'PDF relation pages for phpMyAdmin\''
706 . ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
709 $this->dummyDbi
->addResult(
710 '-- -------------------------------------------------------- -- --'
711 . ' Table structure for table `pma__column_info`'
712 . ' -- CREATE TABLE IF NOT EXISTS `pma__column_info` ( '
713 . '`id` int(5) unsigned NOT NULL auto_increment, `db_name` varchar(64) NOT NULL default \'\','
714 . ' `table_name` varchar(64) NOT NULL default \'\', `column_name` varchar(64) NOT NULL default \'\','
715 . ' `comment` varchar(255) COLLATE utf8_general_ci NOT NULL default \'\','
716 . ' `mimetype` varchar(255) COLLATE utf8_general_ci NOT NULL default \'\','
717 . ' `transformation` varchar(255) NOT NULL default \'\','
718 . ' `transformation_options` varchar(255) NOT NULL default \'\','
719 . ' `input_transformation` varchar(255) NOT NULL default \'\','
720 . ' `input_transformation_options` varchar(255) NOT NULL default \'\','
721 . ' PRIMARY KEY (`id`), UNIQUE KEY `db_name` (`db_name`,`table_name`,`column_name`) )'
722 . ' COMMENT=\'Column information for phpMyAdmin\' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
725 $this->dummyDbi
->addResult(
726 '-- -------------------------------------------------------- -- --'
727 . ' Table structure for table `pma__history` '
728 . '-- CREATE TABLE IF NOT EXISTS `pma__history` ( '
729 . '`id` bigint(20) unsigned NOT NULL auto_increment, `username` varchar(64) NOT NULL default \'\','
730 . ' `db` varchar(64) NOT NULL default \'\', `table` varchar(64) NOT NULL default \'\','
731 . ' `timevalue` timestamp NOT NULL default CURRENT_TIMESTAMP, `sqlquery` text NOT NULL,'
732 . ' PRIMARY KEY (`id`), KEY `username` (`username`,`db`,`table`,`timevalue`) )'
733 . ' COMMENT=\'SQL history for phpMyAdmin\' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
736 $this->dummyDbi
->addResult(
737 '-- -------------------------------------------------------- -- --'
738 . ' Table structure for table `pma__recent` '
739 . '-- CREATE TABLE IF NOT EXISTS `pma__recent` ( '
740 . '`username` varchar(64) NOT NULL, `tables` text NOT NULL, PRIMARY KEY (`username`) )'
741 . ' COMMENT=\'Recently accessed tables\' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
744 $this->dummyDbi
->addResult(
745 '-- -------------------------------------------------------- -- --'
746 . ' Table structure for table `pma__favorite` '
747 . '-- CREATE TABLE IF NOT EXISTS `pma__favorite` ( '
748 . '`username` varchar(64) NOT NULL, `tables` text NOT NULL, PRIMARY KEY (`username`) )'
749 . ' COMMENT=\'Favorite tables\' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
752 $this->dummyDbi
->addResult(
753 '-- -------------------------------------------------------- -- --'
754 . ' Table structure for table `pma__table_uiprefs`'
755 . ' -- CREATE TABLE IF NOT EXISTS `pma__table_uiprefs` ( '
756 . '`username` varchar(64) NOT NULL, `db_name` varchar(64) NOT NULL,'
757 . ' `table_name` varchar(64) NOT NULL, `prefs` text NOT NULL,'
758 . ' `last_update` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,'
759 . ' PRIMARY KEY (`username`,`db_name`,`table_name`) ) COMMENT=\'Tables\'\' UI preferences\''
760 . ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
763 $this->dummyDbi
->addResult(
764 '-- -------------------------------------------------------- -- --'
765 . ' Table structure for table `pma__tracking` '
766 . '-- CREATE TABLE IF NOT EXISTS `pma__tracking` ( '
767 . '`db_name` varchar(64) NOT NULL, `table_name` varchar(64) NOT NULL,'
768 . ' `version` int(10) unsigned NOT NULL, `date_created` datetime NOT NULL,'
769 . ' `date_updated` datetime NOT NULL, `schema_snapshot` text NOT NULL,'
770 . ' `schema_sql` text, `data_sql` longtext, `tracking`'
771 . ' set(\'UPDATE\',\'REPLACE\',\'INSERT\',\'DELETE\','
772 . '\'TRUNCATE\',\'CREATE DATABASE\',\'ALTER DATABASE\','
773 . '\'DROP DATABASE\',\'CREATE TABLE\',\'ALTER TABLE\','
774 . '\'RENAME TABLE\',\'DROP TABLE\',\'CREATE INDEX\','
775 . '\'DROP INDEX\',\'CREATE VIEW\',\'ALTER VIEW\',\'DROP VIEW\')'
776 . ' default NULL, `tracking_active` int(1) unsigned NOT NULL'
777 . ' default \'1\', PRIMARY KEY (`db_name`,`table_name`,`version`) )'
778 . ' COMMENT=\'Database changes tracking for phpMyAdmin\''
779 . ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
782 $this->dummyDbi
->addResult(
783 '-- -------------------------------------------------------- -- --'
784 . ' Table structure for table `pma__users` '
785 . '-- CREATE TABLE IF NOT EXISTS `pma__users` ( '
786 . '`username` varchar(64) NOT NULL, `usergroup` varchar(64) NOT NULL,'
787 . ' PRIMARY KEY (`username`,`usergroup`) )'
788 . ' COMMENT=\'Users and their assignments to user groups\''
789 . ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
792 $this->dummyDbi
->addResult(
793 '-- -------------------------------------------------------- -- --'
794 . ' Table structure for table `pma__usergroups`'
795 . ' -- CREATE TABLE IF NOT EXISTS `pma__usergroups` ( '
796 . '`usergroup` varchar(64) NOT NULL, `tab` varchar(64) NOT NULL,'
797 . ' `allowed` enum(\'Y\',\'N\') NOT NULL DEFAULT \'N\','
798 . ' PRIMARY KEY (`usergroup`,`tab`,`allowed`) )'
799 . ' COMMENT=\'User groups with configured menu items\''
800 . ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
803 $this->dummyDbi
->addResult(
804 '-- -------------------------------------------------------- -- --'
805 . ' Table structure for table `pma__navigationhiding`'
806 . ' -- CREATE TABLE IF NOT EXISTS `pma__navigationhiding` ( '
807 . '`username` varchar(64) NOT NULL, `item_name` varchar(64)'
808 . ' NOT NULL, `item_type` varchar(64) NOT NULL, `db_name` varchar(64) NOT NULL,'
809 . ' `table_name` varchar(64) NOT NULL,'
810 . ' PRIMARY KEY (`username`,`item_name`,`item_type`,`db_name`,`table_name`) )'
811 . ' COMMENT=\'Hidden items of navigation tree\' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
814 $this->dummyDbi
->addResult(
815 '-- -------------------------------------------------------- -- --'
816 . ' Table structure for table `pma__savedsearches`'
817 . ' -- CREATE TABLE IF NOT EXISTS `pma__savedsearches` ( '
818 . '`id` int(5) unsigned NOT NULL auto_increment, `username` varchar(64) NOT NULL default \'\','
819 . ' `db_name` varchar(64) NOT NULL default \'\', `search_name` varchar(64) NOT NULL default \'\','
820 . ' `search_data` text NOT NULL, PRIMARY KEY (`id`),'
821 . ' UNIQUE KEY `u_savedsearches_username_dbname` (`username`,`db_name`,`search_name`) )'
822 . ' COMMENT=\'Saved searches\' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
825 $this->dummyDbi
->addResult(
826 '-- -------------------------------------------------------- -- --'
827 . ' Table structure for table `pma__central_columns`'
828 . ' -- CREATE TABLE IF NOT EXISTS `pma__central_columns` ( '
829 . '`db_name` varchar(64) NOT NULL, `col_name` varchar(64) NOT NULL, `col_type` varchar(64) NOT NULL,'
830 . ' `col_length` text, `col_collation` varchar(64) NOT NULL, `col_isNull` boolean NOT NULL,'
831 . ' `col_extra` varchar(255) default \'\', `col_default` text,'
832 . ' PRIMARY KEY (`db_name`,`col_name`) )'
833 . ' COMMENT=\'Central list of columns\' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
836 $this->dummyDbi
->addResult(
837 '-- -------------------------------------------------------- -- --'
838 . ' Table structure for table `pma__designer_settings`'
839 . ' -- CREATE TABLE IF NOT EXISTS `pma__designer_settings` ( '
840 . '`username` varchar(64) NOT NULL, `settings_data` text NOT NULL,'
841 . ' PRIMARY KEY (`username`) )'
842 . ' COMMENT=\'Settings related to Designer\' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
845 $this->dummyDbi
->addResult(
846 '-- -------------------------------------------------------- -- --'
847 . ' Table structure for table `pma__export_templates`'
848 . ' -- CREATE TABLE IF NOT EXISTS `pma__export_templates` ( '
849 . '`id` int(5) unsigned NOT NULL AUTO_INCREMENT, `username` varchar(64) NOT NULL,'
850 . ' `export_type` varchar(10) NOT NULL, `template_name` varchar(64) NOT NULL,'
851 . ' `template_data` text NOT NULL, PRIMARY KEY (`id`),'
852 . ' UNIQUE KEY `u_user_type_template` (`username`,`export_type`,`template_name`) )'
853 . ' COMMENT=\'Saved export templates\' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
857 $this->assertSame('db_pma', $GLOBALS['cfg']['Server']['pmadb']);
859 $_SESSION['relation'] = [];
861 $this->dummyDbi
->addSelectDb('db_pma');
862 $this->dummyDbi
->addSelectDb('db_pma');
863 $this->relation
->fixPmaTables('db_pma', true);
864 $this->assertArrayNotHasKey('message', $GLOBALS);
865 $this->assertArrayHasKey($GLOBALS['server'], $_SESSION['relation'], 'The cache is expected to be filled');
866 /** @psalm-suppress EmptyArrayAccess */
867 $this->assertIsArray($_SESSION['relation'][$GLOBALS['server']]);
868 $this->assertSame('db_pma', $GLOBALS['cfg']['Server']['pmadb']);
870 $relationParameters = RelationParameters
::fromArray([
872 'userconfigwork' => true,
873 'userconfig' => 'pma__userconfig',
875 $this->assertSame($relationParameters->toArray(), $_SESSION['relation'][$GLOBALS['server']]);
877 $this->assertAllQueriesConsumed();
878 $this->assertAllSelectsConsumed();
881 public function testFixPmaTablesNormalFixTablesFails(): void
883 parent
::setGlobalDbi();
886 $GLOBALS['server'] = 1;
887 $GLOBALS['cfg']['Server']['user'] = '';
888 $GLOBALS['cfg']['Server']['pmadb'] = '';
889 $GLOBALS['cfg']['Server']['bookmarktable'] = '';
890 $GLOBALS['cfg']['Server']['relation'] = '';
891 $GLOBALS['cfg']['Server']['table_info'] = '';
892 $GLOBALS['cfg']['Server']['table_coords'] = '';
893 $GLOBALS['cfg']['Server']['column_info'] = '';
894 $GLOBALS['cfg']['Server']['pdf_pages'] = '';
895 $GLOBALS['cfg']['Server']['history'] = '';
896 $GLOBALS['cfg']['Server']['recent'] = '';
897 $GLOBALS['cfg']['Server']['favorite'] = '';
898 $GLOBALS['cfg']['Server']['table_uiprefs'] = '';
899 $GLOBALS['cfg']['Server']['tracking'] = '';
900 $GLOBALS['cfg']['Server']['userconfig'] = '';
901 $GLOBALS['cfg']['Server']['users'] = '';
902 $GLOBALS['cfg']['Server']['usergroups'] = '';
903 $GLOBALS['cfg']['Server']['navigationhiding'] = '';
904 $GLOBALS['cfg']['Server']['savedsearches'] = '';
905 $GLOBALS['cfg']['Server']['central_columns'] = '';
906 $GLOBALS['cfg']['Server']['designer_settings'] = '';
907 $GLOBALS['cfg']['Server']['export_templates'] = '';
909 $this->relation
= new Relation($this->dbi
);
911 $this->dummyDbi
->removeDefaultResults();
912 $this->dummyDbi
->addResult(
913 'SHOW TABLES FROM `db_pma`;',
921 $this->dummyDbi
->addErrorCode('MYSQL_ERROR');
922 $this->dummyDbi
->addResult(
923 '-- -------------------------------------------------------- -- --'
924 . ' Table structure for table `pma__bookmark` '
925 . '-- CREATE TABLE IF NOT EXISTS `pma__bookmark` ( '
926 . '`id` int(10) unsigned NOT NULL auto_increment,'
927 . ' `dbase` varchar(255) NOT NULL default \'\','
928 . ' `user` varchar(255) NOT NULL default \'\','
929 . ' `label` varchar(255) COLLATE utf8_general_ci NOT NULL default \'\','
930 . ' `query` text NOT NULL, PRIMARY KEY (`id`) )'
931 . ' COMMENT=\'Bookmarks\' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
934 $this->dummyDbi
->addSelectDb('db_pma');
936 $this->assertSame('', $GLOBALS['cfg']['Server']['pmadb']);
938 $_SESSION['relation'] = [];
940 $this->relation
->fixPmaTables('db_pma', true);
942 $this->assertArrayHasKey('message', $GLOBALS);
943 $this->assertSame('MYSQL_ERROR', $GLOBALS['message']);
944 $this->assertSame('', $GLOBALS['cfg']['Server']['pmadb']);
946 $this->assertSame([], $_SESSION['relation']);
948 $this->assertAllQueriesConsumed();
949 $this->assertAllErrorCodesConsumed();
950 $this->assertAllSelectsConsumed();
953 public function testCreatePmaDatabase(): void
955 parent
::setGlobalDbi();
956 $this->relation
= new Relation($this->dbi
);
958 $this->dummyDbi
->removeDefaultResults();
959 $this->dummyDbi
->addErrorCode(false);
960 $this->dummyDbi
->addResult(
961 'CREATE DATABASE IF NOT EXISTS `phpmyadmin`',
965 $this->dummyDbi
->addResult(
966 'SHOW TABLES FROM `phpmyadmin`',
969 $this->dummyDbi
->addSelectDb('phpmyadmin');
971 $this->assertArrayNotHasKey('errno', $GLOBALS);
974 $this->relation
->createPmaDatabase('phpmyadmin')
977 $this->assertArrayNotHasKey('message', $GLOBALS);
979 $this->assertAllQueriesConsumed();
980 $this->assertAllErrorCodesConsumed();
981 $this->assertAllSelectsConsumed();
984 public function testCreatePmaDatabaseFailsError1044(): void
986 parent
::setGlobalDbi();
987 $this->relation
= new Relation($this->dbi
);
989 $this->dummyDbi
->removeDefaultResults();
990 $this->dummyDbi
->addErrorCode('MYSQL_ERROR');
991 $this->dummyDbi
->addResult('CREATE DATABASE IF NOT EXISTS `phpmyadmin`', false);
993 $GLOBALS['errno'] = 1044;// ER_DBACCESS_DENIED_ERROR
996 $this->relation
->createPmaDatabase('phpmyadmin')
999 $this->assertArrayHasKey('message', $GLOBALS);
1001 'You do not have necessary privileges to create a database named'
1002 . ' \'phpmyadmin\'. You may go to \'Operations\' tab of any'
1003 . ' database to set up the phpMyAdmin configuration storage there.',
1007 $this->assertAllQueriesConsumed();
1008 $this->assertAllErrorCodesConsumed();
1011 public function testCreatePmaDatabaseFailsError1040(): void
1013 parent
::setGlobalDbi();
1014 $this->relation
= new Relation($this->dbi
);
1016 $this->dummyDbi
->removeDefaultResults();
1017 $this->dummyDbi
->addErrorCode('Too many connections');
1018 $this->dummyDbi
->addResult('CREATE DATABASE IF NOT EXISTS `pma_1040`', false);
1020 $GLOBALS['errno'] = 1040;
1023 $this->relation
->createPmaDatabase('pma_1040')
1026 $this->assertArrayHasKey('message', $GLOBALS);
1027 $this->assertSame('Too many connections', $GLOBALS['message']);
1029 $this->assertAllQueriesConsumed();
1030 $this->assertAllErrorCodesConsumed();
1033 public function testGetDefaultPmaTableNames(): void
1035 $this->relation
= new Relation($this->dbi
);
1038 'pma__bookmark' => implode("\n", [
1041 '-- --------------------------------------------------------',
1044 '-- Table structure for table `pma__bookmark`',
1047 'CREATE TABLE IF NOT EXISTS `pma__bookmark` (',
1048 ' `id` int(10) unsigned NOT NULL auto_increment,',
1049 ' `dbase` varchar(255) NOT NULL default \'\',',
1050 ' `user` varchar(255) NOT NULL default \'\',',
1051 ' `label` varchar(255) COLLATE utf8_general_ci NOT NULL default \'\',',
1052 ' `query` text NOT NULL,',
1053 ' PRIMARY KEY (`id`)',
1055 ' COMMENT=\'Bookmarks\'',
1056 ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
1058 'pma__column_info' => implode("\n", [
1061 '-- --------------------------------------------------------',
1064 '-- Table structure for table `pma__column_info`',
1067 'CREATE TABLE IF NOT EXISTS `pma__column_info` (',
1068 ' `id` int(5) unsigned NOT NULL auto_increment,',
1069 ' `db_name` varchar(64) NOT NULL default \'\',',
1070 ' `table_name` varchar(64) NOT NULL default \'\',',
1071 ' `column_name` varchar(64) NOT NULL default \'\',',
1072 ' `comment` varchar(255) COLLATE utf8_general_ci NOT NULL default \'\',',
1073 ' `mimetype` varchar(255) COLLATE utf8_general_ci NOT NULL default \'\',',
1074 ' `transformation` varchar(255) NOT NULL default \'\',',
1075 ' `transformation_options` varchar(255) NOT NULL default \'\',',
1076 ' `input_transformation` varchar(255) NOT NULL default \'\',',
1077 ' `input_transformation_options` varchar(255) NOT NULL default \'\',',
1078 ' PRIMARY KEY (`id`),',
1079 ' UNIQUE KEY `db_name` (`db_name`,`table_name`,`column_name`)',
1081 ' COMMENT=\'Column information for phpMyAdmin\'',
1082 ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
1084 'pma__history' => implode("\n", [
1087 '-- --------------------------------------------------------',
1090 '-- Table structure for table `pma__history`',
1093 'CREATE TABLE IF NOT EXISTS `pma__history` (',
1094 ' `id` bigint(20) unsigned NOT NULL auto_increment,',
1095 ' `username` varchar(64) NOT NULL default \'\',',
1096 ' `db` varchar(64) NOT NULL default \'\',',
1097 ' `table` varchar(64) NOT NULL default \'\',',
1098 ' `timevalue` timestamp NOT NULL default CURRENT_TIMESTAMP,',
1099 ' `sqlquery` text NOT NULL,',
1100 ' PRIMARY KEY (`id`),',
1101 ' KEY `username` (`username`,`db`,`table`,`timevalue`)',
1103 ' COMMENT=\'SQL history for phpMyAdmin\'',
1104 ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
1106 'pma__pdf_pages' => implode("\n", [
1109 '-- --------------------------------------------------------',
1112 '-- Table structure for table `pma__pdf_pages`',
1115 'CREATE TABLE IF NOT EXISTS `pma__pdf_pages` (',
1116 ' `db_name` varchar(64) NOT NULL default \'\',',
1117 ' `page_nr` int(10) unsigned NOT NULL auto_increment,',
1118 ' `page_descr` varchar(50) COLLATE utf8_general_ci NOT NULL default \'\',',
1119 ' PRIMARY KEY (`page_nr`),',
1120 ' KEY `db_name` (`db_name`)',
1122 ' COMMENT=\'PDF relation pages for phpMyAdmin\'',
1123 ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
1125 'pma__recent' => implode("\n", [
1128 '-- --------------------------------------------------------',
1131 '-- Table structure for table `pma__recent`',
1134 'CREATE TABLE IF NOT EXISTS `pma__recent` (',
1135 ' `username` varchar(64) NOT NULL,',
1136 ' `tables` text NOT NULL,',
1137 ' PRIMARY KEY (`username`)',
1139 ' COMMENT=\'Recently accessed tables\'',
1140 ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
1142 'pma__favorite' => implode("\n", [
1145 '-- --------------------------------------------------------',
1148 '-- Table structure for table `pma__favorite`',
1151 'CREATE TABLE IF NOT EXISTS `pma__favorite` (',
1152 ' `username` varchar(64) NOT NULL,',
1153 ' `tables` text NOT NULL,',
1154 ' PRIMARY KEY (`username`)',
1156 ' COMMENT=\'Favorite tables\'',
1157 ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
1159 'pma__table_uiprefs' => implode("\n", [
1162 '-- --------------------------------------------------------',
1165 '-- Table structure for table `pma__table_uiprefs`',
1168 'CREATE TABLE IF NOT EXISTS `pma__table_uiprefs` (',
1169 ' `username` varchar(64) NOT NULL,',
1170 ' `db_name` varchar(64) NOT NULL,',
1171 ' `table_name` varchar(64) NOT NULL,',
1172 ' `prefs` text NOT NULL,',
1173 ' `last_update` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,',
1174 ' PRIMARY KEY (`username`,`db_name`,`table_name`)',
1176 ' COMMENT=\'Tables\'\' UI preferences\'',
1177 ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
1179 'pma__relation' => implode("\n", [
1182 '-- --------------------------------------------------------',
1185 '-- Table structure for table `pma__relation`',
1188 'CREATE TABLE IF NOT EXISTS `pma__relation` (',
1189 ' `master_db` varchar(64) NOT NULL default \'\',',
1190 ' `master_table` varchar(64) NOT NULL default \'\',',
1191 ' `master_field` varchar(64) NOT NULL default \'\',',
1192 ' `foreign_db` varchar(64) NOT NULL default \'\',',
1193 ' `foreign_table` varchar(64) NOT NULL default \'\',',
1194 ' `foreign_field` varchar(64) NOT NULL default \'\',',
1195 ' PRIMARY KEY (`master_db`,`master_table`,`master_field`),',
1196 ' KEY `foreign_field` (`foreign_db`,`foreign_table`)',
1198 ' COMMENT=\'Relation table\'',
1199 ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
1201 'pma__table_coords' => implode("\n", [
1204 '-- --------------------------------------------------------',
1207 '-- Table structure for table `pma__table_coords`',
1210 'CREATE TABLE IF NOT EXISTS `pma__table_coords` (',
1211 ' `db_name` varchar(64) NOT NULL default \'\',',
1212 ' `table_name` varchar(64) NOT NULL default \'\',',
1213 ' `pdf_page_number` int(11) NOT NULL default \'0\',',
1214 ' `x` float unsigned NOT NULL default \'0\',',
1215 ' `y` float unsigned NOT NULL default \'0\',',
1216 ' PRIMARY KEY (`db_name`,`table_name`,`pdf_page_number`)',
1218 ' COMMENT=\'Table coordinates for phpMyAdmin PDF output\'',
1219 ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
1221 'pma__table_info' => implode("\n", [
1224 '-- --------------------------------------------------------',
1227 '-- Table structure for table `pma__table_info`',
1230 'CREATE TABLE IF NOT EXISTS `pma__table_info` (',
1231 ' `db_name` varchar(64) NOT NULL default \'\',',
1232 ' `table_name` varchar(64) NOT NULL default \'\',',
1233 ' `display_field` varchar(64) NOT NULL default \'\',',
1234 ' PRIMARY KEY (`db_name`,`table_name`)',
1236 ' COMMENT=\'Table information for phpMyAdmin\'',
1237 ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
1239 'pma__tracking' => implode("\n", [
1242 '-- --------------------------------------------------------',
1245 '-- Table structure for table `pma__tracking`',
1248 'CREATE TABLE IF NOT EXISTS `pma__tracking` (',
1249 ' `db_name` varchar(64) NOT NULL,',
1250 ' `table_name` varchar(64) NOT NULL,',
1251 ' `version` int(10) unsigned NOT NULL,',
1252 ' `date_created` datetime NOT NULL,',
1253 ' `date_updated` datetime NOT NULL,',
1254 ' `schema_snapshot` text NOT NULL,',
1255 ' `schema_sql` text,',
1256 ' `data_sql` longtext,',
1257 ' `tracking` set(\'UPDATE\',\'REPLACE\',\'INSERT\',\'DELETE\','
1258 . '\'TRUNCATE\',\'CREATE DATABASE\',\'ALTER DATABASE\',\'DROP DATABASE\','
1259 . '\'CREATE TABLE\',\'ALTER TABLE\',\'RENAME TABLE\',\'DROP TABLE\','
1260 . '\'CREATE INDEX\',\'DROP INDEX\',\'CREATE VIEW\',\'ALTER VIEW\','
1261 . '\'DROP VIEW\') default NULL,',
1262 ' `tracking_active` int(1) unsigned NOT NULL default \'1\',',
1263 ' PRIMARY KEY (`db_name`,`table_name`,`version`)',
1265 ' COMMENT=\'Database changes tracking for phpMyAdmin\'',
1266 ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
1268 'pma__userconfig' => implode("\n", [
1271 '-- --------------------------------------------------------',
1274 '-- Table structure for table `pma__userconfig`',
1277 'CREATE TABLE IF NOT EXISTS `pma__userconfig` (',
1278 ' `username` varchar(64) NOT NULL,',
1279 ' `timevalue` timestamp NOT NULL default CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,',
1280 ' `config_data` text NOT NULL,',
1281 ' PRIMARY KEY (`username`)',
1283 ' COMMENT=\'User preferences storage for phpMyAdmin\'',
1284 ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
1286 'pma__users' => implode("\n", [
1289 '-- --------------------------------------------------------',
1292 '-- Table structure for table `pma__users`',
1295 'CREATE TABLE IF NOT EXISTS `pma__users` (',
1296 ' `username` varchar(64) NOT NULL,',
1297 ' `usergroup` varchar(64) NOT NULL,',
1298 ' PRIMARY KEY (`username`,`usergroup`)',
1300 ' COMMENT=\'Users and their assignments to user groups\'',
1301 ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
1303 'pma__usergroups' => implode("\n", [
1306 '-- --------------------------------------------------------',
1309 '-- Table structure for table `pma__usergroups`',
1312 'CREATE TABLE IF NOT EXISTS `pma__usergroups` (',
1313 ' `usergroup` varchar(64) NOT NULL,',
1314 ' `tab` varchar(64) NOT NULL,',
1315 ' `allowed` enum(\'Y\',\'N\') NOT NULL DEFAULT \'N\',',
1316 ' PRIMARY KEY (`usergroup`,`tab`,`allowed`)',
1318 ' COMMENT=\'User groups with configured menu items\'',
1319 ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
1321 'pma__navigationhiding' => implode("\n", [
1324 '-- --------------------------------------------------------',
1327 '-- Table structure for table `pma__navigationhiding`',
1330 'CREATE TABLE IF NOT EXISTS `pma__navigationhiding` (',
1331 ' `username` varchar(64) NOT NULL,',
1332 ' `item_name` varchar(64) NOT NULL,',
1333 ' `item_type` varchar(64) NOT NULL,',
1334 ' `db_name` varchar(64) NOT NULL,',
1335 ' `table_name` varchar(64) NOT NULL,',
1336 ' PRIMARY KEY (`username`,`item_name`,`item_type`,`db_name`,`table_name`)',
1338 ' COMMENT=\'Hidden items of navigation tree\'',
1339 ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
1341 'pma__savedsearches' => implode("\n", [
1344 '-- --------------------------------------------------------',
1347 '-- Table structure for table `pma__savedsearches`',
1350 'CREATE TABLE IF NOT EXISTS `pma__savedsearches` (',
1351 ' `id` int(5) unsigned NOT NULL auto_increment,',
1352 ' `username` varchar(64) NOT NULL default \'\',',
1353 ' `db_name` varchar(64) NOT NULL default \'\',',
1354 ' `search_name` varchar(64) NOT NULL default \'\',',
1355 ' `search_data` text NOT NULL,',
1356 ' PRIMARY KEY (`id`),',
1357 ' UNIQUE KEY `u_savedsearches_username_dbname` (`username`,`db_name`,`search_name`)',
1359 ' COMMENT=\'Saved searches\'',
1360 ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
1362 'pma__central_columns' => implode("\n", [
1365 '-- --------------------------------------------------------',
1368 '-- Table structure for table `pma__central_columns`',
1371 'CREATE TABLE IF NOT EXISTS `pma__central_columns` (',
1372 ' `db_name` varchar(64) NOT NULL,',
1373 ' `col_name` varchar(64) NOT NULL,',
1374 ' `col_type` varchar(64) NOT NULL,',
1375 ' `col_length` text,',
1376 ' `col_collation` varchar(64) NOT NULL,',
1377 ' `col_isNull` boolean NOT NULL,',
1378 ' `col_extra` varchar(255) default \'\',',
1379 ' `col_default` text,',
1380 ' PRIMARY KEY (`db_name`,`col_name`)',
1382 ' COMMENT=\'Central list of columns\'',
1383 ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
1385 'pma__designer_settings' => implode("\n", [
1388 '-- --------------------------------------------------------',
1391 '-- Table structure for table `pma__designer_settings`',
1394 'CREATE TABLE IF NOT EXISTS `pma__designer_settings` (',
1395 ' `username` varchar(64) NOT NULL,',
1396 ' `settings_data` text NOT NULL,',
1397 ' PRIMARY KEY (`username`)',
1399 ' COMMENT=\'Settings related to Designer\'',
1400 ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
1402 'pma__export_templates' => implode("\n", [
1405 '-- --------------------------------------------------------',
1408 '-- Table structure for table `pma__export_templates`',
1411 'CREATE TABLE IF NOT EXISTS `pma__export_templates` (',
1412 ' `id` int(5) unsigned NOT NULL AUTO_INCREMENT,',
1413 ' `username` varchar(64) NOT NULL,',
1414 ' `export_type` varchar(10) NOT NULL,',
1415 ' `template_name` varchar(64) NOT NULL,',
1416 ' `template_data` text NOT NULL,',
1417 ' PRIMARY KEY (`id`),',
1418 ' UNIQUE KEY `u_user_type_template` (`username`,`export_type`,`template_name`)',
1420 ' COMMENT=\'Saved export templates\'',
1421 ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
1427 $this->relation
->getDefaultPmaTableNames([])
1430 $data['pma__export_templates'] = implode("\n", [
1433 '-- --------------------------------------------------------',
1436 '-- Table structure for table `db_exporttemplates_pma`',
1439 'CREATE TABLE IF NOT EXISTS `db_exporttemplates_pma` (',
1440 ' `id` int(5) unsigned NOT NULL AUTO_INCREMENT,',
1441 ' `username` varchar(64) NOT NULL,',
1442 ' `export_type` varchar(10) NOT NULL,',
1443 ' `template_name` varchar(64) NOT NULL,',
1444 ' `template_data` text NOT NULL,',
1445 ' PRIMARY KEY (`id`),',
1446 ' UNIQUE KEY `u_user_type_template` (`username`,`export_type`,`template_name`)',
1448 ' COMMENT=\'Saved export templates\'',
1449 ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
1454 $this->relation
->getDefaultPmaTableNames(['pma__export_templates' => 'db_exporttemplates_pma'])
1458 public function testInitRelationParamsCacheDefaultDbNameDbDoesNotExist(): void
1460 parent
::setGlobalDbi();
1462 $GLOBALS['db'] = '';
1463 $GLOBALS['server'] = 0;
1465 $this->dummyDbi
->removeDefaultResults();
1466 $this->dummyDbi
->addResult('SHOW TABLES FROM `phpmyadmin`;', false);
1468 $relation = new Relation($this->dbi
);
1469 $relation->initRelationParamsCache();
1471 $this->assertAllQueriesConsumed();
1474 public function testInitRelationParamsCacheDefaultDbNameDbExistsServerZero(): void
1476 parent
::setGlobalDbi();
1478 $GLOBALS['db'] = '';
1479 $GLOBALS['server'] = 0;
1480 $GLOBALS['cfg']['Server'] = [];
1482 $this->dummyDbi
->removeDefaultResults();
1483 $this->dummyDbi
->addResult(
1484 'SHOW TABLES FROM `phpmyadmin`;',
1486 ['pma__userconfig'],
1488 ['Tables_in_phpmyadmin']
1491 $_SESSION['relation'] = [];
1493 $relation = new Relation($this->dbi
);
1494 $relation->initRelationParamsCache();
1496 $this->assertArrayHasKey($GLOBALS['server'], $_SESSION['relation'], 'The cache is expected to be filled');
1497 /** @psalm-suppress EmptyArrayAccess */
1498 $this->assertIsArray($_SESSION['relation'][$GLOBALS['server']]);
1500 // Should all be false for server = 0
1501 $relationParameters = RelationParameters
::fromArray([]);
1502 $this->assertSame($relationParameters->toArray(), $_SESSION['relation'][$GLOBALS['server']]);
1504 $this->assertEquals([
1505 'userconfig' => 'pma__userconfig',
1506 'pmadb' => false,// This is the expected value for server = 0
1507 ], $GLOBALS['cfg']['Server']);
1508 $this->assertAllQueriesConsumed();
1511 public function testInitRelationParamsCacheDefaultDbNameDbExistsFirstServer(): void
1513 parent
::setGlobalDbi();
1515 $GLOBALS['db'] = '';
1516 $GLOBALS['server'] = 1;
1517 $GLOBALS['cfg']['Server'] = [];
1518 $GLOBALS['cfg']['Server']['user'] = '';
1519 $GLOBALS['cfg']['Server']['pmadb'] = '';
1520 $GLOBALS['cfg']['Server']['bookmarktable'] = '';
1521 $GLOBALS['cfg']['Server']['relation'] = '';
1522 $GLOBALS['cfg']['Server']['table_info'] = '';
1523 $GLOBALS['cfg']['Server']['table_coords'] = '';
1524 $GLOBALS['cfg']['Server']['column_info'] = '';
1525 $GLOBALS['cfg']['Server']['pdf_pages'] = '';
1526 $GLOBALS['cfg']['Server']['history'] = '';
1527 $GLOBALS['cfg']['Server']['recent'] = '';
1528 $GLOBALS['cfg']['Server']['favorite'] = '';
1529 $GLOBALS['cfg']['Server']['table_uiprefs'] = '';
1530 $GLOBALS['cfg']['Server']['tracking'] = '';
1531 $GLOBALS['cfg']['Server']['userconfig'] = '';
1532 $GLOBALS['cfg']['Server']['users'] = '';
1533 $GLOBALS['cfg']['Server']['usergroups'] = '';
1534 $GLOBALS['cfg']['Server']['navigationhiding'] = '';
1535 $GLOBALS['cfg']['Server']['savedsearches'] = '';
1536 $GLOBALS['cfg']['Server']['central_columns'] = '';
1537 $GLOBALS['cfg']['Server']['designer_settings'] = '';
1538 $GLOBALS['cfg']['Server']['export_templates'] = '';
1540 $this->dummyDbi
->removeDefaultResults();
1541 $this->dummyDbi
->addResult(
1542 'SHOW TABLES FROM `phpmyadmin`;',
1544 ['pma__userconfig'],
1546 ['Tables_in_phpmyadmin']
1549 $this->dummyDbi
->addResult(
1550 'SHOW TABLES FROM `phpmyadmin`',
1552 ['pma__userconfig'],
1554 ['Tables_in_phpmyadmin']
1557 $this->dummyDbi
->addResult(
1558 'SELECT NULL FROM `pma__userconfig` LIMIT 0',
1565 $_SESSION['relation'] = [];
1567 $this->dummyDbi
->addSelectDb('phpmyadmin');
1568 $relation = new Relation($this->dbi
);
1569 $relation->initRelationParamsCache();
1570 $this->assertAllSelectsConsumed();
1572 $this->assertArrayHasKey($GLOBALS['server'], $_SESSION['relation'], 'The cache is expected to be filled');
1573 /** @psalm-suppress EmptyArrayAccess */
1574 $this->assertIsArray($_SESSION['relation'][$GLOBALS['server']]);
1576 // Should all be false for server = 0
1577 $relationParameters = RelationParameters
::fromArray([
1578 'db' => 'phpmyadmin',
1579 'userconfigwork' => true,
1580 'userconfig' => 'pma__userconfig',
1582 $this->assertSame($relationParameters->toArray(), $_SESSION['relation'][$GLOBALS['server']]);
1586 'pmadb' => 'phpmyadmin',
1587 'bookmarktable' => '',
1590 'table_coords' => '',
1591 'column_info' => '',
1596 'table_uiprefs' => '',
1598 'userconfig' => 'pma__userconfig',
1601 'navigationhiding' => '',
1602 'savedsearches' => '',
1603 'central_columns' => '',
1604 'designer_settings' => '',
1605 'export_templates' => '',
1606 ], $GLOBALS['cfg']['Server']);
1608 $this->assertAllQueriesConsumed();
1611 public function testInitRelationParamsCacheDefaultDbNameDbExistsFirstServerNotWorkingTable(): void
1613 parent
::setGlobalDbi();
1615 $GLOBALS['db'] = '';
1616 $GLOBALS['server'] = 1;
1617 $GLOBALS['cfg']['Server'] = [];
1618 $GLOBALS['cfg']['Server']['user'] = '';
1619 $GLOBALS['cfg']['Server']['pmadb'] = '';
1620 $GLOBALS['cfg']['Server']['bookmarktable'] = '';
1621 $GLOBALS['cfg']['Server']['relation'] = '';
1622 $GLOBALS['cfg']['Server']['table_info'] = '';
1623 $GLOBALS['cfg']['Server']['table_coords'] = '';
1624 $GLOBALS['cfg']['Server']['column_info'] = '';
1625 $GLOBALS['cfg']['Server']['pdf_pages'] = '';
1626 $GLOBALS['cfg']['Server']['history'] = '';
1627 $GLOBALS['cfg']['Server']['recent'] = '';
1628 $GLOBALS['cfg']['Server']['favorite'] = '';
1629 $GLOBALS['cfg']['Server']['table_uiprefs'] = '';
1630 $GLOBALS['cfg']['Server']['tracking'] = '';
1631 $GLOBALS['cfg']['Server']['userconfig'] = '';
1632 $GLOBALS['cfg']['Server']['users'] = '';
1633 $GLOBALS['cfg']['Server']['usergroups'] = '';
1634 $GLOBALS['cfg']['Server']['navigationhiding'] = '';
1635 $GLOBALS['cfg']['Server']['savedsearches'] = '';
1636 $GLOBALS['cfg']['Server']['central_columns'] = '';
1637 $GLOBALS['cfg']['Server']['designer_settings'] = '';
1638 $GLOBALS['cfg']['Server']['export_templates'] = '';
1640 $this->dummyDbi
->removeDefaultResults();
1641 $this->dummyDbi
->addResult(
1642 'SHOW TABLES FROM `phpmyadmin`;',
1644 ['pma__userconfig'],
1646 ['Tables_in_phpmyadmin']
1649 $this->dummyDbi
->addResult(
1650 'SHOW TABLES FROM `phpmyadmin`',
1652 ['pma__userconfig'],
1654 ['Tables_in_phpmyadmin']
1657 $this->dummyDbi
->addResult('SELECT NULL FROM `pma__userconfig` LIMIT 0', false);
1659 $_SESSION['relation'] = [];
1661 $this->dummyDbi
->addSelectDb('phpmyadmin');
1662 $relation = new Relation($this->dbi
);
1663 $relation->initRelationParamsCache();
1664 $this->assertAllSelectsConsumed();
1666 $this->assertArrayHasKey($GLOBALS['server'], $_SESSION['relation'], 'The cache is expected to be filled');
1667 /** @psalm-suppress EmptyArrayAccess */
1668 $this->assertIsArray($_SESSION['relation'][$GLOBALS['server']]);
1670 $relationParameters = RelationParameters
::fromArray([
1671 'db' => 'phpmyadmin',
1672 'userconfigwork' => false,
1673 'userconfig' => 'pma__userconfig',
1675 $this->assertSame($relationParameters->toArray(), $_SESSION['relation'][$GLOBALS['server']]);
1679 'pmadb' => 'phpmyadmin',
1680 'bookmarktable' => '',
1683 'table_coords' => '',
1684 'column_info' => '',
1689 'table_uiprefs' => '',
1691 'userconfig' => 'pma__userconfig',
1694 'navigationhiding' => '',
1695 'savedsearches' => '',
1696 'central_columns' => '',
1697 'designer_settings' => '',
1698 'export_templates' => '',
1699 ], $GLOBALS['cfg']['Server']);
1701 $this->assertAllQueriesConsumed();
1704 public function testInitRelationParamsCacheDefaultDbNameDbExistsFirstServerOverride(): void
1706 parent
::setGlobalDbi();
1708 $GLOBALS['db'] = '';
1709 $GLOBALS['server'] = 1;
1710 $GLOBALS['cfg']['Server'] = [];
1711 $GLOBALS['cfg']['Server']['user'] = '';
1712 $GLOBALS['cfg']['Server']['pmadb'] = 'PMA-storage';
1713 $GLOBALS['cfg']['Server']['bookmarktable'] = '';
1714 $GLOBALS['cfg']['Server']['relation'] = '';
1715 $GLOBALS['cfg']['Server']['table_info'] = '';
1716 $GLOBALS['cfg']['Server']['table_coords'] = '';
1717 $GLOBALS['cfg']['Server']['column_info'] = '';
1718 $GLOBALS['cfg']['Server']['pdf_pages'] = '';
1719 $GLOBALS['cfg']['Server']['history'] = '';
1720 $GLOBALS['cfg']['Server']['recent'] = '';
1721 $GLOBALS['cfg']['Server']['favorite'] = '';
1722 $GLOBALS['cfg']['Server']['table_uiprefs'] = '';
1723 $GLOBALS['cfg']['Server']['tracking'] = '';
1724 $GLOBALS['cfg']['Server']['userconfig'] = 'pma__userconfig_custom';
1725 $GLOBALS['cfg']['Server']['users'] = '';
1726 $GLOBALS['cfg']['Server']['usergroups'] = '';
1727 $GLOBALS['cfg']['Server']['navigationhiding'] = '';
1728 $GLOBALS['cfg']['Server']['savedsearches'] = '';
1729 $GLOBALS['cfg']['Server']['central_columns'] = '';
1730 $GLOBALS['cfg']['Server']['designer_settings'] = '';
1731 $GLOBALS['cfg']['Server']['export_templates'] = '';
1733 $this->dummyDbi
->removeDefaultResults();
1734 $this->dummyDbi
->addResult(
1735 'SHOW TABLES FROM `PMA-storage`;',
1738 'pma__userconfig_custom',
1742 ['Tables_in_PMA-storage']
1745 $this->dummyDbi
->addResult(
1746 'SHOW TABLES FROM `PMA-storage`',
1749 'pma__userconfig_custom',
1753 ['Tables_in_PMA-storage']
1756 $this->dummyDbi
->addResult(
1757 'SELECT NULL FROM `pma__userconfig_custom` LIMIT 0',
1764 $this->dummyDbi
->addSelectDb('PMA-storage');
1766 $_SESSION['relation'] = [];
1768 $relation = new Relation($this->dbi
);
1769 $relation->initRelationParamsCache();
1771 $this->assertArrayHasKey(
1774 'The cache is expected to be filled because the custom override'
1775 . 'was undertood (pma__userconfig vs pma__userconfig_custom)'
1778 $this->assertAllQueriesConsumed();
1779 $this->assertAllSelectsConsumed();
1781 $this->dummyDbi
->addResult(
1782 'SHOW TABLES FROM `PMA-storage`',
1785 'pma__userconfig_custom',
1789 ['Tables_in_PMA-storage']
1792 $this->dummyDbi
->addResult(
1793 'SELECT NULL FROM `pma__userconfig_custom` LIMIT 0',
1800 $this->dummyDbi
->addSelectDb('PMA-storage');
1801 /** @psalm-suppress EmptyArrayAccess */
1802 unset($_SESSION['relation'][$GLOBALS['server']]);
1803 $relationData = $relation->getRelationParameters();
1804 $this->assertAllSelectsConsumed();
1806 $relationParameters = RelationParameters
::fromArray([
1807 'db' => 'PMA-storage',
1808 'userconfigwork' => true,
1809 'userconfig' => 'pma__userconfig_custom',
1811 $this->assertSame($relationParameters->toArray(), $relationData->toArray());
1815 'pmadb' => 'PMA-storage',
1816 'bookmarktable' => '',
1819 'table_coords' => '',
1820 'column_info' => '',
1825 'table_uiprefs' => '',
1827 'userconfig' => 'pma__userconfig_custom',
1830 'navigationhiding' => '',
1831 'savedsearches' => '',
1832 'central_columns' => '',
1833 'designer_settings' => '',
1834 'export_templates' => '',
1835 ], $GLOBALS['cfg']['Server']);
1837 $this->assertAllQueriesConsumed();