Change deprecated ReflectionProperty method call
[phpmyadmin.git] / test / classes / ConfigStorage / RelationTest.php
blobb202f374b5368489fd383ecbd35adb40cad41b32
1 <?php
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\RecentFavoriteTable;
11 use PhpMyAdmin\Tests\AbstractTestCase;
12 use PhpMyAdmin\Tests\Stubs\DummyResult;
13 use ReflectionClass;
15 use function implode;
17 /**
18 * @covers \PhpMyAdmin\ConfigStorage\Relation
19 * @group medium
21 class RelationTest extends AbstractTestCase
23 /** @var Relation */
24 private $relation;
26 /**
27 * Sets up the fixture, for example, opens a network connection.
28 * This method is called before a test is executed.
30 protected function setUp(): void
32 parent::setUp();
33 parent::setTheme();
34 $GLOBALS['server'] = 1;
35 $GLOBALS['db'] = 'db';
36 $GLOBALS['cfg']['Server']['user'] = 'root';
37 $GLOBALS['cfg']['Server']['pmadb'] = 'phpmyadmin';
38 $GLOBALS['cfg']['Server']['DisableIS'] = false;
39 $GLOBALS['cfg']['ZeroConf'] = true;
40 $GLOBALS['cfg']['ServerDefault'] = 0;
41 $_SESSION['relation'] = [];
43 $this->relation = new Relation($GLOBALS['dbi']);
46 /**
47 * Test for getDisplayField
49 public function testPMAGetDisplayField(): void
51 $this->dummyDbi->addSelectDb('phpmyadmin');
52 $db = 'information_schema';
53 $table = 'CHARACTER_SETS';
54 $this->assertEquals(
55 'DESCRIPTION',
56 $this->relation->getDisplayField($db, $table)
58 $this->assertAllSelectsConsumed();
60 $db = 'information_schema';
61 $table = 'TABLES';
62 $this->assertEquals(
63 'TABLE_COMMENT',
64 $this->relation->getDisplayField($db, $table)
67 $db = 'information_schema';
68 $table = 'PMA';
69 $this->assertFalse(
70 $this->relation->getDisplayField($db, $table)
74 /**
75 * Test for getComments
77 public function testPMAGetComments(): void
79 $GLOBALS['cfg']['ServerDefault'] = 0;
81 $dbi = $this->getMockBuilder(DatabaseInterface::class)
82 ->disableOriginalConstructor()
83 ->getMock();
85 $getColumnsResult = [
87 'Field' => 'field1',
88 'Type' => 'int(11)',
89 'Comment' => 'Comment1',
92 'Field' => 'field2',
93 'Type' => 'text',
94 'Comment' => 'Comment1',
97 $dbi->expects($this->any())->method('getColumns')
98 ->will($this->returnValue($getColumnsResult));
100 $GLOBALS['dbi'] = $dbi;
101 $this->relation->dbi = $GLOBALS['dbi'];
103 $db = 'information_schema';
104 $this->assertEquals(
105 [''],
106 $this->relation->getComments($db)
109 $db = 'information_schema';
110 $table = 'TABLES';
111 $this->assertEquals(
113 'field1' => 'Comment1',
114 'field2' => 'Comment1',
116 $this->relation->getComments($db, $table)
121 * Test for tryUpgradeTransformations
123 public function testPMATryUpgradeTransformations(): void
125 $resultStub = $this->createMock(DummyResult::class);
127 $dbi = $this->getMockBuilder(DatabaseInterface::class)
128 ->disableOriginalConstructor()
129 ->getMock();
130 $dbi->expects($this->any())
131 ->method('tryQueryAsControlUser')
132 ->will($this->returnValue($resultStub));
133 $resultStub->expects($this->any())
134 ->method('numRows')
135 ->will($this->returnValue(0));
136 $dbi->expects($this->any())
137 ->method('getError')
138 ->will($this->onConsecutiveCalls('Error', ''));
139 $GLOBALS['dbi'] = $dbi;
140 $this->relation->dbi = $GLOBALS['dbi'];
142 $GLOBALS['cfg']['Server']['pmadb'] = 'pmadb';
143 $GLOBALS['cfg']['Server']['column_info'] = 'column_info';
145 // Case 1
146 $actual = $this->relation->tryUpgradeTransformations();
147 $this->assertFalse($actual);
149 // Case 2
150 $actual = $this->relation->tryUpgradeTransformations();
151 $this->assertTrue($actual);
154 public function testSearchColumnInForeignersError(): void
156 $this->assertFalse($this->relation->searchColumnInForeigners([], 'id'));
160 * Test for searchColumnInForeigners
162 public function testPMASearchColumnInForeigners(): void
164 $foreigners = [
165 'value' => [
166 'master_field' => 'value',
167 'foreign_db' => 'GSoC14',
168 'foreign_table' => 'test',
169 'foreign_field' => 'value',
171 'foreign_keys_data' => [
172 0 => [
173 'constraint' => 'ad',
174 'index_list' => [
175 'id',
176 'value',
178 'ref_db_name' => 'GSoC14',
179 'ref_table_name' => 'table_1',
180 'ref_index_list' => [
181 'id',
182 'value',
184 'on_delete' => 'CASCADE',
185 'on_update' => 'CASCADE',
190 $foreigner = $this->relation->searchColumnInForeigners($foreigners, 'id');
191 $expected = [];
192 $expected['foreign_field'] = 'id';
193 $expected['foreign_db'] = 'GSoC14';
194 $expected['foreign_table'] = 'table_1';
195 $expected['constraint'] = 'ad';
196 $expected['on_delete'] = 'CASCADE';
197 $expected['on_update'] = 'CASCADE';
199 $this->assertEquals($expected, $foreigner);
202 public function testFixPmaTablesNothingWorks(): void
204 parent::setGlobalDbi();
206 $this->relation = new Relation($this->dbi);
208 $this->dummyDbi->removeDefaultResults();
209 $this->dummyDbi->addResult('SHOW TABLES FROM `db_pma`;', false);
211 $this->relation->fixPmaTables('db_pma', false);
212 $this->assertAllQueriesConsumed();
215 public function testFixPmaTablesNormal(): void
217 parent::setGlobalDbi();
219 $GLOBALS['db'] = '';
220 $GLOBALS['server'] = 1;
221 $GLOBALS['cfg']['Server']['user'] = '';
222 $GLOBALS['cfg']['Server']['pmadb'] = '';
223 $GLOBALS['cfg']['Server']['bookmarktable'] = '';
224 $GLOBALS['cfg']['Server']['relation'] = '';
225 $GLOBALS['cfg']['Server']['table_info'] = '';
226 $GLOBALS['cfg']['Server']['table_coords'] = '';
227 $GLOBALS['cfg']['Server']['column_info'] = '';
228 $GLOBALS['cfg']['Server']['pdf_pages'] = '';
229 $GLOBALS['cfg']['Server']['history'] = '';
230 $GLOBALS['cfg']['Server']['recent'] = '';
231 $GLOBALS['cfg']['Server']['favorite'] = '';
232 $GLOBALS['cfg']['Server']['table_uiprefs'] = '';
233 $GLOBALS['cfg']['Server']['tracking'] = '';
234 $GLOBALS['cfg']['Server']['userconfig'] = '';
235 $GLOBALS['cfg']['Server']['users'] = '';
236 $GLOBALS['cfg']['Server']['usergroups'] = '';
237 $GLOBALS['cfg']['Server']['navigationhiding'] = '';
238 $GLOBALS['cfg']['Server']['savedsearches'] = '';
239 $GLOBALS['cfg']['Server']['central_columns'] = '';
240 $GLOBALS['cfg']['Server']['designer_settings'] = '';
241 $GLOBALS['cfg']['Server']['export_templates'] = '';
243 $this->relation = new Relation($this->dbi);
245 $this->dummyDbi->removeDefaultResults();
246 $this->dummyDbi->addResult(
247 'SHOW TABLES FROM `db_pma`;',
249 ['pma__userconfig'],
251 ['Tables_in_db_pma']
254 $this->dummyDbi->addResult(
255 'SHOW TABLES FROM `db_pma`',
257 ['pma__userconfig'],
259 ['Tables_in_db_pma']
262 $this->dummyDbi->addResult(
263 'SELECT NULL FROM `pma__userconfig` LIMIT 0',
264 [['NULL']]
266 $this->dummyDbi->addSelectDb('db_pma');
268 $_SESSION['relation'] = [];
270 $this->relation->fixPmaTables('db_pma', false);
272 $this->assertArrayHasKey($GLOBALS['server'], $_SESSION['relation'], 'The cache is expected to be filled');
273 /** @psalm-suppress EmptyArrayAccess */
274 $this->assertIsArray($_SESSION['relation'][$GLOBALS['server']]);
276 $relationParameters = RelationParameters::fromArray([
277 'db' => 'db_pma',
278 'userconfigwork' => true,
279 'userconfig' => 'pma__userconfig',
281 $this->assertSame($relationParameters->toArray(), $_SESSION['relation'][$GLOBALS['server']]);
283 $this->assertAllQueriesConsumed();
284 $this->assertAllSelectsConsumed();
287 public function testFixPmaTablesNormalFixTables(): void
289 parent::setGlobalDbi();
291 $GLOBALS['db'] = '';
292 $GLOBALS['server'] = 1;
293 $GLOBALS['cfg']['Server']['user'] = '';
294 $GLOBALS['cfg']['Server']['pmadb'] = '';
295 $GLOBALS['cfg']['Server']['bookmarktable'] = '';
296 $GLOBALS['cfg']['Server']['relation'] = '';
297 $GLOBALS['cfg']['Server']['table_info'] = '';
298 $GLOBALS['cfg']['Server']['table_coords'] = '';
299 $GLOBALS['cfg']['Server']['column_info'] = '';
300 $GLOBALS['cfg']['Server']['pdf_pages'] = '';
301 $GLOBALS['cfg']['Server']['history'] = '';
302 $GLOBALS['cfg']['Server']['recent'] = '';
303 $GLOBALS['cfg']['Server']['favorite'] = '';
304 $GLOBALS['cfg']['Server']['table_uiprefs'] = '';
305 $GLOBALS['cfg']['Server']['tracking'] = '';
306 $GLOBALS['cfg']['Server']['userconfig'] = '';
307 $GLOBALS['cfg']['Server']['users'] = '';
308 $GLOBALS['cfg']['Server']['usergroups'] = '';
309 $GLOBALS['cfg']['Server']['navigationhiding'] = '';
310 $GLOBALS['cfg']['Server']['savedsearches'] = '';
311 $GLOBALS['cfg']['Server']['central_columns'] = '';
312 $GLOBALS['cfg']['Server']['designer_settings'] = '';
313 $GLOBALS['cfg']['Server']['export_templates'] = '';
315 $this->relation = new Relation($this->dbi);
317 $this->dummyDbi->removeDefaultResults();
318 $this->dummyDbi->addResult(
319 'SHOW TABLES FROM `db_pma`;',
321 ['pma__userconfig'],
323 ['Tables_in_db_pma']
326 $this->dummyDbi->addResult(
327 'SHOW TABLES FROM `db_pma`',
329 ['pma__userconfig'],
331 ['Tables_in_db_pma']
334 $this->dummyDbi->addResult(
335 'SELECT NULL FROM `pma__userconfig` LIMIT 0',
336 [['NULL']]
338 $this->dummyDbi->addSelectDb('db_pma');
339 $this->dummyDbi->addSelectDb('db_pma');
341 $this->dummyDbi->addResult(
342 '-- -------------------------------------------------------- -- --'
343 . ' Table structure for table `pma__bookmark` '
344 . '-- CREATE TABLE IF NOT EXISTS `pma__bookmark` ( '
345 . '`id` int(10) unsigned NOT NULL auto_increment,'
346 . ' `dbase` varchar(255) NOT NULL default \'\','
347 . ' `user` varchar(255) NOT NULL default \'\','
348 . ' `label` varchar(255) COLLATE utf8_general_ci NOT NULL default \'\','
349 . ' `query` text NOT NULL, PRIMARY KEY (`id`) )'
350 . ' COMMENT=\'Bookmarks\' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
353 $this->dummyDbi->addResult(
354 '-- -------------------------------------------------------- -- --'
355 . ' Table structure for table `pma__relation` '
356 . '-- CREATE TABLE IF NOT EXISTS `pma__relation` ( '
357 . '`master_db` varchar(64) NOT NULL default \'\', `master_table` varchar(64) NOT NULL default \'\','
358 . ' `master_field` varchar(64) NOT NULL default \'\', `foreign_db` varchar(64) NOT NULL default \'\','
359 . ' `foreign_table` varchar(64) NOT NULL default \'\','
360 . ' `foreign_field` varchar(64) NOT NULL default \'\','
361 . ' PRIMARY KEY (`master_db`,`master_table`,`master_field`),'
362 . ' KEY `foreign_field` (`foreign_db`,`foreign_table`) ) COMMENT=\'Relation table\''
363 . ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
366 $this->dummyDbi->addResult(
367 '-- -------------------------------------------------------- -- --'
368 . ' Table structure for table `pma__table_info`'
369 . ' -- CREATE TABLE IF NOT EXISTS `pma__table_info` ( '
370 . '`db_name` varchar(64) NOT NULL default \'\', `table_name` varchar(64) NOT NULL default \'\','
371 . ' `display_field` varchar(64) NOT NULL default \'\', PRIMARY KEY (`db_name`,`table_name`) )'
372 . ' COMMENT=\'Table information for phpMyAdmin\' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
376 $this->dummyDbi->addResult(
377 '-- -------------------------------------------------------- -- --'
378 . ' Table structure for table `pma__table_coords`'
379 . ' -- CREATE TABLE IF NOT EXISTS `pma__table_coords` ( '
380 . '`db_name` varchar(64) NOT NULL default \'\', `table_name` varchar(64) NOT NULL default \'\','
381 . ' `pdf_page_number` int(11) NOT NULL default \'0\', `x` float unsigned NOT NULL default \'0\','
382 . ' `y` float unsigned NOT NULL default \'0\','
383 . ' PRIMARY KEY (`db_name`,`table_name`,`pdf_page_number`) )'
384 . ' COMMENT=\'Table coordinates for phpMyAdmin PDF output\''
385 . ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
388 $this->dummyDbi->addResult(
389 '-- -------------------------------------------------------- -- --'
390 . ' Table structure for table `pma__pdf_pages`'
391 . ' -- CREATE TABLE IF NOT EXISTS `pma__pdf_pages` ( '
392 . '`db_name` varchar(64) NOT NULL default \'\', `page_nr` int(10) unsigned NOT NULL auto_increment,'
393 . ' `page_descr` varchar(50) COLLATE utf8_general_ci NOT NULL default \'\', PRIMARY KEY (`page_nr`),'
394 . ' KEY `db_name` (`db_name`) ) COMMENT=\'PDF relation pages for phpMyAdmin\''
395 . ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
398 $this->dummyDbi->addResult(
399 '-- -------------------------------------------------------- -- --'
400 . ' Table structure for table `pma__column_info`'
401 . ' -- CREATE TABLE IF NOT EXISTS `pma__column_info` ( '
402 . '`id` int(5) unsigned NOT NULL auto_increment, `db_name` varchar(64) NOT NULL default \'\','
403 . ' `table_name` varchar(64) NOT NULL default \'\', `column_name` varchar(64) NOT NULL default \'\','
404 . ' `comment` varchar(255) COLLATE utf8_general_ci NOT NULL default \'\','
405 . ' `mimetype` varchar(255) COLLATE utf8_general_ci NOT NULL default \'\','
406 . ' `transformation` varchar(255) NOT NULL default \'\','
407 . ' `transformation_options` varchar(255) NOT NULL default \'\','
408 . ' `input_transformation` varchar(255) NOT NULL default \'\','
409 . ' `input_transformation_options` varchar(255) NOT NULL default \'\','
410 . ' PRIMARY KEY (`id`), UNIQUE KEY `db_name` (`db_name`,`table_name`,`column_name`) )'
411 . ' COMMENT=\'Column information for phpMyAdmin\' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
414 $this->dummyDbi->addResult(
415 '-- -------------------------------------------------------- -- --'
416 . ' Table structure for table `pma__history` '
417 . '-- CREATE TABLE IF NOT EXISTS `pma__history` ( '
418 . '`id` bigint(20) unsigned NOT NULL auto_increment, `username` varchar(64) NOT NULL default \'\','
419 . ' `db` varchar(64) NOT NULL default \'\', `table` varchar(64) NOT NULL default \'\','
420 . ' `timevalue` timestamp NOT NULL default CURRENT_TIMESTAMP, `sqlquery` text NOT NULL,'
421 . ' PRIMARY KEY (`id`), KEY `username` (`username`,`db`,`table`,`timevalue`) )'
422 . ' COMMENT=\'SQL history for phpMyAdmin\' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
425 $this->dummyDbi->addResult(
426 '-- -------------------------------------------------------- -- --'
427 . ' Table structure for table `pma__recent` '
428 . '-- CREATE TABLE IF NOT EXISTS `pma__recent` ( '
429 . '`username` varchar(64) NOT NULL, `tables` text NOT NULL, PRIMARY KEY (`username`) )'
430 . ' COMMENT=\'Recently accessed tables\' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
433 $this->dummyDbi->addResult(
434 '-- -------------------------------------------------------- -- --'
435 . ' Table structure for table `pma__favorite` '
436 . '-- CREATE TABLE IF NOT EXISTS `pma__favorite` ( '
437 . '`username` varchar(64) NOT NULL, `tables` text NOT NULL, PRIMARY KEY (`username`) )'
438 . ' COMMENT=\'Favorite tables\' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
441 $this->dummyDbi->addResult(
442 '-- -------------------------------------------------------- -- --'
443 . ' Table structure for table `pma__table_uiprefs`'
444 . ' -- CREATE TABLE IF NOT EXISTS `pma__table_uiprefs` ( '
445 . '`username` varchar(64) NOT NULL, `db_name` varchar(64) NOT NULL,'
446 . ' `table_name` varchar(64) NOT NULL, `prefs` text NOT NULL,'
447 . ' `last_update` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,'
448 . ' PRIMARY KEY (`username`,`db_name`,`table_name`) ) COMMENT=\'Tables\'\' UI preferences\''
449 . ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
452 $this->dummyDbi->addResult(
453 '-- -------------------------------------------------------- -- --'
454 . ' Table structure for table `pma__tracking` '
455 . '-- CREATE TABLE IF NOT EXISTS `pma__tracking` ( '
456 . '`db_name` varchar(64) NOT NULL, `table_name` varchar(64) NOT NULL,'
457 . ' `version` int(10) unsigned NOT NULL, `date_created` datetime NOT NULL,'
458 . ' `date_updated` datetime NOT NULL, `schema_snapshot` text NOT NULL,'
459 . ' `schema_sql` text, `data_sql` longtext, `tracking`'
460 . ' set(\'UPDATE\',\'REPLACE\',\'INSERT\',\'DELETE\','
461 . '\'TRUNCATE\',\'CREATE DATABASE\',\'ALTER DATABASE\','
462 . '\'DROP DATABASE\',\'CREATE TABLE\',\'ALTER TABLE\','
463 . '\'RENAME TABLE\',\'DROP TABLE\',\'CREATE INDEX\','
464 . '\'DROP INDEX\',\'CREATE VIEW\',\'ALTER VIEW\',\'DROP VIEW\')'
465 . ' default NULL, `tracking_active` int(1) unsigned NOT NULL'
466 . ' default \'1\', PRIMARY KEY (`db_name`,`table_name`,`version`) )'
467 . ' COMMENT=\'Database changes tracking for phpMyAdmin\''
468 . ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
471 $this->dummyDbi->addResult(
472 '-- -------------------------------------------------------- -- --'
473 . ' Table structure for table `pma__users` '
474 . '-- CREATE TABLE IF NOT EXISTS `pma__users` ( '
475 . '`username` varchar(64) NOT NULL, `usergroup` varchar(64) NOT NULL,'
476 . ' PRIMARY KEY (`username`,`usergroup`) )'
477 . ' COMMENT=\'Users and their assignments to user groups\''
478 . ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
481 $this->dummyDbi->addResult(
482 '-- -------------------------------------------------------- -- --'
483 . ' Table structure for table `pma__usergroups`'
484 . ' -- CREATE TABLE IF NOT EXISTS `pma__usergroups` ( '
485 . '`usergroup` varchar(64) NOT NULL, `tab` varchar(64) NOT NULL,'
486 . ' `allowed` enum(\'Y\',\'N\') NOT NULL DEFAULT \'N\','
487 . ' PRIMARY KEY (`usergroup`,`tab`,`allowed`) )'
488 . ' COMMENT=\'User groups with configured menu items\''
489 . ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
492 $this->dummyDbi->addResult(
493 '-- -------------------------------------------------------- -- --'
494 . ' Table structure for table `pma__navigationhiding`'
495 . ' -- CREATE TABLE IF NOT EXISTS `pma__navigationhiding` ( '
496 . '`username` varchar(64) NOT NULL, `item_name` varchar(64)'
497 . ' NOT NULL, `item_type` varchar(64) NOT NULL, `db_name` varchar(64) NOT NULL,'
498 . ' `table_name` varchar(64) NOT NULL,'
499 . ' PRIMARY KEY (`username`,`item_name`,`item_type`,`db_name`,`table_name`) )'
500 . ' COMMENT=\'Hidden items of navigation tree\' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
503 $this->dummyDbi->addResult(
504 '-- -------------------------------------------------------- -- --'
505 . ' Table structure for table `pma__savedsearches`'
506 . ' -- CREATE TABLE IF NOT EXISTS `pma__savedsearches` ( '
507 . '`id` int(5) unsigned NOT NULL auto_increment, `username` varchar(64) NOT NULL default \'\','
508 . ' `db_name` varchar(64) NOT NULL default \'\', `search_name` varchar(64) NOT NULL default \'\','
509 . ' `search_data` text NOT NULL, PRIMARY KEY (`id`),'
510 . ' UNIQUE KEY `u_savedsearches_username_dbname` (`username`,`db_name`,`search_name`) )'
511 . ' COMMENT=\'Saved searches\' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
514 $this->dummyDbi->addResult(
515 '-- -------------------------------------------------------- -- --'
516 . ' Table structure for table `pma__central_columns`'
517 . ' -- CREATE TABLE IF NOT EXISTS `pma__central_columns` ( '
518 . '`db_name` varchar(64) NOT NULL, `col_name` varchar(64) NOT NULL, `col_type` varchar(64) NOT NULL,'
519 . ' `col_length` text, `col_collation` varchar(64) NOT NULL, `col_isNull` boolean NOT NULL,'
520 . ' `col_extra` varchar(255) default \'\', `col_default` text,'
521 . ' PRIMARY KEY (`db_name`,`col_name`) )'
522 . ' COMMENT=\'Central list of columns\' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
525 $this->dummyDbi->addResult(
526 '-- -------------------------------------------------------- -- --'
527 . ' Table structure for table `pma__designer_settings`'
528 . ' -- CREATE TABLE IF NOT EXISTS `pma__designer_settings` ( '
529 . '`username` varchar(64) NOT NULL, `settings_data` text NOT NULL,'
530 . ' PRIMARY KEY (`username`) )'
531 . ' COMMENT=\'Settings related to Designer\' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
534 $this->dummyDbi->addResult(
535 '-- -------------------------------------------------------- -- --'
536 . ' Table structure for table `pma__export_templates`'
537 . ' -- CREATE TABLE IF NOT EXISTS `pma__export_templates` ( '
538 . '`id` int(5) unsigned NOT NULL AUTO_INCREMENT, `username` varchar(64) NOT NULL,'
539 . ' `export_type` varchar(10) NOT NULL, `template_name` varchar(64) NOT NULL,'
540 . ' `template_data` text NOT NULL, PRIMARY KEY (`id`),'
541 . ' UNIQUE KEY `u_user_type_template` (`username`,`export_type`,`template_name`) )'
542 . ' COMMENT=\'Saved export templates\' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
546 $this->assertSame('', $GLOBALS['cfg']['Server']['pmadb']);
548 $_SESSION['relation'] = [];
550 $this->relation->fixPmaTables('db_pma', true);
551 $this->assertArrayNotHasKey('message', $GLOBALS);
552 $this->assertArrayHasKey($GLOBALS['server'], $_SESSION['relation'], 'The cache is expected to be filled');
553 /** @psalm-suppress EmptyArrayAccess */
554 $this->assertIsArray($_SESSION['relation'][$GLOBALS['server']]);
555 $this->assertSame('db_pma', $GLOBALS['cfg']['Server']['pmadb']);
557 $relationParameters = RelationParameters::fromArray([
558 'db' => 'db_pma',
559 'userconfigwork' => true,
560 'userconfig' => 'pma__userconfig',
562 $this->assertSame($relationParameters->toArray(), $_SESSION['relation'][$GLOBALS['server']]);
564 $this->assertAllQueriesConsumed();
565 $this->assertAllSelectsConsumed();
568 public function testFixPmaTablesNormalFixTablesWithCustomOverride(): void
570 parent::setGlobalDbi();
572 $GLOBALS['db'] = '';
573 $GLOBALS['server'] = 1;
574 $GLOBALS['cfg']['Server']['user'] = '';
575 $GLOBALS['cfg']['Server']['pmadb'] = 'db_pma';
576 $GLOBALS['cfg']['Server']['bookmarktable'] = '';
577 $GLOBALS['cfg']['Server']['relation'] = 'custom_relation_pma';
578 $GLOBALS['cfg']['Server']['table_info'] = '';
579 $GLOBALS['cfg']['Server']['table_coords'] = '';
580 $GLOBALS['cfg']['Server']['column_info'] = '';
581 $GLOBALS['cfg']['Server']['pdf_pages'] = '';
582 $GLOBALS['cfg']['Server']['history'] = '';
583 $GLOBALS['cfg']['Server']['recent'] = '';
584 $GLOBALS['cfg']['Server']['favorite'] = '';
585 $GLOBALS['cfg']['Server']['table_uiprefs'] = '';
586 $GLOBALS['cfg']['Server']['tracking'] = '';
587 $GLOBALS['cfg']['Server']['userconfig'] = '';
588 $GLOBALS['cfg']['Server']['users'] = '';
589 $GLOBALS['cfg']['Server']['usergroups'] = '';
590 $GLOBALS['cfg']['Server']['navigationhiding'] = '';
591 $GLOBALS['cfg']['Server']['savedsearches'] = '';
592 $GLOBALS['cfg']['Server']['central_columns'] = '';
593 $GLOBALS['cfg']['Server']['designer_settings'] = '';
594 $GLOBALS['cfg']['Server']['export_templates'] = '';
596 $this->relation = new Relation($this->dbi);
598 $this->dummyDbi->removeDefaultResults();
599 $this->dummyDbi->addResult(
600 'SHOW TABLES FROM `db_pma`;',
602 ['pma__userconfig'],
603 // This is important as it tricks default existing table detection
604 // If the check does not consider the custom name it will skip the table
605 ['pma__relation'],
607 ['Tables_in_db_pma']
610 $this->dummyDbi->addResult(
611 'SHOW TABLES FROM `db_pma`',
613 ['pma__userconfig'],
614 // This is important as it tricks default existing table detection
615 // If the check does not consider the custom name it will skip the table
616 ['pma__relation'],
618 ['Tables_in_db_pma']
621 $this->dummyDbi->addResult(
622 'SELECT NULL FROM `pma__userconfig` LIMIT 0',
623 [['NULL']]
626 $this->dummyDbi->addResult(
627 '-- -------------------------------------------------------- -- --'
628 . ' Table structure for table `pma__bookmark` '
629 . '-- CREATE TABLE IF NOT EXISTS `pma__bookmark` ( '
630 . '`id` int(10) unsigned NOT NULL auto_increment,'
631 . ' `dbase` varchar(255) NOT NULL default \'\','
632 . ' `user` varchar(255) NOT NULL default \'\','
633 . ' `label` varchar(255) COLLATE utf8_general_ci NOT NULL default \'\','
634 . ' `query` text NOT NULL, PRIMARY KEY (`id`) )'
635 . ' COMMENT=\'Bookmarks\' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
638 $this->dummyDbi->addResult(
639 '-- -------------------------------------------------------- -- --'
640 . ' Table structure for table `custom_relation_pma` '
641 . '-- CREATE TABLE IF NOT EXISTS `custom_relation_pma` ( '
642 . '`master_db` varchar(64) NOT NULL default \'\', `master_table` varchar(64) NOT NULL default \'\','
643 . ' `master_field` varchar(64) NOT NULL default \'\', `foreign_db` varchar(64) NOT NULL default \'\','
644 . ' `foreign_table` varchar(64) NOT NULL default \'\','
645 . ' `foreign_field` varchar(64) NOT NULL default \'\','
646 . ' PRIMARY KEY (`master_db`,`master_table`,`master_field`),'
647 . ' KEY `foreign_field` (`foreign_db`,`foreign_table`) ) COMMENT=\'Relation table\''
648 . ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
651 $this->dummyDbi->addResult(
652 '-- -------------------------------------------------------- -- --'
653 . ' Table structure for table `pma__table_info`'
654 . ' -- CREATE TABLE IF NOT EXISTS `pma__table_info` ( '
655 . '`db_name` varchar(64) NOT NULL default \'\', `table_name` varchar(64) NOT NULL default \'\','
656 . ' `display_field` varchar(64) NOT NULL default \'\', PRIMARY KEY (`db_name`,`table_name`) )'
657 . ' COMMENT=\'Table information for phpMyAdmin\' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
661 $this->dummyDbi->addResult(
662 '-- -------------------------------------------------------- -- --'
663 . ' Table structure for table `pma__table_coords`'
664 . ' -- CREATE TABLE IF NOT EXISTS `pma__table_coords` ( '
665 . '`db_name` varchar(64) NOT NULL default \'\', `table_name` varchar(64) NOT NULL default \'\','
666 . ' `pdf_page_number` int(11) NOT NULL default \'0\', `x` float unsigned NOT NULL default \'0\','
667 . ' `y` float unsigned NOT NULL default \'0\','
668 . ' PRIMARY KEY (`db_name`,`table_name`,`pdf_page_number`) )'
669 . ' COMMENT=\'Table coordinates for phpMyAdmin PDF output\''
670 . ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
673 $this->dummyDbi->addResult(
674 '-- -------------------------------------------------------- -- --'
675 . ' Table structure for table `pma__pdf_pages`'
676 . ' -- CREATE TABLE IF NOT EXISTS `pma__pdf_pages` ( '
677 . '`db_name` varchar(64) NOT NULL default \'\', `page_nr` int(10) unsigned NOT NULL auto_increment,'
678 . ' `page_descr` varchar(50) COLLATE utf8_general_ci NOT NULL default \'\', PRIMARY KEY (`page_nr`),'
679 . ' KEY `db_name` (`db_name`) ) COMMENT=\'PDF relation pages for phpMyAdmin\''
680 . ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
683 $this->dummyDbi->addResult(
684 '-- -------------------------------------------------------- -- --'
685 . ' Table structure for table `pma__column_info`'
686 . ' -- CREATE TABLE IF NOT EXISTS `pma__column_info` ( '
687 . '`id` int(5) unsigned NOT NULL auto_increment, `db_name` varchar(64) NOT NULL default \'\','
688 . ' `table_name` varchar(64) NOT NULL default \'\', `column_name` varchar(64) NOT NULL default \'\','
689 . ' `comment` varchar(255) COLLATE utf8_general_ci NOT NULL default \'\','
690 . ' `mimetype` varchar(255) COLLATE utf8_general_ci NOT NULL default \'\','
691 . ' `transformation` varchar(255) NOT NULL default \'\','
692 . ' `transformation_options` varchar(255) NOT NULL default \'\','
693 . ' `input_transformation` varchar(255) NOT NULL default \'\','
694 . ' `input_transformation_options` varchar(255) NOT NULL default \'\','
695 . ' PRIMARY KEY (`id`), UNIQUE KEY `db_name` (`db_name`,`table_name`,`column_name`) )'
696 . ' COMMENT=\'Column information for phpMyAdmin\' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
699 $this->dummyDbi->addResult(
700 '-- -------------------------------------------------------- -- --'
701 . ' Table structure for table `pma__history` '
702 . '-- CREATE TABLE IF NOT EXISTS `pma__history` ( '
703 . '`id` bigint(20) unsigned NOT NULL auto_increment, `username` varchar(64) NOT NULL default \'\','
704 . ' `db` varchar(64) NOT NULL default \'\', `table` varchar(64) NOT NULL default \'\','
705 . ' `timevalue` timestamp NOT NULL default CURRENT_TIMESTAMP, `sqlquery` text NOT NULL,'
706 . ' PRIMARY KEY (`id`), KEY `username` (`username`,`db`,`table`,`timevalue`) )'
707 . ' COMMENT=\'SQL history for phpMyAdmin\' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
710 $this->dummyDbi->addResult(
711 '-- -------------------------------------------------------- -- --'
712 . ' Table structure for table `pma__recent` '
713 . '-- CREATE TABLE IF NOT EXISTS `pma__recent` ( '
714 . '`username` varchar(64) NOT NULL, `tables` text NOT NULL, PRIMARY KEY (`username`) )'
715 . ' COMMENT=\'Recently accessed tables\' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
718 $this->dummyDbi->addResult(
719 '-- -------------------------------------------------------- -- --'
720 . ' Table structure for table `pma__favorite` '
721 . '-- CREATE TABLE IF NOT EXISTS `pma__favorite` ( '
722 . '`username` varchar(64) NOT NULL, `tables` text NOT NULL, PRIMARY KEY (`username`) )'
723 . ' COMMENT=\'Favorite tables\' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
726 $this->dummyDbi->addResult(
727 '-- -------------------------------------------------------- -- --'
728 . ' Table structure for table `pma__table_uiprefs`'
729 . ' -- CREATE TABLE IF NOT EXISTS `pma__table_uiprefs` ( '
730 . '`username` varchar(64) NOT NULL, `db_name` varchar(64) NOT NULL,'
731 . ' `table_name` varchar(64) NOT NULL, `prefs` text NOT NULL,'
732 . ' `last_update` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,'
733 . ' PRIMARY KEY (`username`,`db_name`,`table_name`) ) COMMENT=\'Tables\'\' UI preferences\''
734 . ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
737 $this->dummyDbi->addResult(
738 '-- -------------------------------------------------------- -- --'
739 . ' Table structure for table `pma__tracking` '
740 . '-- CREATE TABLE IF NOT EXISTS `pma__tracking` ( '
741 . '`db_name` varchar(64) NOT NULL, `table_name` varchar(64) NOT NULL,'
742 . ' `version` int(10) unsigned NOT NULL, `date_created` datetime NOT NULL,'
743 . ' `date_updated` datetime NOT NULL, `schema_snapshot` text NOT NULL,'
744 . ' `schema_sql` text, `data_sql` longtext, `tracking`'
745 . ' set(\'UPDATE\',\'REPLACE\',\'INSERT\',\'DELETE\','
746 . '\'TRUNCATE\',\'CREATE DATABASE\',\'ALTER DATABASE\','
747 . '\'DROP DATABASE\',\'CREATE TABLE\',\'ALTER TABLE\','
748 . '\'RENAME TABLE\',\'DROP TABLE\',\'CREATE INDEX\','
749 . '\'DROP INDEX\',\'CREATE VIEW\',\'ALTER VIEW\',\'DROP VIEW\')'
750 . ' default NULL, `tracking_active` int(1) unsigned NOT NULL'
751 . ' default \'1\', PRIMARY KEY (`db_name`,`table_name`,`version`) )'
752 . ' COMMENT=\'Database changes tracking for phpMyAdmin\''
753 . ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
756 $this->dummyDbi->addResult(
757 '-- -------------------------------------------------------- -- --'
758 . ' Table structure for table `pma__users` '
759 . '-- CREATE TABLE IF NOT EXISTS `pma__users` ( '
760 . '`username` varchar(64) NOT NULL, `usergroup` varchar(64) NOT NULL,'
761 . ' PRIMARY KEY (`username`,`usergroup`) )'
762 . ' COMMENT=\'Users and their assignments to user groups\''
763 . ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
766 $this->dummyDbi->addResult(
767 '-- -------------------------------------------------------- -- --'
768 . ' Table structure for table `pma__usergroups`'
769 . ' -- CREATE TABLE IF NOT EXISTS `pma__usergroups` ( '
770 . '`usergroup` varchar(64) NOT NULL, `tab` varchar(64) NOT NULL,'
771 . ' `allowed` enum(\'Y\',\'N\') NOT NULL DEFAULT \'N\','
772 . ' PRIMARY KEY (`usergroup`,`tab`,`allowed`) )'
773 . ' COMMENT=\'User groups with configured menu items\''
774 . ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
777 $this->dummyDbi->addResult(
778 '-- -------------------------------------------------------- -- --'
779 . ' Table structure for table `pma__navigationhiding`'
780 . ' -- CREATE TABLE IF NOT EXISTS `pma__navigationhiding` ( '
781 . '`username` varchar(64) NOT NULL, `item_name` varchar(64)'
782 . ' NOT NULL, `item_type` varchar(64) NOT NULL, `db_name` varchar(64) NOT NULL,'
783 . ' `table_name` varchar(64) NOT NULL,'
784 . ' PRIMARY KEY (`username`,`item_name`,`item_type`,`db_name`,`table_name`) )'
785 . ' COMMENT=\'Hidden items of navigation tree\' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
788 $this->dummyDbi->addResult(
789 '-- -------------------------------------------------------- -- --'
790 . ' Table structure for table `pma__savedsearches`'
791 . ' -- CREATE TABLE IF NOT EXISTS `pma__savedsearches` ( '
792 . '`id` int(5) unsigned NOT NULL auto_increment, `username` varchar(64) NOT NULL default \'\','
793 . ' `db_name` varchar(64) NOT NULL default \'\', `search_name` varchar(64) NOT NULL default \'\','
794 . ' `search_data` text NOT NULL, PRIMARY KEY (`id`),'
795 . ' UNIQUE KEY `u_savedsearches_username_dbname` (`username`,`db_name`,`search_name`) )'
796 . ' COMMENT=\'Saved searches\' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
799 $this->dummyDbi->addResult(
800 '-- -------------------------------------------------------- -- --'
801 . ' Table structure for table `pma__central_columns`'
802 . ' -- CREATE TABLE IF NOT EXISTS `pma__central_columns` ( '
803 . '`db_name` varchar(64) NOT NULL, `col_name` varchar(64) NOT NULL, `col_type` varchar(64) NOT NULL,'
804 . ' `col_length` text, `col_collation` varchar(64) NOT NULL, `col_isNull` boolean NOT NULL,'
805 . ' `col_extra` varchar(255) default \'\', `col_default` text,'
806 . ' PRIMARY KEY (`db_name`,`col_name`) )'
807 . ' COMMENT=\'Central list of columns\' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
810 $this->dummyDbi->addResult(
811 '-- -------------------------------------------------------- -- --'
812 . ' Table structure for table `pma__designer_settings`'
813 . ' -- CREATE TABLE IF NOT EXISTS `pma__designer_settings` ( '
814 . '`username` varchar(64) NOT NULL, `settings_data` text NOT NULL,'
815 . ' PRIMARY KEY (`username`) )'
816 . ' COMMENT=\'Settings related to Designer\' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
819 $this->dummyDbi->addResult(
820 '-- -------------------------------------------------------- -- --'
821 . ' Table structure for table `pma__export_templates`'
822 . ' -- CREATE TABLE IF NOT EXISTS `pma__export_templates` ( '
823 . '`id` int(5) unsigned NOT NULL AUTO_INCREMENT, `username` varchar(64) NOT NULL,'
824 . ' `export_type` varchar(10) NOT NULL, `template_name` varchar(64) NOT NULL,'
825 . ' `template_data` text NOT NULL, PRIMARY KEY (`id`),'
826 . ' UNIQUE KEY `u_user_type_template` (`username`,`export_type`,`template_name`) )'
827 . ' COMMENT=\'Saved export templates\' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
831 $this->assertSame('db_pma', $GLOBALS['cfg']['Server']['pmadb']);
833 $_SESSION['relation'] = [];
835 $this->dummyDbi->addSelectDb('db_pma');
836 $this->dummyDbi->addSelectDb('db_pma');
837 $this->relation->fixPmaTables('db_pma', true);
838 $this->assertArrayNotHasKey('message', $GLOBALS);
839 $this->assertArrayHasKey($GLOBALS['server'], $_SESSION['relation'], 'The cache is expected to be filled');
840 /** @psalm-suppress EmptyArrayAccess */
841 $this->assertIsArray($_SESSION['relation'][$GLOBALS['server']]);
842 $this->assertSame('db_pma', $GLOBALS['cfg']['Server']['pmadb']);
844 $relationParameters = RelationParameters::fromArray([
845 'db' => 'db_pma',
846 'userconfigwork' => true,
847 'userconfig' => 'pma__userconfig',
849 $this->assertSame($relationParameters->toArray(), $_SESSION['relation'][$GLOBALS['server']]);
851 $this->assertAllQueriesConsumed();
852 $this->assertAllSelectsConsumed();
855 public function testFixPmaTablesNormalFixTablesFails(): void
857 parent::setGlobalDbi();
859 $GLOBALS['db'] = '';
860 $GLOBALS['server'] = 1;
861 $GLOBALS['cfg']['Server']['user'] = '';
862 $GLOBALS['cfg']['Server']['pmadb'] = '';
863 $GLOBALS['cfg']['Server']['bookmarktable'] = '';
864 $GLOBALS['cfg']['Server']['relation'] = '';
865 $GLOBALS['cfg']['Server']['table_info'] = '';
866 $GLOBALS['cfg']['Server']['table_coords'] = '';
867 $GLOBALS['cfg']['Server']['column_info'] = '';
868 $GLOBALS['cfg']['Server']['pdf_pages'] = '';
869 $GLOBALS['cfg']['Server']['history'] = '';
870 $GLOBALS['cfg']['Server']['recent'] = '';
871 $GLOBALS['cfg']['Server']['favorite'] = '';
872 $GLOBALS['cfg']['Server']['table_uiprefs'] = '';
873 $GLOBALS['cfg']['Server']['tracking'] = '';
874 $GLOBALS['cfg']['Server']['userconfig'] = '';
875 $GLOBALS['cfg']['Server']['users'] = '';
876 $GLOBALS['cfg']['Server']['usergroups'] = '';
877 $GLOBALS['cfg']['Server']['navigationhiding'] = '';
878 $GLOBALS['cfg']['Server']['savedsearches'] = '';
879 $GLOBALS['cfg']['Server']['central_columns'] = '';
880 $GLOBALS['cfg']['Server']['designer_settings'] = '';
881 $GLOBALS['cfg']['Server']['export_templates'] = '';
883 $this->relation = new Relation($this->dbi);
885 $this->dummyDbi->removeDefaultResults();
886 $this->dummyDbi->addResult(
887 'SHOW TABLES FROM `db_pma`;',
889 ['pma__userconfig'],
891 ['Tables_in_db_pma']
894 // Fail the query
895 $this->dummyDbi->addErrorCode('MYSQL_ERROR');
896 $this->dummyDbi->addResult(
897 '-- -------------------------------------------------------- -- --'
898 . ' Table structure for table `pma__bookmark` '
899 . '-- CREATE TABLE IF NOT EXISTS `pma__bookmark` ( '
900 . '`id` int(10) unsigned NOT NULL auto_increment,'
901 . ' `dbase` varchar(255) NOT NULL default \'\','
902 . ' `user` varchar(255) NOT NULL default \'\','
903 . ' `label` varchar(255) COLLATE utf8_general_ci NOT NULL default \'\','
904 . ' `query` text NOT NULL, PRIMARY KEY (`id`) )'
905 . ' COMMENT=\'Bookmarks\' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
906 false
908 $this->dummyDbi->addSelectDb('db_pma');
910 $this->assertSame('', $GLOBALS['cfg']['Server']['pmadb']);
912 $_SESSION['relation'] = [];
914 $this->relation->fixPmaTables('db_pma', true);
916 $this->assertArrayHasKey('message', $GLOBALS);
917 $this->assertSame('MYSQL_ERROR', $GLOBALS['message']);
918 $this->assertSame('', $GLOBALS['cfg']['Server']['pmadb']);
920 $this->assertSame([], $_SESSION['relation']);
922 $this->assertAllQueriesConsumed();
923 $this->assertAllErrorCodesConsumed();
924 $this->assertAllSelectsConsumed();
927 public function testCreatePmaDatabase(): void
929 parent::setGlobalDbi();
930 $this->relation = new Relation($this->dbi);
932 $this->dummyDbi->removeDefaultResults();
933 $this->dummyDbi->addResult(
934 'CREATE DATABASE IF NOT EXISTS `phpmyadmin`',
938 $this->dummyDbi->addResult(
939 'SHOW TABLES FROM `phpmyadmin`',
942 $this->dummyDbi->addSelectDb('phpmyadmin');
944 $this->assertArrayNotHasKey('errno', $GLOBALS);
946 $this->assertTrue(
947 $this->relation->createPmaDatabase('phpmyadmin')
950 $this->assertArrayNotHasKey('message', $GLOBALS);
952 $this->assertAllQueriesConsumed();
953 $this->assertAllErrorCodesConsumed();
954 $this->assertAllSelectsConsumed();
957 public function testCreatePmaDatabaseFailsError1044(): void
959 parent::setGlobalDbi();
960 $this->relation = new Relation($this->dbi);
962 $this->dummyDbi->removeDefaultResults();
963 $this->dummyDbi->addErrorCode('MYSQL_ERROR');
964 $this->dummyDbi->addResult('CREATE DATABASE IF NOT EXISTS `phpmyadmin`', false);
966 $GLOBALS['errno'] = 1044;// ER_DBACCESS_DENIED_ERROR
968 $this->assertFalse(
969 $this->relation->createPmaDatabase('phpmyadmin')
972 $this->assertArrayHasKey('message', $GLOBALS);
973 $this->assertSame(
974 'You do not have necessary privileges to create a database named'
975 . ' \'phpmyadmin\'. You may go to \'Operations\' tab of any'
976 . ' database to set up the phpMyAdmin configuration storage there.',
977 $GLOBALS['message']
980 $this->assertAllQueriesConsumed();
981 $this->assertAllErrorCodesConsumed();
984 public function testCreatePmaDatabaseFailsError1040(): void
986 parent::setGlobalDbi();
987 $this->relation = new Relation($this->dbi);
989 $this->dummyDbi->removeDefaultResults();
990 $this->dummyDbi->addErrorCode('Too many connections');
991 $this->dummyDbi->addResult('CREATE DATABASE IF NOT EXISTS `pma_1040`', false);
993 $GLOBALS['errno'] = 1040;
995 $this->assertFalse(
996 $this->relation->createPmaDatabase('pma_1040')
999 $this->assertArrayHasKey('message', $GLOBALS);
1000 $this->assertSame('Too many connections', $GLOBALS['message']);
1002 $this->assertAllQueriesConsumed();
1003 $this->assertAllErrorCodesConsumed();
1006 public function testGetDefaultPmaTableNames(): void
1008 $this->relation = new Relation($this->dbi);
1010 $data = [
1011 'pma__bookmark' => implode("\n", [
1014 '-- --------------------------------------------------------',
1016 '--',
1017 '-- Table structure for table `pma__bookmark`',
1018 '--',
1020 'CREATE TABLE IF NOT EXISTS `pma__bookmark` (',
1021 ' `id` int(10) unsigned NOT NULL auto_increment,',
1022 ' `dbase` varchar(255) NOT NULL default \'\',',
1023 ' `user` varchar(255) NOT NULL default \'\',',
1024 ' `label` varchar(255) COLLATE utf8_general_ci NOT NULL default \'\',',
1025 ' `query` text NOT NULL,',
1026 ' PRIMARY KEY (`id`)',
1027 ')',
1028 ' COMMENT=\'Bookmarks\'',
1029 ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
1031 'pma__column_info' => implode("\n", [
1034 '-- --------------------------------------------------------',
1036 '--',
1037 '-- Table structure for table `pma__column_info`',
1038 '--',
1040 'CREATE TABLE IF NOT EXISTS `pma__column_info` (',
1041 ' `id` int(5) unsigned NOT NULL auto_increment,',
1042 ' `db_name` varchar(64) NOT NULL default \'\',',
1043 ' `table_name` varchar(64) NOT NULL default \'\',',
1044 ' `column_name` varchar(64) NOT NULL default \'\',',
1045 ' `comment` varchar(255) COLLATE utf8_general_ci NOT NULL default \'\',',
1046 ' `mimetype` varchar(255) COLLATE utf8_general_ci NOT NULL default \'\',',
1047 ' `transformation` varchar(255) NOT NULL default \'\',',
1048 ' `transformation_options` varchar(255) NOT NULL default \'\',',
1049 ' `input_transformation` varchar(255) NOT NULL default \'\',',
1050 ' `input_transformation_options` varchar(255) NOT NULL default \'\',',
1051 ' PRIMARY KEY (`id`),',
1052 ' UNIQUE KEY `db_name` (`db_name`,`table_name`,`column_name`)',
1053 ')',
1054 ' COMMENT=\'Column information for phpMyAdmin\'',
1055 ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
1057 'pma__history' => implode("\n", [
1060 '-- --------------------------------------------------------',
1062 '--',
1063 '-- Table structure for table `pma__history`',
1064 '--',
1066 'CREATE TABLE IF NOT EXISTS `pma__history` (',
1067 ' `id` bigint(20) unsigned NOT NULL auto_increment,',
1068 ' `username` varchar(64) NOT NULL default \'\',',
1069 ' `db` varchar(64) NOT NULL default \'\',',
1070 ' `table` varchar(64) NOT NULL default \'\',',
1071 ' `timevalue` timestamp NOT NULL default CURRENT_TIMESTAMP,',
1072 ' `sqlquery` text NOT NULL,',
1073 ' PRIMARY KEY (`id`),',
1074 ' KEY `username` (`username`,`db`,`table`,`timevalue`)',
1075 ')',
1076 ' COMMENT=\'SQL history for phpMyAdmin\'',
1077 ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
1079 'pma__pdf_pages' => implode("\n", [
1082 '-- --------------------------------------------------------',
1084 '--',
1085 '-- Table structure for table `pma__pdf_pages`',
1086 '--',
1088 'CREATE TABLE IF NOT EXISTS `pma__pdf_pages` (',
1089 ' `db_name` varchar(64) NOT NULL default \'\',',
1090 ' `page_nr` int(10) unsigned NOT NULL auto_increment,',
1091 ' `page_descr` varchar(50) COLLATE utf8_general_ci NOT NULL default \'\',',
1092 ' PRIMARY KEY (`page_nr`),',
1093 ' KEY `db_name` (`db_name`)',
1094 ')',
1095 ' COMMENT=\'PDF relation pages for phpMyAdmin\'',
1096 ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
1098 'pma__recent' => implode("\n", [
1101 '-- --------------------------------------------------------',
1103 '--',
1104 '-- Table structure for table `pma__recent`',
1105 '--',
1107 'CREATE TABLE IF NOT EXISTS `pma__recent` (',
1108 ' `username` varchar(64) NOT NULL,',
1109 ' `tables` text NOT NULL,',
1110 ' PRIMARY KEY (`username`)',
1111 ')',
1112 ' COMMENT=\'Recently accessed tables\'',
1113 ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
1115 'pma__favorite' => implode("\n", [
1118 '-- --------------------------------------------------------',
1120 '--',
1121 '-- Table structure for table `pma__favorite`',
1122 '--',
1124 'CREATE TABLE IF NOT EXISTS `pma__favorite` (',
1125 ' `username` varchar(64) NOT NULL,',
1126 ' `tables` text NOT NULL,',
1127 ' PRIMARY KEY (`username`)',
1128 ')',
1129 ' COMMENT=\'Favorite tables\'',
1130 ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
1132 'pma__table_uiprefs' => implode("\n", [
1135 '-- --------------------------------------------------------',
1137 '--',
1138 '-- Table structure for table `pma__table_uiprefs`',
1139 '--',
1141 'CREATE TABLE IF NOT EXISTS `pma__table_uiprefs` (',
1142 ' `username` varchar(64) NOT NULL,',
1143 ' `db_name` varchar(64) NOT NULL,',
1144 ' `table_name` varchar(64) NOT NULL,',
1145 ' `prefs` text NOT NULL,',
1146 ' `last_update` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,',
1147 ' PRIMARY KEY (`username`,`db_name`,`table_name`)',
1148 ')',
1149 ' COMMENT=\'Tables\'\' UI preferences\'',
1150 ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
1152 'pma__relation' => implode("\n", [
1155 '-- --------------------------------------------------------',
1157 '--',
1158 '-- Table structure for table `pma__relation`',
1159 '--',
1161 'CREATE TABLE IF NOT EXISTS `pma__relation` (',
1162 ' `master_db` varchar(64) NOT NULL default \'\',',
1163 ' `master_table` varchar(64) NOT NULL default \'\',',
1164 ' `master_field` varchar(64) NOT NULL default \'\',',
1165 ' `foreign_db` varchar(64) NOT NULL default \'\',',
1166 ' `foreign_table` varchar(64) NOT NULL default \'\',',
1167 ' `foreign_field` varchar(64) NOT NULL default \'\',',
1168 ' PRIMARY KEY (`master_db`,`master_table`,`master_field`),',
1169 ' KEY `foreign_field` (`foreign_db`,`foreign_table`)',
1170 ')',
1171 ' COMMENT=\'Relation table\'',
1172 ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
1174 'pma__table_coords' => implode("\n", [
1177 '-- --------------------------------------------------------',
1179 '--',
1180 '-- Table structure for table `pma__table_coords`',
1181 '--',
1183 'CREATE TABLE IF NOT EXISTS `pma__table_coords` (',
1184 ' `db_name` varchar(64) NOT NULL default \'\',',
1185 ' `table_name` varchar(64) NOT NULL default \'\',',
1186 ' `pdf_page_number` int(11) NOT NULL default \'0\',',
1187 ' `x` float unsigned NOT NULL default \'0\',',
1188 ' `y` float unsigned NOT NULL default \'0\',',
1189 ' PRIMARY KEY (`db_name`,`table_name`,`pdf_page_number`)',
1190 ')',
1191 ' COMMENT=\'Table coordinates for phpMyAdmin PDF output\'',
1192 ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
1194 'pma__table_info' => implode("\n", [
1197 '-- --------------------------------------------------------',
1199 '--',
1200 '-- Table structure for table `pma__table_info`',
1201 '--',
1203 'CREATE TABLE IF NOT EXISTS `pma__table_info` (',
1204 ' `db_name` varchar(64) NOT NULL default \'\',',
1205 ' `table_name` varchar(64) NOT NULL default \'\',',
1206 ' `display_field` varchar(64) NOT NULL default \'\',',
1207 ' PRIMARY KEY (`db_name`,`table_name`)',
1208 ')',
1209 ' COMMENT=\'Table information for phpMyAdmin\'',
1210 ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
1212 'pma__tracking' => implode("\n", [
1215 '-- --------------------------------------------------------',
1217 '--',
1218 '-- Table structure for table `pma__tracking`',
1219 '--',
1221 'CREATE TABLE IF NOT EXISTS `pma__tracking` (',
1222 ' `db_name` varchar(64) NOT NULL,',
1223 ' `table_name` varchar(64) NOT NULL,',
1224 ' `version` int(10) unsigned NOT NULL,',
1225 ' `date_created` datetime NOT NULL,',
1226 ' `date_updated` datetime NOT NULL,',
1227 ' `schema_snapshot` text NOT NULL,',
1228 ' `schema_sql` text,',
1229 ' `data_sql` longtext,',
1230 ' `tracking` set(\'UPDATE\',\'REPLACE\',\'INSERT\',\'DELETE\','
1231 . '\'TRUNCATE\',\'CREATE DATABASE\',\'ALTER DATABASE\',\'DROP DATABASE\','
1232 . '\'CREATE TABLE\',\'ALTER TABLE\',\'RENAME TABLE\',\'DROP TABLE\','
1233 . '\'CREATE INDEX\',\'DROP INDEX\',\'CREATE VIEW\',\'ALTER VIEW\','
1234 . '\'DROP VIEW\') default NULL,',
1235 ' `tracking_active` int(1) unsigned NOT NULL default \'1\',',
1236 ' PRIMARY KEY (`db_name`,`table_name`,`version`)',
1237 ')',
1238 ' COMMENT=\'Database changes tracking for phpMyAdmin\'',
1239 ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
1241 'pma__userconfig' => implode("\n", [
1244 '-- --------------------------------------------------------',
1246 '--',
1247 '-- Table structure for table `pma__userconfig`',
1248 '--',
1250 'CREATE TABLE IF NOT EXISTS `pma__userconfig` (',
1251 ' `username` varchar(64) NOT NULL,',
1252 ' `timevalue` timestamp NOT NULL default CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,',
1253 ' `config_data` text NOT NULL,',
1254 ' PRIMARY KEY (`username`)',
1255 ')',
1256 ' COMMENT=\'User preferences storage for phpMyAdmin\'',
1257 ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
1259 'pma__users' => implode("\n", [
1262 '-- --------------------------------------------------------',
1264 '--',
1265 '-- Table structure for table `pma__users`',
1266 '--',
1268 'CREATE TABLE IF NOT EXISTS `pma__users` (',
1269 ' `username` varchar(64) NOT NULL,',
1270 ' `usergroup` varchar(64) NOT NULL,',
1271 ' PRIMARY KEY (`username`,`usergroup`)',
1272 ')',
1273 ' COMMENT=\'Users and their assignments to user groups\'',
1274 ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
1276 'pma__usergroups' => implode("\n", [
1279 '-- --------------------------------------------------------',
1281 '--',
1282 '-- Table structure for table `pma__usergroups`',
1283 '--',
1285 'CREATE TABLE IF NOT EXISTS `pma__usergroups` (',
1286 ' `usergroup` varchar(64) NOT NULL,',
1287 ' `tab` varchar(64) NOT NULL,',
1288 ' `allowed` enum(\'Y\',\'N\') NOT NULL DEFAULT \'N\',',
1289 ' PRIMARY KEY (`usergroup`,`tab`,`allowed`)',
1290 ')',
1291 ' COMMENT=\'User groups with configured menu items\'',
1292 ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
1294 'pma__navigationhiding' => implode("\n", [
1297 '-- --------------------------------------------------------',
1299 '--',
1300 '-- Table structure for table `pma__navigationhiding`',
1301 '--',
1303 'CREATE TABLE IF NOT EXISTS `pma__navigationhiding` (',
1304 ' `username` varchar(64) NOT NULL,',
1305 ' `item_name` varchar(64) NOT NULL,',
1306 ' `item_type` varchar(64) NOT NULL,',
1307 ' `db_name` varchar(64) NOT NULL,',
1308 ' `table_name` varchar(64) NOT NULL,',
1309 ' PRIMARY KEY (`username`,`item_name`,`item_type`,`db_name`,`table_name`)',
1310 ')',
1311 ' COMMENT=\'Hidden items of navigation tree\'',
1312 ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
1314 'pma__savedsearches' => implode("\n", [
1317 '-- --------------------------------------------------------',
1319 '--',
1320 '-- Table structure for table `pma__savedsearches`',
1321 '--',
1323 'CREATE TABLE IF NOT EXISTS `pma__savedsearches` (',
1324 ' `id` int(5) unsigned NOT NULL auto_increment,',
1325 ' `username` varchar(64) NOT NULL default \'\',',
1326 ' `db_name` varchar(64) NOT NULL default \'\',',
1327 ' `search_name` varchar(64) NOT NULL default \'\',',
1328 ' `search_data` text NOT NULL,',
1329 ' PRIMARY KEY (`id`),',
1330 ' UNIQUE KEY `u_savedsearches_username_dbname` (`username`,`db_name`,`search_name`)',
1331 ')',
1332 ' COMMENT=\'Saved searches\'',
1333 ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
1335 'pma__central_columns' => implode("\n", [
1338 '-- --------------------------------------------------------',
1340 '--',
1341 '-- Table structure for table `pma__central_columns`',
1342 '--',
1344 'CREATE TABLE IF NOT EXISTS `pma__central_columns` (',
1345 ' `db_name` varchar(64) NOT NULL,',
1346 ' `col_name` varchar(64) NOT NULL,',
1347 ' `col_type` varchar(64) NOT NULL,',
1348 ' `col_length` text,',
1349 ' `col_collation` varchar(64) NOT NULL,',
1350 ' `col_isNull` boolean NOT NULL,',
1351 ' `col_extra` varchar(255) default \'\',',
1352 ' `col_default` text,',
1353 ' PRIMARY KEY (`db_name`,`col_name`)',
1354 ')',
1355 ' COMMENT=\'Central list of columns\'',
1356 ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
1358 'pma__designer_settings' => implode("\n", [
1361 '-- --------------------------------------------------------',
1363 '--',
1364 '-- Table structure for table `pma__designer_settings`',
1365 '--',
1367 'CREATE TABLE IF NOT EXISTS `pma__designer_settings` (',
1368 ' `username` varchar(64) NOT NULL,',
1369 ' `settings_data` text NOT NULL,',
1370 ' PRIMARY KEY (`username`)',
1371 ')',
1372 ' COMMENT=\'Settings related to Designer\'',
1373 ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
1375 'pma__export_templates' => implode("\n", [
1378 '-- --------------------------------------------------------',
1380 '--',
1381 '-- Table structure for table `pma__export_templates`',
1382 '--',
1384 'CREATE TABLE IF NOT EXISTS `pma__export_templates` (',
1385 ' `id` int(5) unsigned NOT NULL AUTO_INCREMENT,',
1386 ' `username` varchar(64) NOT NULL,',
1387 ' `export_type` varchar(10) NOT NULL,',
1388 ' `template_name` varchar(64) NOT NULL,',
1389 ' `template_data` text NOT NULL,',
1390 ' PRIMARY KEY (`id`),',
1391 ' UNIQUE KEY `u_user_type_template` (`username`,`export_type`,`template_name`)',
1392 ')',
1393 ' COMMENT=\'Saved export templates\'',
1394 ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
1398 $this->assertSame(
1399 $data,
1400 $this->relation->getDefaultPmaTableNames([])
1403 $data['pma__export_templates'] = implode("\n", [
1406 '-- --------------------------------------------------------',
1408 '--',
1409 '-- Table structure for table `db_exporttemplates_pma`',
1410 '--',
1412 'CREATE TABLE IF NOT EXISTS `db_exporttemplates_pma` (',
1413 ' `id` int(5) unsigned NOT NULL AUTO_INCREMENT,',
1414 ' `username` varchar(64) NOT NULL,',
1415 ' `export_type` varchar(10) NOT NULL,',
1416 ' `template_name` varchar(64) NOT NULL,',
1417 ' `template_data` text NOT NULL,',
1418 ' PRIMARY KEY (`id`),',
1419 ' UNIQUE KEY `u_user_type_template` (`username`,`export_type`,`template_name`)',
1420 ')',
1421 ' COMMENT=\'Saved export templates\'',
1422 ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;',
1425 $this->assertSame(
1426 $data,
1427 $this->relation->getDefaultPmaTableNames(['pma__export_templates' => 'db_exporttemplates_pma'])
1431 public function testInitRelationParamsCacheDefaultDbNameDbDoesNotExist(): void
1433 parent::setGlobalDbi();
1435 $GLOBALS['db'] = '';
1436 $GLOBALS['server'] = 0;
1438 $this->dummyDbi->removeDefaultResults();
1439 $this->dummyDbi->addResult('SHOW TABLES FROM `phpmyadmin`;', false);
1441 $relation = new Relation($this->dbi);
1442 $relation->initRelationParamsCache();
1444 $this->assertAllQueriesConsumed();
1447 public function testInitRelationParamsCacheDefaultDbNameDbExistsServerZero(): void
1449 parent::setGlobalDbi();
1451 $GLOBALS['db'] = '';
1452 $GLOBALS['server'] = 0;
1453 $GLOBALS['cfg']['Server'] = [];
1455 $this->dummyDbi->removeDefaultResults();
1456 $this->dummyDbi->addResult(
1457 'SHOW TABLES FROM `phpmyadmin`;',
1459 ['pma__userconfig'],
1461 ['Tables_in_phpmyadmin']
1464 $_SESSION['relation'] = [];
1466 $relation = new Relation($this->dbi);
1467 $relation->initRelationParamsCache();
1469 $this->assertArrayHasKey($GLOBALS['server'], $_SESSION['relation'], 'The cache is expected to be filled');
1470 /** @psalm-suppress EmptyArrayAccess */
1471 $this->assertIsArray($_SESSION['relation'][$GLOBALS['server']]);
1473 // Should all be false for server = 0
1474 $relationParameters = RelationParameters::fromArray([]);
1475 $this->assertSame($relationParameters->toArray(), $_SESSION['relation'][$GLOBALS['server']]);
1477 $this->assertEquals([
1478 'userconfig' => 'pma__userconfig',
1479 'pmadb' => false,// This is the expected value for server = 0
1480 ], $GLOBALS['cfg']['Server']);
1481 $this->assertAllQueriesConsumed();
1484 public function testInitRelationParamsCacheDefaultDbNameDbExistsFirstServer(): void
1486 parent::setGlobalDbi();
1488 $GLOBALS['db'] = '';
1489 $GLOBALS['server'] = 1;
1490 $GLOBALS['cfg']['Server'] = [];
1491 $GLOBALS['cfg']['Server']['user'] = '';
1492 $GLOBALS['cfg']['Server']['pmadb'] = '';
1493 $GLOBALS['cfg']['Server']['bookmarktable'] = '';
1494 $GLOBALS['cfg']['Server']['relation'] = '';
1495 $GLOBALS['cfg']['Server']['table_info'] = '';
1496 $GLOBALS['cfg']['Server']['table_coords'] = '';
1497 $GLOBALS['cfg']['Server']['column_info'] = '';
1498 $GLOBALS['cfg']['Server']['pdf_pages'] = '';
1499 $GLOBALS['cfg']['Server']['history'] = '';
1500 $GLOBALS['cfg']['Server']['recent'] = '';
1501 $GLOBALS['cfg']['Server']['favorite'] = '';
1502 $GLOBALS['cfg']['Server']['table_uiprefs'] = '';
1503 $GLOBALS['cfg']['Server']['tracking'] = '';
1504 $GLOBALS['cfg']['Server']['userconfig'] = '';
1505 $GLOBALS['cfg']['Server']['users'] = '';
1506 $GLOBALS['cfg']['Server']['usergroups'] = '';
1507 $GLOBALS['cfg']['Server']['navigationhiding'] = '';
1508 $GLOBALS['cfg']['Server']['savedsearches'] = '';
1509 $GLOBALS['cfg']['Server']['central_columns'] = '';
1510 $GLOBALS['cfg']['Server']['designer_settings'] = '';
1511 $GLOBALS['cfg']['Server']['export_templates'] = '';
1513 $this->dummyDbi->removeDefaultResults();
1514 $this->dummyDbi->addResult(
1515 'SHOW TABLES FROM `phpmyadmin`;',
1517 ['pma__userconfig'],
1519 ['Tables_in_phpmyadmin']
1522 $this->dummyDbi->addResult(
1523 'SHOW TABLES FROM `phpmyadmin`',
1525 ['pma__userconfig'],
1527 ['Tables_in_phpmyadmin']
1530 $this->dummyDbi->addResult(
1531 'SELECT NULL FROM `pma__userconfig` LIMIT 0',
1533 ['NULL'],
1535 ['NULL']
1538 $_SESSION['relation'] = [];
1540 $this->dummyDbi->addSelectDb('phpmyadmin');
1541 $relation = new Relation($this->dbi);
1542 $relation->initRelationParamsCache();
1543 $this->assertAllSelectsConsumed();
1545 $this->assertArrayHasKey($GLOBALS['server'], $_SESSION['relation'], 'The cache is expected to be filled');
1546 /** @psalm-suppress EmptyArrayAccess */
1547 $this->assertIsArray($_SESSION['relation'][$GLOBALS['server']]);
1549 // Should all be false for server = 0
1550 $relationParameters = RelationParameters::fromArray([
1551 'db' => 'phpmyadmin',
1552 'userconfigwork' => true,
1553 'userconfig' => 'pma__userconfig',
1555 $this->assertSame($relationParameters->toArray(), $_SESSION['relation'][$GLOBALS['server']]);
1557 $this->assertSame([
1558 'user' => '',
1559 'pmadb' => 'phpmyadmin',
1560 'bookmarktable' => '',
1561 'relation' => '',
1562 'table_info' => '',
1563 'table_coords' => '',
1564 'column_info' => '',
1565 'pdf_pages' => '',
1566 'history' => '',
1567 'recent' => '',
1568 'favorite' => '',
1569 'table_uiprefs' => '',
1570 'tracking' => '',
1571 'userconfig' => 'pma__userconfig',
1572 'users' => '',
1573 'usergroups' => '',
1574 'navigationhiding' => '',
1575 'savedsearches' => '',
1576 'central_columns' => '',
1577 'designer_settings' => '',
1578 'export_templates' => '',
1579 ], $GLOBALS['cfg']['Server']);
1581 $this->assertAllQueriesConsumed();
1584 public function testInitRelationParamsCacheDefaultDbNameDbExistsFirstServerNotWorkingTable(): void
1586 parent::setGlobalDbi();
1588 $GLOBALS['db'] = '';
1589 $GLOBALS['server'] = 1;
1590 $GLOBALS['cfg']['Server'] = [];
1591 $GLOBALS['cfg']['Server']['user'] = '';
1592 $GLOBALS['cfg']['Server']['pmadb'] = '';
1593 $GLOBALS['cfg']['Server']['bookmarktable'] = '';
1594 $GLOBALS['cfg']['Server']['relation'] = '';
1595 $GLOBALS['cfg']['Server']['table_info'] = '';
1596 $GLOBALS['cfg']['Server']['table_coords'] = '';
1597 $GLOBALS['cfg']['Server']['column_info'] = '';
1598 $GLOBALS['cfg']['Server']['pdf_pages'] = '';
1599 $GLOBALS['cfg']['Server']['history'] = '';
1600 $GLOBALS['cfg']['Server']['recent'] = '';
1601 $GLOBALS['cfg']['Server']['favorite'] = '';
1602 $GLOBALS['cfg']['Server']['table_uiprefs'] = '';
1603 $GLOBALS['cfg']['Server']['tracking'] = '';
1604 $GLOBALS['cfg']['Server']['userconfig'] = '';
1605 $GLOBALS['cfg']['Server']['users'] = '';
1606 $GLOBALS['cfg']['Server']['usergroups'] = '';
1607 $GLOBALS['cfg']['Server']['navigationhiding'] = '';
1608 $GLOBALS['cfg']['Server']['savedsearches'] = '';
1609 $GLOBALS['cfg']['Server']['central_columns'] = '';
1610 $GLOBALS['cfg']['Server']['designer_settings'] = '';
1611 $GLOBALS['cfg']['Server']['export_templates'] = '';
1613 $this->dummyDbi->removeDefaultResults();
1614 $this->dummyDbi->addResult(
1615 'SHOW TABLES FROM `phpmyadmin`;',
1617 ['pma__userconfig'],
1619 ['Tables_in_phpmyadmin']
1622 $this->dummyDbi->addResult(
1623 'SHOW TABLES FROM `phpmyadmin`',
1625 ['pma__userconfig'],
1627 ['Tables_in_phpmyadmin']
1630 $this->dummyDbi->addResult('SELECT NULL FROM `pma__userconfig` LIMIT 0', false);
1632 $_SESSION['relation'] = [];
1634 $this->dummyDbi->addSelectDb('phpmyadmin');
1635 $relation = new Relation($this->dbi);
1636 $relation->initRelationParamsCache();
1637 $this->assertAllSelectsConsumed();
1639 $this->assertArrayHasKey($GLOBALS['server'], $_SESSION['relation'], 'The cache is expected to be filled');
1640 /** @psalm-suppress EmptyArrayAccess */
1641 $this->assertIsArray($_SESSION['relation'][$GLOBALS['server']]);
1643 $relationParameters = RelationParameters::fromArray([
1644 'db' => 'phpmyadmin',
1645 'userconfigwork' => false,
1646 'userconfig' => 'pma__userconfig',
1648 $this->assertSame($relationParameters->toArray(), $_SESSION['relation'][$GLOBALS['server']]);
1650 $this->assertSame([
1651 'user' => '',
1652 'pmadb' => 'phpmyadmin',
1653 'bookmarktable' => '',
1654 'relation' => '',
1655 'table_info' => '',
1656 'table_coords' => '',
1657 'column_info' => '',
1658 'pdf_pages' => '',
1659 'history' => '',
1660 'recent' => '',
1661 'favorite' => '',
1662 'table_uiprefs' => '',
1663 'tracking' => '',
1664 'userconfig' => 'pma__userconfig',
1665 'users' => '',
1666 'usergroups' => '',
1667 'navigationhiding' => '',
1668 'savedsearches' => '',
1669 'central_columns' => '',
1670 'designer_settings' => '',
1671 'export_templates' => '',
1672 ], $GLOBALS['cfg']['Server']);
1674 $this->assertAllQueriesConsumed();
1677 public function testInitRelationParamsCacheDefaultDbNameDbExistsFirstServerOverride(): void
1679 parent::setGlobalDbi();
1681 $GLOBALS['db'] = '';
1682 $GLOBALS['server'] = 1;
1683 $GLOBALS['cfg']['Server'] = [];
1684 $GLOBALS['cfg']['Server']['user'] = '';
1685 $GLOBALS['cfg']['Server']['pmadb'] = 'PMA-storage';
1686 $GLOBALS['cfg']['Server']['bookmarktable'] = '';
1687 $GLOBALS['cfg']['Server']['relation'] = '';
1688 $GLOBALS['cfg']['Server']['table_info'] = '';
1689 $GLOBALS['cfg']['Server']['table_coords'] = '';
1690 $GLOBALS['cfg']['Server']['column_info'] = '';
1691 $GLOBALS['cfg']['Server']['pdf_pages'] = '';
1692 $GLOBALS['cfg']['Server']['history'] = '';
1693 $GLOBALS['cfg']['Server']['recent'] = '';
1694 $GLOBALS['cfg']['Server']['favorite'] = '';
1695 $GLOBALS['cfg']['Server']['table_uiprefs'] = '';
1696 $GLOBALS['cfg']['Server']['tracking'] = '';
1697 $GLOBALS['cfg']['Server']['userconfig'] = 'pma__userconfig_custom';
1698 $GLOBALS['cfg']['Server']['users'] = '';
1699 $GLOBALS['cfg']['Server']['usergroups'] = '';
1700 $GLOBALS['cfg']['Server']['navigationhiding'] = '';
1701 $GLOBALS['cfg']['Server']['savedsearches'] = '';
1702 $GLOBALS['cfg']['Server']['central_columns'] = '';
1703 $GLOBALS['cfg']['Server']['designer_settings'] = '';
1704 $GLOBALS['cfg']['Server']['export_templates'] = '';
1706 $this->dummyDbi->removeDefaultResults();
1707 $this->dummyDbi->addResult(
1708 'SHOW TABLES FROM `PMA-storage`;',
1711 'pma__userconfig_custom',
1712 'pma__usergroups',
1715 ['Tables_in_PMA-storage']
1718 $this->dummyDbi->addResult(
1719 'SHOW TABLES FROM `PMA-storage`',
1722 'pma__userconfig_custom',
1723 'pma__usergroups',
1726 ['Tables_in_PMA-storage']
1729 $this->dummyDbi->addResult(
1730 'SELECT NULL FROM `pma__userconfig_custom` LIMIT 0',
1732 ['NULL'],
1734 ['NULL']
1737 $this->dummyDbi->addSelectDb('PMA-storage');
1739 $_SESSION['relation'] = [];
1741 $relation = new Relation($this->dbi);
1742 $relation->initRelationParamsCache();
1744 $this->assertArrayHasKey(
1745 'relation',
1746 $_SESSION,
1747 'The cache is expected to be filled because the custom override'
1748 . 'was understood (pma__userconfig vs pma__userconfig_custom)'
1751 $this->assertAllQueriesConsumed();
1752 $this->assertAllSelectsConsumed();
1754 $this->dummyDbi->addResult(
1755 'SHOW TABLES FROM `PMA-storage`',
1758 'pma__userconfig_custom',
1759 'pma__usergroups',
1762 ['Tables_in_PMA-storage']
1765 $this->dummyDbi->addResult(
1766 'SELECT NULL FROM `pma__userconfig_custom` LIMIT 0',
1768 ['NULL'],
1770 ['NULL']
1773 $this->dummyDbi->addSelectDb('PMA-storage');
1774 /** @psalm-suppress EmptyArrayAccess */
1775 unset($_SESSION['relation'][$GLOBALS['server']]);
1776 $relationData = $relation->getRelationParameters();
1777 $this->assertAllSelectsConsumed();
1779 $relationParameters = RelationParameters::fromArray([
1780 'db' => 'PMA-storage',
1781 'userconfigwork' => true,
1782 'userconfig' => 'pma__userconfig_custom',
1784 $this->assertSame($relationParameters->toArray(), $relationData->toArray());
1786 $this->assertSame([
1787 'user' => '',
1788 'pmadb' => 'PMA-storage',
1789 'bookmarktable' => '',
1790 'relation' => '',
1791 'table_info' => '',
1792 'table_coords' => '',
1793 'column_info' => '',
1794 'pdf_pages' => '',
1795 'history' => '',
1796 'recent' => '',
1797 'favorite' => '',
1798 'table_uiprefs' => '',
1799 'tracking' => '',
1800 'userconfig' => 'pma__userconfig_custom',
1801 'users' => '',
1802 'usergroups' => '',
1803 'navigationhiding' => '',
1804 'savedsearches' => '',
1805 'central_columns' => '',
1806 'designer_settings' => '',
1807 'export_templates' => '',
1808 ], $GLOBALS['cfg']['Server']);
1810 $this->assertAllQueriesConsumed();
1813 public function testInitRelationParamsDisabledTracking(): void
1815 parent::setGlobalDbi();
1817 $GLOBALS['db'] = '';
1818 $GLOBALS['server'] = 1;
1819 $GLOBALS['cfg']['Server'] = [];
1820 $GLOBALS['cfg']['Server']['user'] = '';
1821 $GLOBALS['cfg']['Server']['pmadb'] = 'PMA-storage';
1822 $GLOBALS['cfg']['Server']['bookmarktable'] = '';
1823 $GLOBALS['cfg']['Server']['relation'] = '';
1824 $GLOBALS['cfg']['Server']['table_info'] = '';
1825 $GLOBALS['cfg']['Server']['table_coords'] = '';
1826 $GLOBALS['cfg']['Server']['column_info'] = '';
1827 $GLOBALS['cfg']['Server']['pdf_pages'] = '';
1828 $GLOBALS['cfg']['Server']['history'] = '';
1829 $GLOBALS['cfg']['Server']['recent'] = '';
1830 $GLOBALS['cfg']['Server']['favorite'] = '';
1831 $GLOBALS['cfg']['Server']['table_uiprefs'] = '';
1832 $GLOBALS['cfg']['Server']['tracking'] = false;
1833 $GLOBALS['cfg']['Server']['userconfig'] = '';
1834 $GLOBALS['cfg']['Server']['users'] = '';
1835 $GLOBALS['cfg']['Server']['usergroups'] = '';
1836 $GLOBALS['cfg']['Server']['navigationhiding'] = '';
1837 $GLOBALS['cfg']['Server']['savedsearches'] = '';
1838 $GLOBALS['cfg']['Server']['central_columns'] = '';
1839 $GLOBALS['cfg']['Server']['designer_settings'] = '';
1840 $GLOBALS['cfg']['Server']['export_templates'] = '';
1842 $this->dummyDbi->removeDefaultResults();
1843 $this->dummyDbi->addResult(
1844 'SHOW TABLES FROM `PMA-storage`;',
1846 ['pma__tracking'],
1848 ['Tables_in_PMA-storage']
1851 $_SESSION['relation'] = [];
1853 $relation = new Relation($this->dbi);
1854 $relation->initRelationParamsCache();
1856 $this->assertArrayHasKey(
1857 'relation',
1858 $_SESSION,
1859 'The cache is expected to be filled because the custom override'
1860 . 'was understood'
1863 $this->assertAllQueriesConsumed();
1864 $this->assertAllSelectsConsumed();
1866 $this->dummyDbi->addResult(
1867 'SHOW TABLES FROM `PMA-storage`',
1870 'pma__userconfig_custom',
1871 'pma__usergroups',
1874 ['Tables_in_PMA-storage']
1877 $this->dummyDbi->addSelectDb('PMA-storage');
1878 /** @psalm-suppress EmptyArrayAccess */
1879 unset($_SESSION['relation'][$GLOBALS['server']]);
1880 $relationData = $relation->getRelationParameters();
1881 $this->assertAllSelectsConsumed();
1883 $relationParameters = RelationParameters::fromArray([
1884 'db' => 'PMA-storage',
1885 'trackingwork' => false,
1886 'tracking' => false,
1888 $this->assertSame($relationParameters->toArray(), $relationData->toArray());
1889 $this->assertNull($relationParameters->trackingFeature, 'The feature should not be enabled');
1891 $this->assertSame([
1892 'user' => '',
1893 'pmadb' => 'PMA-storage',
1894 'bookmarktable' => '',
1895 'relation' => '',
1896 'table_info' => '',
1897 'table_coords' => '',
1898 'column_info' => '',
1899 'pdf_pages' => '',
1900 'history' => '',
1901 'recent' => '',
1902 'favorite' => '',
1903 'table_uiprefs' => '',
1904 'tracking' => false,
1905 'userconfig' => '',
1906 'users' => '',
1907 'usergroups' => '',
1908 'navigationhiding' => '',
1909 'savedsearches' => '',
1910 'central_columns' => '',
1911 'designer_settings' => '',
1912 'export_templates' => '',
1913 ], $GLOBALS['cfg']['Server']);
1915 $this->assertAllQueriesConsumed();
1918 public function testInitRelationParamsDisabledTrackingOthersExist(): void
1920 parent::setGlobalDbi();
1922 $GLOBALS['db'] = '';
1923 $GLOBALS['server'] = 1;
1924 $GLOBALS['cfg']['Server'] = [];
1925 $GLOBALS['cfg']['Server']['user'] = '';
1926 $GLOBALS['cfg']['Server']['pmadb'] = 'PMA-storage';
1927 $GLOBALS['cfg']['Server']['bookmarktable'] = '';
1928 $GLOBALS['cfg']['Server']['relation'] = '';
1929 $GLOBALS['cfg']['Server']['table_info'] = '';
1930 $GLOBALS['cfg']['Server']['table_coords'] = '';
1931 $GLOBALS['cfg']['Server']['column_info'] = '';
1932 $GLOBALS['cfg']['Server']['pdf_pages'] = '';
1933 $GLOBALS['cfg']['Server']['history'] = '';
1934 $GLOBALS['cfg']['Server']['recent'] = '';
1935 $GLOBALS['cfg']['Server']['favorite'] = 'pma__favorite_custom';
1936 $GLOBALS['cfg']['Server']['table_uiprefs'] = '';
1937 $GLOBALS['cfg']['Server']['tracking'] = false;
1938 $GLOBALS['cfg']['Server']['userconfig'] = '';
1939 $GLOBALS['cfg']['Server']['users'] = '';
1940 $GLOBALS['cfg']['Server']['usergroups'] = '';
1941 $GLOBALS['cfg']['Server']['navigationhiding'] = '';
1942 $GLOBALS['cfg']['Server']['savedsearches'] = '';
1943 $GLOBALS['cfg']['Server']['central_columns'] = '';
1944 $GLOBALS['cfg']['Server']['designer_settings'] = '';
1945 $GLOBALS['cfg']['Server']['export_templates'] = '';
1947 $this->dummyDbi->removeDefaultResults();
1948 $this->dummyDbi->addSelectDb('PMA-storage');
1949 $this->dummyDbi->addResult(
1950 'SHOW TABLES FROM `PMA-storage`;',
1952 ['pma__favorite_custom'],
1954 ['Tables_in_PMA-storage']
1957 $this->dummyDbi->addResult(
1958 'SHOW TABLES FROM `PMA-storage`',
1960 ['pma__favorite_custom'],
1962 ['Tables_in_PMA-storage']
1965 $this->dummyDbi->addResult(
1966 'SELECT NULL FROM `pma__favorite_custom` LIMIT 0',
1968 ['NULL'],
1970 ['NULL']
1973 $_SESSION['relation'] = [];
1974 $_SESSION['tmpval'] = [];
1975 $recentFavoriteTableInstances = (new ReflectionClass(RecentFavoriteTable::class))->getProperty('instances');
1976 $recentFavoriteTableInstances->setAccessible(true);
1977 $recentFavoriteTableInstances->setValue(null, []);
1979 $relation = new Relation($this->dbi);
1980 $relation->initRelationParamsCache();
1982 $this->assertArrayHasKey(
1983 'relation',
1984 $_SESSION,
1985 'The cache is expected to be filled because the custom override'
1986 . 'was understood'
1989 $this->assertAllQueriesConsumed();
1990 $this->assertAllSelectsConsumed();
1992 $this->dummyDbi->addSelectDb('PMA-storage');
1994 $this->dummyDbi->addResult(
1995 'SHOW TABLES FROM `PMA-storage`',
1997 ['pma__favorite_custom'],
1999 ['Tables_in_PMA-storage']
2002 $this->dummyDbi->addResult(
2003 'SELECT NULL FROM `pma__favorite_custom` LIMIT 0',
2005 ['NULL'],
2007 ['NULL']
2010 /** @psalm-suppress EmptyArrayAccess */
2011 unset($_SESSION['relation'][$GLOBALS['server']]);
2012 $relationData = $relation->getRelationParameters();
2013 $this->assertAllSelectsConsumed();
2015 $relationParameters = RelationParameters::fromArray([
2016 'db' => 'PMA-storage',
2017 'trackingwork' => false,
2018 'tracking' => false,
2019 'favorite' => 'pma__favorite_custom',
2020 'favoritework' => true,
2022 $this->assertSame($relationParameters->toArray(), $relationData->toArray());
2023 $this->assertNull($relationParameters->trackingFeature, 'The feature should not be enabled');
2025 $this->assertSame([
2026 'user' => '',
2027 'pmadb' => 'PMA-storage',
2028 'bookmarktable' => '',
2029 'relation' => '',
2030 'table_info' => '',
2031 'table_coords' => '',
2032 'column_info' => '',
2033 'pdf_pages' => '',
2034 'history' => '',
2035 'recent' => '',
2036 'favorite' => 'pma__favorite_custom',
2037 'table_uiprefs' => '',
2038 'tracking' => false,
2039 'userconfig' => '',
2040 'users' => '',
2041 'usergroups' => '',
2042 'navigationhiding' => '',
2043 'savedsearches' => '',
2044 'central_columns' => '',
2045 'designer_settings' => '',
2046 'export_templates' => '',
2047 ], $GLOBALS['cfg']['Server']);
2049 $this->assertAllQueriesConsumed();
2052 public function testArePmadbTablesDefinedAndArePmadbTablesAllDisabled(): void
2054 parent::setGlobalDbi();
2056 $GLOBALS['cfg']['Server']['bookmarktable'] = '';
2057 $GLOBALS['cfg']['Server']['relation'] = '';
2058 $GLOBALS['cfg']['Server']['table_info'] = '';
2059 $GLOBALS['cfg']['Server']['table_coords'] = '';
2060 $GLOBALS['cfg']['Server']['column_info'] = '';
2061 $GLOBALS['cfg']['Server']['pdf_pages'] = '';
2062 $GLOBALS['cfg']['Server']['history'] = '';
2063 $GLOBALS['cfg']['Server']['recent'] = '';
2064 $GLOBALS['cfg']['Server']['favorite'] = '';
2065 $GLOBALS['cfg']['Server']['table_uiprefs'] = '';
2066 $GLOBALS['cfg']['Server']['tracking'] = '';
2067 $GLOBALS['cfg']['Server']['userconfig'] = '';
2068 $GLOBALS['cfg']['Server']['users'] = '';
2069 $GLOBALS['cfg']['Server']['usergroups'] = '';
2070 $GLOBALS['cfg']['Server']['navigationhiding'] = '';
2071 $GLOBALS['cfg']['Server']['savedsearches'] = '';
2072 $GLOBALS['cfg']['Server']['central_columns'] = '';
2073 $GLOBALS['cfg']['Server']['designer_settings'] = '';
2074 $GLOBALS['cfg']['Server']['export_templates'] = '';
2076 $this->assertFalse($this->relation->arePmadbTablesDefined());
2077 $this->assertFalse($this->relation->arePmadbTablesAllDisabled());
2079 $GLOBALS['cfg']['Server']['bookmarktable'] = '';
2080 $GLOBALS['cfg']['Server']['relation'] = '';
2081 $GLOBALS['cfg']['Server']['table_info'] = '';
2082 $GLOBALS['cfg']['Server']['table_coords'] = '';
2083 $GLOBALS['cfg']['Server']['column_info'] = '';
2084 $GLOBALS['cfg']['Server']['pdf_pages'] = '';
2085 $GLOBALS['cfg']['Server']['history'] = '';
2086 $GLOBALS['cfg']['Server']['recent'] = '';
2087 $GLOBALS['cfg']['Server']['favorite'] = 'pma__favorite_custom';
2088 $GLOBALS['cfg']['Server']['table_uiprefs'] = '';
2089 $GLOBALS['cfg']['Server']['tracking'] = false;
2090 $GLOBALS['cfg']['Server']['userconfig'] = '';
2091 $GLOBALS['cfg']['Server']['users'] = '';
2092 $GLOBALS['cfg']['Server']['usergroups'] = '';
2093 $GLOBALS['cfg']['Server']['navigationhiding'] = '';
2094 $GLOBALS['cfg']['Server']['savedsearches'] = '';
2095 $GLOBALS['cfg']['Server']['central_columns'] = '';
2096 $GLOBALS['cfg']['Server']['designer_settings'] = '';
2097 $GLOBALS['cfg']['Server']['export_templates'] = '';
2099 $this->assertFalse($this->relation->arePmadbTablesDefined());
2100 $this->assertFalse($this->relation->arePmadbTablesAllDisabled());
2102 $GLOBALS['cfg']['Server']['bookmarktable'] = 'pma__bookmark';
2103 $GLOBALS['cfg']['Server']['relation'] = 'pma__relation';
2104 $GLOBALS['cfg']['Server']['table_info'] = 'pma__table_info';
2105 $GLOBALS['cfg']['Server']['table_coords'] = 'pma__table_coords';
2106 $GLOBALS['cfg']['Server']['pdf_pages'] = 'pma__pdf_pages';
2107 $GLOBALS['cfg']['Server']['column_info'] = 'pma__column_info';
2108 $GLOBALS['cfg']['Server']['history'] = 'pma__history';
2109 $GLOBALS['cfg']['Server']['table_uiprefs'] = 'pma__table_uiprefs';
2110 $GLOBALS['cfg']['Server']['tracking'] = 'pma__tracking';
2111 $GLOBALS['cfg']['Server']['userconfig'] = 'pma__userconfig';
2112 $GLOBALS['cfg']['Server']['recent'] = 'pma__recent';
2113 $GLOBALS['cfg']['Server']['favorite'] = 'pma__favorite';
2114 $GLOBALS['cfg']['Server']['users'] = 'pma__users';
2115 $GLOBALS['cfg']['Server']['usergroups'] = 'pma__usergroups';
2116 $GLOBALS['cfg']['Server']['navigationhiding'] = 'pma__navigationhiding';
2117 $GLOBALS['cfg']['Server']['savedsearches'] = 'pma__savedsearches';
2118 $GLOBALS['cfg']['Server']['central_columns'] = 'pma__central_columns';
2119 $GLOBALS['cfg']['Server']['designer_settings'] = 'pma__designer_settings';
2120 $GLOBALS['cfg']['Server']['export_templates'] = 'pma__export_templates';
2122 $this->assertTrue($this->relation->arePmadbTablesDefined());
2123 $this->assertFalse($this->relation->arePmadbTablesAllDisabled());
2125 $GLOBALS['cfg']['Server']['bookmarktable'] = 'pma__bookmark';
2126 $GLOBALS['cfg']['Server']['relation'] = 'pma__relation';
2127 $GLOBALS['cfg']['Server']['table_info'] = 'pma__table_info';
2128 $GLOBALS['cfg']['Server']['table_coords'] = 'pma__table_coords';
2129 $GLOBALS['cfg']['Server']['pdf_pages'] = 'pma__pdf_pages';
2130 $GLOBALS['cfg']['Server']['column_info'] = 'pma__column_info';
2131 $GLOBALS['cfg']['Server']['history'] = 'custom_name';
2132 $GLOBALS['cfg']['Server']['table_uiprefs'] = 'pma__table_uiprefs';
2133 $GLOBALS['cfg']['Server']['tracking'] = 'pma__tracking';
2134 $GLOBALS['cfg']['Server']['userconfig'] = 'pma__userconfig';
2135 $GLOBALS['cfg']['Server']['recent'] = 'pma__recent';
2136 $GLOBALS['cfg']['Server']['favorite'] = 'pma__favorite';
2137 $GLOBALS['cfg']['Server']['users'] = 'pma__users';
2138 $GLOBALS['cfg']['Server']['usergroups'] = 'pma__usergroups';
2139 $GLOBALS['cfg']['Server']['navigationhiding'] = 'pma__navigationhiding';
2140 $GLOBALS['cfg']['Server']['savedsearches'] = 'pma__savedsearches';
2141 $GLOBALS['cfg']['Server']['central_columns'] = 'pma__central_columns';
2142 $GLOBALS['cfg']['Server']['designer_settings'] = 'pma__designer_settings';
2143 $GLOBALS['cfg']['Server']['export_templates'] = 'pma__export_templates';
2145 $this->assertTrue($this->relation->arePmadbTablesDefined());
2146 $this->assertFalse($this->relation->arePmadbTablesAllDisabled());
2148 $GLOBALS['cfg']['Server']['bookmarktable'] = 'pma__bookmark';
2149 $GLOBALS['cfg']['Server']['relation'] = 'pma__relation';
2150 $GLOBALS['cfg']['Server']['table_info'] = 'pma__table_info';
2151 $GLOBALS['cfg']['Server']['table_coords'] = 'pma__table_coords';
2152 $GLOBALS['cfg']['Server']['pdf_pages'] = 'pma__pdf_pages';
2153 $GLOBALS['cfg']['Server']['column_info'] = 'pma__column_info';
2154 $GLOBALS['cfg']['Server']['history'] = 'pma__history';
2155 $GLOBALS['cfg']['Server']['table_uiprefs'] = 'pma__table_uiprefs';
2156 $GLOBALS['cfg']['Server']['tracking'] = 'pma__tracking';
2157 $GLOBALS['cfg']['Server']['userconfig'] = '';
2158 $GLOBALS['cfg']['Server']['recent'] = 'pma__recent';
2159 $GLOBALS['cfg']['Server']['favorite'] = 'pma__favorite';
2160 $GLOBALS['cfg']['Server']['users'] = 'pma__users';
2161 $GLOBALS['cfg']['Server']['usergroups'] = 'pma__usergroups';
2162 $GLOBALS['cfg']['Server']['navigationhiding'] = 'pma__navigationhiding';
2163 $GLOBALS['cfg']['Server']['savedsearches'] = 'pma__savedsearches';
2164 $GLOBALS['cfg']['Server']['central_columns'] = 'pma__central_columns';
2165 $GLOBALS['cfg']['Server']['designer_settings'] = 'pma__designer_settings';
2166 $GLOBALS['cfg']['Server']['export_templates'] = 'pma__export_templates';
2168 $this->assertFalse($this->relation->arePmadbTablesDefined());
2169 $this->assertFalse($this->relation->arePmadbTablesAllDisabled());
2171 $GLOBALS['cfg']['Server']['bookmarktable'] = false; //'pma__bookmark';
2172 $GLOBALS['cfg']['Server']['relation'] = false; //'pma__relation';
2173 $GLOBALS['cfg']['Server']['table_info'] = false; //'pma__table_info';
2174 $GLOBALS['cfg']['Server']['table_coords'] = false; //'pma__table_coords';
2175 $GLOBALS['cfg']['Server']['pdf_pages'] = false; //'pma__pdf_pages';
2176 $GLOBALS['cfg']['Server']['column_info'] = false; //'pma__column_info';
2177 $GLOBALS['cfg']['Server']['history'] = false; //'pma__history';
2178 $GLOBALS['cfg']['Server']['table_uiprefs'] = false; //'pma__table_uiprefs';
2179 $GLOBALS['cfg']['Server']['tracking'] = false; //'pma__tracking';
2180 $GLOBALS['cfg']['Server']['userconfig'] = false; //'pma__userconfig';
2181 $GLOBALS['cfg']['Server']['recent'] = false; //'pma__recent';
2182 $GLOBALS['cfg']['Server']['favorite'] = false; //'pma__favorite';
2183 $GLOBALS['cfg']['Server']['users'] = false; //'pma__users';
2184 $GLOBALS['cfg']['Server']['usergroups'] = false; //'pma__usergroups';
2185 $GLOBALS['cfg']['Server']['navigationhiding'] = false; //'pma__navigationhiding';
2186 $GLOBALS['cfg']['Server']['savedsearches'] = false; //'pma__savedsearches';
2187 $GLOBALS['cfg']['Server']['central_columns'] = false; //'pma__central_columns';
2188 $GLOBALS['cfg']['Server']['designer_settings'] = false; //'pma__designer_settings';
2189 $GLOBALS['cfg']['Server']['export_templates'] = false; //'pma__export_templates';
2191 $this->assertFalse($this->relation->arePmadbTablesDefined());
2192 $this->assertTrue($this->relation->arePmadbTablesAllDisabled());
2196 * @param array<string, bool|string> $params
2197 * @param string[] $queries
2199 * @dataProvider providerForTestRenameTable
2201 public function testRenameTable(array $params, array $queries): void
2203 $GLOBALS['server'] = 1;
2204 $_SESSION['relation'] = [];
2205 $_SESSION['relation'][$GLOBALS['server']] = RelationParameters::fromArray($params)->toArray();
2207 foreach ($queries as $query) {
2208 $this->dummyDbi->addResult($query, []);
2211 $this->relation->renameTable('db_1', 'db_2', 'table_1', 'table_2');
2213 $this->assertAllQueriesConsumed();
2217 * @return array<int, array<int, array<int|string, bool|string>>>
2218 * @psalm-return list<array{array<string, bool|string>, string[]}>
2220 public function providerForTestRenameTable(): array
2222 // phpcs:disable Generic.Files.LineLength.TooLong
2223 return [
2225 ['user' => 'user', 'db' => 'pmadb', 'commwork' => true, 'column_info' => 'column_info'],
2226 ['UPDATE `pmadb`.`column_info` SET db_name = \'db_2\', table_name = \'table_2\' WHERE db_name = \'db_1\' AND table_name = \'table_1\''],
2229 ['user' => 'user', 'db' => 'pmadb', 'displaywork' => true, 'relation' => 'relation', 'table_info' => 'table_info'],
2230 ['UPDATE `pmadb`.`table_info` SET db_name = \'db_2\', table_name = \'table_2\' WHERE db_name = \'db_1\' AND table_name = \'table_1\''],
2233 ['user' => 'user', 'db' => 'pmadb', 'relwork' => true, 'relation' => 'relation'],
2235 'UPDATE `pmadb`.`relation` SET foreign_db = \'db_2\', foreign_table = \'table_2\' WHERE foreign_db = \'db_1\' AND foreign_table = \'table_1\'',
2236 'UPDATE `pmadb`.`relation` SET master_db = \'db_2\', master_table = \'table_2\' WHERE master_db = \'db_1\' AND master_table = \'table_1\'',
2240 ['user' => 'user', 'db' => 'pmadb', 'pdfwork' => true, 'pdf_pages' => 'pdf_pages', 'table_coords' => 'table_coords'],
2241 ['DELETE FROM `pmadb`.`table_coords` WHERE db_name = \'db_1\' AND table_name = \'table_1\''],
2244 ['user' => 'user', 'db' => 'pmadb', 'uiprefswork' => true, 'table_uiprefs' => 'table_uiprefs'],
2245 ['UPDATE `pmadb`.`table_uiprefs` SET db_name = \'db_2\', table_name = \'table_2\' WHERE db_name = \'db_1\' AND table_name = \'table_1\''],
2248 ['user' => 'user', 'db' => 'pmadb', 'navwork' => true, 'navigationhiding' => 'navigationhiding'],
2250 'UPDATE `pmadb`.`navigationhiding` SET db_name = \'db_2\', table_name = \'table_2\' WHERE db_name = \'db_1\' AND table_name = \'table_1\'',
2251 'UPDATE `pmadb`.`navigationhiding` SET db_name = \'db_2\', item_name = \'table_2\' WHERE db_name = \'db_1\' AND item_name = \'table_1\' AND item_type = \'table\'',
2255 // phpcs:enable
2258 public function testRenameTableEscaping(): void
2260 $GLOBALS['server'] = 1;
2261 $_SESSION['relation'] = [];
2262 $_SESSION['relation'][$GLOBALS['server']] = RelationParameters::fromArray([
2263 'user' => 'user',
2264 'db' => 'pma`db',
2265 'pdfwork' => true,
2266 'pdf_pages' => 'pdf_pages',
2267 'table_coords' => 'table`coords',
2268 ])->toArray();
2270 $this->dummyDbi->addResult(
2271 'UPDATE `pma``db`.`table``coords` SET db_name = \'db\\\'1\', table_name = \'table\\\'2\''
2272 . ' WHERE db_name = \'db\\\'1\' AND table_name = \'table\\\'1\'',
2276 $this->relation->renameTable('db\'1', 'db\'1', 'table\'1', 'table\'2');
2278 $this->assertAllQueriesConsumed();