1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace PhpMyAdmin\Tests\ConfigStorage; |
6
|
|
|
|
7
|
|
|
use PhpMyAdmin\ColumnFull; |
8
|
|
|
use PhpMyAdmin\Config; |
9
|
|
|
use PhpMyAdmin\ConfigStorage\Relation; |
10
|
|
|
use PhpMyAdmin\ConfigStorage\RelationParameters; |
11
|
|
|
use PhpMyAdmin\Current; |
12
|
|
|
use PhpMyAdmin\DatabaseInterface; |
13
|
|
|
use PhpMyAdmin\Favorites\RecentFavoriteTables; |
14
|
|
|
use PhpMyAdmin\Tests\AbstractTestCase; |
15
|
|
|
use PhpMyAdmin\Tests\Stubs\DummyResult; |
16
|
|
|
use PHPUnit\Framework\Attributes\CoversClass; |
17
|
|
|
use PHPUnit\Framework\Attributes\DataProvider; |
18
|
|
|
use PHPUnit\Framework\Attributes\Medium; |
19
|
|
|
use ReflectionProperty; |
20
|
|
|
|
21
|
|
|
use function implode; |
22
|
|
|
|
23
|
|
|
#[CoversClass(Relation::class)] |
24
|
|
|
#[Medium] |
25
|
|
|
class RelationTest extends AbstractTestCase |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* Test for getDisplayField |
29
|
|
|
*/ |
30
|
|
|
public function testPMAGetDisplayField(): void |
31
|
|
|
{ |
32
|
|
|
$config = Config::getInstance(); |
|
|
|
|
33
|
|
|
$config->selectedServer['user'] = 'root'; |
34
|
|
|
$config->selectedServer['pmadb'] = 'phpmyadmin'; |
35
|
|
|
$config->selectedServer['DisableIS'] = false; |
36
|
|
|
|
37
|
|
|
$dummyDbi = $this->createDbiDummy(); |
38
|
|
|
$dbi = $this->createDatabaseInterface($dummyDbi); |
39
|
|
|
|
40
|
|
|
$relation = new Relation($dbi); |
41
|
|
|
|
42
|
|
|
$dummyDbi->addSelectDb('phpmyadmin'); |
43
|
|
|
$db = 'information_schema'; |
44
|
|
|
$table = 'CHARACTER_SETS'; |
45
|
|
|
self::assertSame( |
46
|
|
|
'DESCRIPTION', |
47
|
|
|
$relation->getDisplayField($db, $table), |
48
|
|
|
); |
49
|
|
|
$dummyDbi->assertAllSelectsConsumed(); |
50
|
|
|
|
51
|
|
|
$db = 'information_schema'; |
52
|
|
|
$table = 'TABLES'; |
53
|
|
|
self::assertSame( |
54
|
|
|
'TABLE_COMMENT', |
55
|
|
|
$relation->getDisplayField($db, $table), |
56
|
|
|
); |
57
|
|
|
|
58
|
|
|
$db = 'information_schema'; |
59
|
|
|
$table = 'PMA'; |
60
|
|
|
self::assertSame( |
61
|
|
|
'', |
62
|
|
|
$relation->getDisplayField($db, $table), |
63
|
|
|
); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Test for getComments |
68
|
|
|
*/ |
69
|
|
|
public function testPMAGetComments(): void |
70
|
|
|
{ |
71
|
|
|
$config = Config::getInstance(); |
|
|
|
|
72
|
|
|
$config->selectedServer['DisableIS'] = false; |
73
|
|
|
$config->settings['ServerDefault'] = 0; |
74
|
|
|
|
75
|
|
|
$dbi = $this->getMockBuilder(DatabaseInterface::class) |
76
|
|
|
->disableOriginalConstructor() |
77
|
|
|
->getMock(); |
78
|
|
|
|
79
|
|
|
$getColumnsResult = [ |
80
|
|
|
new ColumnFull('field1', 'int(11)', null, false, '', null, '', '', 'Comment1'), |
81
|
|
|
new ColumnFull('field2', 'text', null, false, '', null, '', '', 'Comment1'), |
82
|
|
|
]; |
83
|
|
|
$dbi->expects(self::any())->method('getColumns') |
84
|
|
|
->willReturn($getColumnsResult); |
85
|
|
|
|
86
|
|
|
$relation = new Relation($dbi); |
87
|
|
|
|
88
|
|
|
DatabaseInterface::$instance = $dbi; |
89
|
|
|
|
90
|
|
|
$db = 'information_schema'; |
91
|
|
|
self::assertSame( |
92
|
|
|
[''], |
93
|
|
|
$relation->getComments($db), |
94
|
|
|
); |
95
|
|
|
|
96
|
|
|
$db = 'information_schema'; |
97
|
|
|
$table = 'TABLES'; |
98
|
|
|
self::assertSame( |
99
|
|
|
['field1' => 'Comment1', 'field2' => 'Comment1'], |
100
|
|
|
$relation->getComments($db, $table), |
101
|
|
|
); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* Test for tryUpgradeTransformations |
106
|
|
|
*/ |
107
|
|
|
public function testPMATryUpgradeTransformations(): void |
108
|
|
|
{ |
109
|
|
|
$resultStub = self::createMock(DummyResult::class); |
|
|
|
|
110
|
|
|
|
111
|
|
|
$dbi = $this->getMockBuilder(DatabaseInterface::class) |
112
|
|
|
->disableOriginalConstructor() |
113
|
|
|
->getMock(); |
114
|
|
|
$dbi->expects(self::any()) |
115
|
|
|
->method('tryQueryAsControlUser') |
116
|
|
|
->willReturn($resultStub); |
117
|
|
|
$resultStub->expects(self::any()) |
118
|
|
|
->method('numRows') |
119
|
|
|
->willReturn(0); |
120
|
|
|
$dbi->expects(self::any()) |
121
|
|
|
->method('getError') |
122
|
|
|
->willReturn('Error', ''); |
123
|
|
|
DatabaseInterface::$instance = $dbi; |
124
|
|
|
|
125
|
|
|
$relation = new Relation($dbi); |
126
|
|
|
|
127
|
|
|
$config = Config::getInstance(); |
|
|
|
|
128
|
|
|
$config->selectedServer['pmadb'] = 'pmadb'; |
129
|
|
|
$config->selectedServer['column_info'] = 'column_info'; |
130
|
|
|
|
131
|
|
|
// Case 1 |
132
|
|
|
$actual = $relation->tryUpgradeTransformations(); |
133
|
|
|
self::assertFalse($actual); |
134
|
|
|
|
135
|
|
|
// Case 2 |
136
|
|
|
$actual = $relation->tryUpgradeTransformations(); |
137
|
|
|
self::assertTrue($actual); |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
public function testSearchColumnInForeignersError(): void |
141
|
|
|
{ |
142
|
|
|
$relation = new Relation($this->createDatabaseInterface()); |
143
|
|
|
self::assertFalse($relation->searchColumnInForeigners([], 'id')); |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* Test for searchColumnInForeigners |
148
|
|
|
*/ |
149
|
|
|
public function testPMASearchColumnInForeigners(): void |
150
|
|
|
{ |
151
|
|
|
$foreigners = [ |
152
|
|
|
'value' => [ |
153
|
|
|
'master_field' => 'value', |
154
|
|
|
'foreign_db' => 'GSoC14', |
155
|
|
|
'foreign_table' => 'test', |
156
|
|
|
'foreign_field' => 'value', |
157
|
|
|
], |
158
|
|
|
'foreign_keys_data' => [ |
159
|
|
|
[ |
160
|
|
|
'constraint' => 'ad', |
161
|
|
|
'index_list' => ['id', 'value'], |
162
|
|
|
'ref_db_name' => 'GSoC14', |
163
|
|
|
'ref_table_name' => 'table_1', |
164
|
|
|
'ref_index_list' => ['id', 'value'], |
165
|
|
|
'on_delete' => 'CASCADE', |
166
|
|
|
'on_update' => 'CASCADE', |
167
|
|
|
], |
168
|
|
|
], |
169
|
|
|
]; |
170
|
|
|
|
171
|
|
|
$relation = new Relation($this->createDatabaseInterface()); |
172
|
|
|
|
173
|
|
|
$foreigner = $relation->searchColumnInForeigners($foreigners, 'id'); |
174
|
|
|
$expected = []; |
175
|
|
|
$expected['foreign_field'] = 'id'; |
176
|
|
|
$expected['foreign_db'] = 'GSoC14'; |
177
|
|
|
$expected['foreign_table'] = 'table_1'; |
178
|
|
|
$expected['constraint'] = 'ad'; |
179
|
|
|
$expected['on_delete'] = 'CASCADE'; |
180
|
|
|
$expected['on_update'] = 'CASCADE'; |
181
|
|
|
|
182
|
|
|
self::assertEquals($expected, $foreigner); |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
public function testFixPmaTablesNothingWorks(): void |
186
|
|
|
{ |
187
|
|
|
$dummyDbi = $this->createDbiDummy(); |
188
|
|
|
$dbi = $this->createDatabaseInterface($dummyDbi); |
189
|
|
|
|
190
|
|
|
$relation = new Relation($dbi); |
191
|
|
|
|
192
|
|
|
$dummyDbi->removeDefaultResults(); |
193
|
|
|
$dummyDbi->addResult('SHOW TABLES FROM `db_pma`;', false); |
194
|
|
|
|
195
|
|
|
$relation->fixPmaTables('db_pma', false); |
196
|
|
|
$dummyDbi->assertAllQueriesConsumed(); |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
public function testFixPmaTablesNormal(): void |
200
|
|
|
{ |
201
|
|
|
Current::$database = ''; |
202
|
|
|
$config = Config::getInstance(); |
|
|
|
|
203
|
|
|
$config->selectedServer['user'] = ''; |
204
|
|
|
$config->selectedServer['pmadb'] = ''; |
205
|
|
|
$config->selectedServer['bookmarktable'] = ''; |
206
|
|
|
$config->selectedServer['relation'] = ''; |
207
|
|
|
$config->selectedServer['table_info'] = ''; |
208
|
|
|
$config->selectedServer['table_coords'] = ''; |
209
|
|
|
$config->selectedServer['column_info'] = ''; |
210
|
|
|
$config->selectedServer['pdf_pages'] = ''; |
211
|
|
|
$config->selectedServer['history'] = ''; |
212
|
|
|
$config->selectedServer['recent'] = ''; |
213
|
|
|
$config->selectedServer['favorite'] = ''; |
214
|
|
|
$config->selectedServer['table_uiprefs'] = ''; |
215
|
|
|
$config->selectedServer['tracking'] = ''; |
216
|
|
|
$config->selectedServer['userconfig'] = ''; |
217
|
|
|
$config->selectedServer['users'] = ''; |
218
|
|
|
$config->selectedServer['usergroups'] = ''; |
219
|
|
|
$config->selectedServer['navigationhiding'] = ''; |
220
|
|
|
$config->selectedServer['savedsearches'] = ''; |
221
|
|
|
$config->selectedServer['central_columns'] = ''; |
222
|
|
|
$config->selectedServer['designer_settings'] = ''; |
223
|
|
|
$config->selectedServer['export_templates'] = ''; |
224
|
|
|
|
225
|
|
|
$dummyDbi = $this->createDbiDummy(); |
226
|
|
|
$dbi = $this->createDatabaseInterface($dummyDbi); |
227
|
|
|
$relation = new Relation($dbi); |
228
|
|
|
|
229
|
|
|
$dummyDbi->removeDefaultResults(); |
230
|
|
|
$dummyDbi->addResult( |
231
|
|
|
'SHOW TABLES FROM `db_pma`;', |
232
|
|
|
[['pma__userconfig']], |
233
|
|
|
['Tables_in_db_pma'], |
234
|
|
|
); |
235
|
|
|
|
236
|
|
|
$dummyDbi->addResult( |
237
|
|
|
'SHOW TABLES FROM `db_pma`;', |
238
|
|
|
[['pma__userconfig']], |
239
|
|
|
['Tables_in_db_pma'], |
240
|
|
|
); |
241
|
|
|
|
242
|
|
|
$dummyDbi->addResult('SELECT NULL FROM `pma__userconfig` LIMIT 0', []); |
243
|
|
|
$dummyDbi->addSelectDb('db_pma'); |
244
|
|
|
|
245
|
|
|
(new ReflectionProperty(Relation::class, 'cache'))->setValue(null, null); |
246
|
|
|
|
247
|
|
|
$relation->fixPmaTables('db_pma', false); |
248
|
|
|
|
249
|
|
|
$relationParameters = RelationParameters::fromArray([ |
250
|
|
|
'db' => 'db_pma', |
251
|
|
|
'userconfigwork' => true, |
252
|
|
|
'userconfig' => 'pma__userconfig', |
253
|
|
|
]); |
254
|
|
|
self::assertSame($relationParameters->toArray(), $relation->getRelationParameters()->toArray()); |
255
|
|
|
|
256
|
|
|
$dummyDbi->assertAllQueriesConsumed(); |
257
|
|
|
$dummyDbi->assertAllSelectsConsumed(); |
258
|
|
|
} |
259
|
|
|
|
260
|
|
|
public function testFixPmaTablesNormalFixTables(): void |
261
|
|
|
{ |
262
|
|
|
Current::$database = ''; |
263
|
|
|
$config = Config::getInstance(); |
|
|
|
|
264
|
|
|
$config->selectedServer['user'] = ''; |
265
|
|
|
$config->selectedServer['pmadb'] = ''; |
266
|
|
|
$config->selectedServer['bookmarktable'] = ''; |
267
|
|
|
$config->selectedServer['relation'] = ''; |
268
|
|
|
$config->selectedServer['table_info'] = ''; |
269
|
|
|
$config->selectedServer['table_coords'] = ''; |
270
|
|
|
$config->selectedServer['column_info'] = ''; |
271
|
|
|
$config->selectedServer['pdf_pages'] = ''; |
272
|
|
|
$config->selectedServer['history'] = ''; |
273
|
|
|
$config->selectedServer['recent'] = ''; |
274
|
|
|
$config->selectedServer['favorite'] = ''; |
275
|
|
|
$config->selectedServer['table_uiprefs'] = ''; |
276
|
|
|
$config->selectedServer['tracking'] = ''; |
277
|
|
|
$config->selectedServer['userconfig'] = ''; |
278
|
|
|
$config->selectedServer['users'] = ''; |
279
|
|
|
$config->selectedServer['usergroups'] = ''; |
280
|
|
|
$config->selectedServer['navigationhiding'] = ''; |
281
|
|
|
$config->selectedServer['savedsearches'] = ''; |
282
|
|
|
$config->selectedServer['central_columns'] = ''; |
283
|
|
|
$config->selectedServer['designer_settings'] = ''; |
284
|
|
|
$config->selectedServer['export_templates'] = ''; |
285
|
|
|
|
286
|
|
|
$dummyDbi = $this->createDbiDummy(); |
287
|
|
|
$dbi = $this->createDatabaseInterface($dummyDbi); |
288
|
|
|
|
289
|
|
|
$relation = new Relation($dbi); |
290
|
|
|
|
291
|
|
|
$dummyDbi->removeDefaultResults(); |
292
|
|
|
$dummyDbi->addResult( |
293
|
|
|
'SHOW TABLES FROM `db_pma`;', |
294
|
|
|
[['pma__userconfig']], |
295
|
|
|
['Tables_in_db_pma'], |
296
|
|
|
); |
297
|
|
|
|
298
|
|
|
$dummyDbi->addResult( |
299
|
|
|
'SHOW TABLES FROM `db_pma`;', |
300
|
|
|
[['pma__userconfig']], |
301
|
|
|
['Tables_in_db_pma'], |
302
|
|
|
); |
303
|
|
|
|
304
|
|
|
$dummyDbi->addResult('SELECT NULL FROM `pma__userconfig` LIMIT 0', []); |
305
|
|
|
$dummyDbi->addSelectDb('db_pma'); |
306
|
|
|
$dummyDbi->addSelectDb('db_pma'); |
307
|
|
|
|
308
|
|
|
$dummyDbi->addResult( |
309
|
|
|
'-- -------------------------------------------------------- -- --' |
310
|
|
|
. ' Table structure for table `pma__bookmark` ' |
311
|
|
|
. '-- CREATE TABLE IF NOT EXISTS `pma__bookmark` ( ' |
312
|
|
|
. '`id` int(10) unsigned NOT NULL auto_increment,' |
313
|
|
|
. ' `dbase` varchar(255) NOT NULL default \'\',' |
314
|
|
|
. ' `user` varchar(255) NOT NULL default \'\',' |
315
|
|
|
. ' `label` varchar(255) COLLATE utf8_general_ci NOT NULL default \'\',' |
316
|
|
|
. ' `query` text NOT NULL, PRIMARY KEY (`id`) )' |
317
|
|
|
. ' COMMENT=\'Bookmarks\' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', |
318
|
|
|
true, |
319
|
|
|
); |
320
|
|
|
$dummyDbi->addResult( |
321
|
|
|
'-- -------------------------------------------------------- -- --' |
322
|
|
|
. ' Table structure for table `pma__relation` ' |
323
|
|
|
. '-- CREATE TABLE IF NOT EXISTS `pma__relation` ( ' |
324
|
|
|
. '`master_db` varchar(64) NOT NULL default \'\', `master_table` varchar(64) NOT NULL default \'\',' |
325
|
|
|
. ' `master_field` varchar(64) NOT NULL default \'\', `foreign_db` varchar(64) NOT NULL default \'\',' |
326
|
|
|
. ' `foreign_table` varchar(64) NOT NULL default \'\',' |
327
|
|
|
. ' `foreign_field` varchar(64) NOT NULL default \'\',' |
328
|
|
|
. ' PRIMARY KEY (`master_db`,`master_table`,`master_field`),' |
329
|
|
|
. ' KEY `foreign_field` (`foreign_db`,`foreign_table`) ) COMMENT=\'Relation table\'' |
330
|
|
|
. ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', |
331
|
|
|
true, |
332
|
|
|
); |
333
|
|
|
$dummyDbi->addResult( |
334
|
|
|
'-- -------------------------------------------------------- -- --' |
335
|
|
|
. ' Table structure for table `pma__table_info`' |
336
|
|
|
. ' -- CREATE TABLE IF NOT EXISTS `pma__table_info` ( ' |
337
|
|
|
. '`db_name` varchar(64) NOT NULL default \'\', `table_name` varchar(64) NOT NULL default \'\',' |
338
|
|
|
. ' `display_field` varchar(64) NOT NULL default \'\', PRIMARY KEY (`db_name`,`table_name`) )' |
339
|
|
|
. ' COMMENT=\'Table information for phpMyAdmin\' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', |
340
|
|
|
true, |
341
|
|
|
); |
342
|
|
|
|
343
|
|
|
$dummyDbi->addResult( |
344
|
|
|
'-- -------------------------------------------------------- -- --' |
345
|
|
|
. ' Table structure for table `pma__table_coords`' |
346
|
|
|
. ' -- CREATE TABLE IF NOT EXISTS `pma__table_coords` ( ' |
347
|
|
|
. '`db_name` varchar(64) NOT NULL default \'\', `table_name` varchar(64) NOT NULL default \'\',' |
348
|
|
|
. ' `pdf_page_number` int(11) NOT NULL default \'0\', `x` float unsigned NOT NULL default \'0\',' |
349
|
|
|
. ' `y` float unsigned NOT NULL default \'0\',' |
350
|
|
|
. ' PRIMARY KEY (`db_name`,`table_name`,`pdf_page_number`) )' |
351
|
|
|
. ' COMMENT=\'Table coordinates for phpMyAdmin PDF output\'' |
352
|
|
|
. ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', |
353
|
|
|
true, |
354
|
|
|
); |
355
|
|
|
$dummyDbi->addResult( |
356
|
|
|
'-- -------------------------------------------------------- -- --' |
357
|
|
|
. ' Table structure for table `pma__pdf_pages`' |
358
|
|
|
. ' -- CREATE TABLE IF NOT EXISTS `pma__pdf_pages` ( ' |
359
|
|
|
. '`db_name` varchar(64) NOT NULL default \'\', `page_nr` int(10) unsigned NOT NULL auto_increment,' |
360
|
|
|
. ' `page_descr` varchar(50) COLLATE utf8_general_ci NOT NULL default \'\', PRIMARY KEY (`page_nr`),' |
361
|
|
|
. ' KEY `db_name` (`db_name`) ) COMMENT=\'PDF relation pages for phpMyAdmin\'' |
362
|
|
|
. ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', |
363
|
|
|
true, |
364
|
|
|
); |
365
|
|
|
$dummyDbi->addResult( |
366
|
|
|
'-- -------------------------------------------------------- -- --' |
367
|
|
|
. ' Table structure for table `pma__column_info`' |
368
|
|
|
. ' -- CREATE TABLE IF NOT EXISTS `pma__column_info` ( ' |
369
|
|
|
. '`id` int(5) unsigned NOT NULL auto_increment, `db_name` varchar(64) NOT NULL default \'\',' |
370
|
|
|
. ' `table_name` varchar(64) NOT NULL default \'\', `column_name` varchar(64) NOT NULL default \'\',' |
371
|
|
|
. ' `comment` varchar(255) COLLATE utf8_general_ci NOT NULL default \'\',' |
372
|
|
|
. ' `mimetype` varchar(255) COLLATE utf8_general_ci NOT NULL default \'\',' |
373
|
|
|
. ' `transformation` varchar(255) NOT NULL default \'\',' |
374
|
|
|
. ' `transformation_options` varchar(255) NOT NULL default \'\',' |
375
|
|
|
. ' `input_transformation` varchar(255) NOT NULL default \'\',' |
376
|
|
|
. ' `input_transformation_options` varchar(255) NOT NULL default \'\',' |
377
|
|
|
. ' PRIMARY KEY (`id`), UNIQUE KEY `db_name` (`db_name`,`table_name`,`column_name`) )' |
378
|
|
|
. ' COMMENT=\'Column information for phpMyAdmin\' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', |
379
|
|
|
true, |
380
|
|
|
); |
381
|
|
|
$dummyDbi->addResult( |
382
|
|
|
'-- -------------------------------------------------------- -- --' |
383
|
|
|
. ' Table structure for table `pma__history` ' |
384
|
|
|
. '-- CREATE TABLE IF NOT EXISTS `pma__history` ( ' |
385
|
|
|
. '`id` bigint(20) unsigned NOT NULL auto_increment, `username` varchar(64) NOT NULL default \'\',' |
386
|
|
|
. ' `db` varchar(64) NOT NULL default \'\', `table` varchar(64) NOT NULL default \'\',' |
387
|
|
|
. ' `timevalue` timestamp NOT NULL default CURRENT_TIMESTAMP, `sqlquery` text NOT NULL,' |
388
|
|
|
. ' PRIMARY KEY (`id`), KEY `username` (`username`,`db`,`table`,`timevalue`) )' |
389
|
|
|
. ' COMMENT=\'SQL history for phpMyAdmin\' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', |
390
|
|
|
true, |
391
|
|
|
); |
392
|
|
|
$dummyDbi->addResult( |
393
|
|
|
'-- -------------------------------------------------------- -- --' |
394
|
|
|
. ' Table structure for table `pma__recent` ' |
395
|
|
|
. '-- CREATE TABLE IF NOT EXISTS `pma__recent` ( ' |
396
|
|
|
. '`username` varchar(64) NOT NULL, `tables` text NOT NULL, PRIMARY KEY (`username`) )' |
397
|
|
|
. ' COMMENT=\'Recently accessed tables\' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', |
398
|
|
|
true, |
399
|
|
|
); |
400
|
|
|
$dummyDbi->addResult( |
401
|
|
|
'-- -------------------------------------------------------- -- --' |
402
|
|
|
. ' Table structure for table `pma__favorite` ' |
403
|
|
|
. '-- CREATE TABLE IF NOT EXISTS `pma__favorite` ( ' |
404
|
|
|
. '`username` varchar(64) NOT NULL, `tables` text NOT NULL, PRIMARY KEY (`username`) )' |
405
|
|
|
. ' COMMENT=\'Favorite tables\' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', |
406
|
|
|
true, |
407
|
|
|
); |
408
|
|
|
$dummyDbi->addResult( |
409
|
|
|
'-- -------------------------------------------------------- -- --' |
410
|
|
|
. ' Table structure for table `pma__table_uiprefs`' |
411
|
|
|
. ' -- CREATE TABLE IF NOT EXISTS `pma__table_uiprefs` ( ' |
412
|
|
|
. '`username` varchar(64) NOT NULL, `db_name` varchar(64) NOT NULL,' |
413
|
|
|
. ' `table_name` varchar(64) NOT NULL, `prefs` text NOT NULL,' |
414
|
|
|
. ' `last_update` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,' |
415
|
|
|
. ' PRIMARY KEY (`username`,`db_name`,`table_name`) ) COMMENT=\'Tables\'\' UI preferences\'' |
416
|
|
|
. ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', |
417
|
|
|
true, |
418
|
|
|
); |
419
|
|
|
$dummyDbi->addResult( |
420
|
|
|
'-- -------------------------------------------------------- -- --' |
421
|
|
|
. ' Table structure for table `pma__tracking` ' |
422
|
|
|
. '-- CREATE TABLE IF NOT EXISTS `pma__tracking` ( ' |
423
|
|
|
. '`db_name` varchar(64) NOT NULL, `table_name` varchar(64) NOT NULL,' |
424
|
|
|
. ' `version` int(10) unsigned NOT NULL, `date_created` datetime NOT NULL,' |
425
|
|
|
. ' `date_updated` datetime NOT NULL, `schema_snapshot` text NOT NULL,' |
426
|
|
|
. ' `schema_sql` text, `data_sql` longtext, `tracking`' |
427
|
|
|
. ' set(\'UPDATE\',\'REPLACE\',\'INSERT\',\'DELETE\',' |
428
|
|
|
. '\'TRUNCATE\',\'CREATE DATABASE\',\'ALTER DATABASE\',' |
429
|
|
|
. '\'DROP DATABASE\',\'CREATE TABLE\',\'ALTER TABLE\',' |
430
|
|
|
. '\'RENAME TABLE\',\'DROP TABLE\',\'CREATE INDEX\',' |
431
|
|
|
. '\'DROP INDEX\',\'CREATE VIEW\',\'ALTER VIEW\',\'DROP VIEW\')' |
432
|
|
|
. ' default NULL, `tracking_active` int(1) unsigned NOT NULL' |
433
|
|
|
. ' default \'1\', PRIMARY KEY (`db_name`,`table_name`,`version`) )' |
434
|
|
|
. ' COMMENT=\'Database changes tracking for phpMyAdmin\'' |
435
|
|
|
. ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', |
436
|
|
|
true, |
437
|
|
|
); |
438
|
|
|
$dummyDbi->addResult( |
439
|
|
|
'-- -------------------------------------------------------- -- --' |
440
|
|
|
. ' Table structure for table `pma__users` ' |
441
|
|
|
. '-- CREATE TABLE IF NOT EXISTS `pma__users` ( ' |
442
|
|
|
. '`username` varchar(64) NOT NULL, `usergroup` varchar(64) NOT NULL,' |
443
|
|
|
. ' PRIMARY KEY (`username`,`usergroup`) )' |
444
|
|
|
. ' COMMENT=\'Users and their assignments to user groups\'' |
445
|
|
|
. ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', |
446
|
|
|
true, |
447
|
|
|
); |
448
|
|
|
$dummyDbi->addResult( |
449
|
|
|
'-- -------------------------------------------------------- -- --' |
450
|
|
|
. ' Table structure for table `pma__usergroups`' |
451
|
|
|
. ' -- CREATE TABLE IF NOT EXISTS `pma__usergroups` ( ' |
452
|
|
|
. '`usergroup` varchar(64) NOT NULL, `tab` varchar(64) NOT NULL,' |
453
|
|
|
. ' `allowed` enum(\'Y\',\'N\') NOT NULL DEFAULT \'N\',' |
454
|
|
|
. ' PRIMARY KEY (`usergroup`,`tab`,`allowed`) )' |
455
|
|
|
. ' COMMENT=\'User groups with configured menu items\'' |
456
|
|
|
. ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', |
457
|
|
|
true, |
458
|
|
|
); |
459
|
|
|
$dummyDbi->addResult( |
460
|
|
|
'-- -------------------------------------------------------- -- --' |
461
|
|
|
. ' Table structure for table `pma__navigationhiding`' |
462
|
|
|
. ' -- CREATE TABLE IF NOT EXISTS `pma__navigationhiding` ( ' |
463
|
|
|
. '`username` varchar(64) NOT NULL, `item_name` varchar(64)' |
464
|
|
|
. ' NOT NULL, `item_type` varchar(64) NOT NULL, `db_name` varchar(64) NOT NULL,' |
465
|
|
|
. ' `table_name` varchar(64) NOT NULL,' |
466
|
|
|
. ' PRIMARY KEY (`username`,`item_name`,`item_type`,`db_name`,`table_name`) )' |
467
|
|
|
. ' COMMENT=\'Hidden items of navigation tree\' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', |
468
|
|
|
true, |
469
|
|
|
); |
470
|
|
|
$dummyDbi->addResult( |
471
|
|
|
'-- -------------------------------------------------------- -- --' |
472
|
|
|
. ' Table structure for table `pma__savedsearches`' |
473
|
|
|
. ' -- CREATE TABLE IF NOT EXISTS `pma__savedsearches` ( ' |
474
|
|
|
. '`id` int(5) unsigned NOT NULL auto_increment, `username` varchar(64) NOT NULL default \'\',' |
475
|
|
|
. ' `db_name` varchar(64) NOT NULL default \'\', `search_name` varchar(64) NOT NULL default \'\',' |
476
|
|
|
. ' `search_data` text NOT NULL, PRIMARY KEY (`id`),' |
477
|
|
|
. ' UNIQUE KEY `u_savedsearches_username_dbname` (`username`,`db_name`,`search_name`) )' |
478
|
|
|
. ' COMMENT=\'Saved searches\' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', |
479
|
|
|
true, |
480
|
|
|
); |
481
|
|
|
$dummyDbi->addResult( |
482
|
|
|
'-- -------------------------------------------------------- -- --' |
483
|
|
|
. ' Table structure for table `pma__central_columns`' |
484
|
|
|
. ' -- CREATE TABLE IF NOT EXISTS `pma__central_columns` ( ' |
485
|
|
|
. '`db_name` varchar(64) NOT NULL, `col_name` varchar(64) NOT NULL, `col_type` varchar(64) NOT NULL,' |
486
|
|
|
. ' `col_length` text, `col_collation` varchar(64) NOT NULL, `col_isNull` boolean NOT NULL,' |
487
|
|
|
. ' `col_extra` varchar(255) default \'\', `col_default` text,' |
488
|
|
|
. ' PRIMARY KEY (`db_name`,`col_name`) )' |
489
|
|
|
. ' COMMENT=\'Central list of columns\' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', |
490
|
|
|
true, |
491
|
|
|
); |
492
|
|
|
$dummyDbi->addResult( |
493
|
|
|
'-- -------------------------------------------------------- -- --' |
494
|
|
|
. ' Table structure for table `pma__designer_settings`' |
495
|
|
|
. ' -- CREATE TABLE IF NOT EXISTS `pma__designer_settings` ( ' |
496
|
|
|
. '`username` varchar(64) NOT NULL, `settings_data` text NOT NULL,' |
497
|
|
|
. ' PRIMARY KEY (`username`) )' |
498
|
|
|
. ' COMMENT=\'Settings related to Designer\' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', |
499
|
|
|
true, |
500
|
|
|
); |
501
|
|
|
$dummyDbi->addResult( |
502
|
|
|
'-- -------------------------------------------------------- -- --' |
503
|
|
|
. ' Table structure for table `pma__export_templates`' |
504
|
|
|
. ' -- CREATE TABLE IF NOT EXISTS `pma__export_templates` ( ' |
505
|
|
|
. '`id` int(5) unsigned NOT NULL AUTO_INCREMENT, `username` varchar(64) NOT NULL,' |
506
|
|
|
. ' `export_type` varchar(10) NOT NULL, `template_name` varchar(64) NOT NULL,' |
507
|
|
|
. ' `template_data` text NOT NULL, PRIMARY KEY (`id`),' |
508
|
|
|
. ' UNIQUE KEY `u_user_type_template` (`username`,`export_type`,`template_name`) )' |
509
|
|
|
. ' COMMENT=\'Saved export templates\' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', |
510
|
|
|
true, |
511
|
|
|
); |
512
|
|
|
|
513
|
|
|
self::assertSame('', $config->selectedServer['pmadb']); |
514
|
|
|
|
515
|
|
|
(new ReflectionProperty(Relation::class, 'cache'))->setValue(null, null); |
516
|
|
|
|
517
|
|
|
$relation->fixPmaTables('db_pma', true); |
518
|
|
|
self::assertArrayNotHasKey('message', $GLOBALS); |
519
|
|
|
self::assertSame('db_pma', $config->selectedServer['pmadb']); |
520
|
|
|
|
521
|
|
|
$relationParameters = RelationParameters::fromArray([ |
522
|
|
|
'db' => 'db_pma', |
523
|
|
|
'userconfigwork' => true, |
524
|
|
|
'userconfig' => 'pma__userconfig', |
525
|
|
|
]); |
526
|
|
|
self::assertSame($relationParameters->toArray(), $relation->getRelationParameters()->toArray()); |
527
|
|
|
|
528
|
|
|
$dummyDbi->assertAllQueriesConsumed(); |
529
|
|
|
$dummyDbi->assertAllSelectsConsumed(); |
530
|
|
|
} |
531
|
|
|
|
532
|
|
|
public function testFixPmaTablesNormalFixTablesWithCustomOverride(): void |
533
|
|
|
{ |
534
|
|
|
Current::$database = ''; |
535
|
|
|
$config = Config::getInstance(); |
|
|
|
|
536
|
|
|
$config->selectedServer['user'] = ''; |
537
|
|
|
$config->selectedServer['pmadb'] = 'db_pma'; |
538
|
|
|
$config->selectedServer['bookmarktable'] = ''; |
539
|
|
|
$config->selectedServer['relation'] = 'custom_relation_pma'; |
540
|
|
|
$config->selectedServer['table_info'] = ''; |
541
|
|
|
$config->selectedServer['table_coords'] = ''; |
542
|
|
|
$config->selectedServer['column_info'] = ''; |
543
|
|
|
$config->selectedServer['pdf_pages'] = ''; |
544
|
|
|
$config->selectedServer['history'] = ''; |
545
|
|
|
$config->selectedServer['recent'] = ''; |
546
|
|
|
$config->selectedServer['favorite'] = ''; |
547
|
|
|
$config->selectedServer['table_uiprefs'] = ''; |
548
|
|
|
$config->selectedServer['tracking'] = ''; |
549
|
|
|
$config->selectedServer['userconfig'] = ''; |
550
|
|
|
$config->selectedServer['users'] = ''; |
551
|
|
|
$config->selectedServer['usergroups'] = ''; |
552
|
|
|
$config->selectedServer['navigationhiding'] = ''; |
553
|
|
|
$config->selectedServer['savedsearches'] = ''; |
554
|
|
|
$config->selectedServer['central_columns'] = ''; |
555
|
|
|
$config->selectedServer['designer_settings'] = ''; |
556
|
|
|
$config->selectedServer['export_templates'] = ''; |
557
|
|
|
|
558
|
|
|
$dummyDbi = $this->createDbiDummy(); |
559
|
|
|
$dbi = $this->createDatabaseInterface($dummyDbi); |
560
|
|
|
|
561
|
|
|
$relation = new Relation($dbi); |
562
|
|
|
|
563
|
|
|
$dummyDbi->removeDefaultResults(); |
564
|
|
|
$dummyDbi->addResult( |
565
|
|
|
'SHOW TABLES FROM `db_pma`;', |
566
|
|
|
[ |
567
|
|
|
['pma__userconfig'], |
568
|
|
|
// This is important as it tricks default existing table detection |
569
|
|
|
// If the check does not consider the custom name it will skip the table |
570
|
|
|
['pma__relation'], |
571
|
|
|
], |
572
|
|
|
['Tables_in_db_pma'], |
573
|
|
|
); |
574
|
|
|
|
575
|
|
|
$dummyDbi->addResult( |
576
|
|
|
'SHOW TABLES FROM `db_pma`;', |
577
|
|
|
[ |
578
|
|
|
['pma__userconfig'], |
579
|
|
|
// This is important as it tricks default existing table detection |
580
|
|
|
// If the check does not consider the custom name it will skip the table |
581
|
|
|
['pma__relation'], |
582
|
|
|
], |
583
|
|
|
['Tables_in_db_pma'], |
584
|
|
|
); |
585
|
|
|
|
586
|
|
|
$dummyDbi->addResult('SELECT NULL FROM `pma__userconfig` LIMIT 0', []); |
587
|
|
|
|
588
|
|
|
$dummyDbi->addResult( |
589
|
|
|
'-- -------------------------------------------------------- -- --' |
590
|
|
|
. ' Table structure for table `pma__bookmark` ' |
591
|
|
|
. '-- CREATE TABLE IF NOT EXISTS `pma__bookmark` ( ' |
592
|
|
|
. '`id` int(10) unsigned NOT NULL auto_increment,' |
593
|
|
|
. ' `dbase` varchar(255) NOT NULL default \'\',' |
594
|
|
|
. ' `user` varchar(255) NOT NULL default \'\',' |
595
|
|
|
. ' `label` varchar(255) COLLATE utf8_general_ci NOT NULL default \'\',' |
596
|
|
|
. ' `query` text NOT NULL, PRIMARY KEY (`id`) )' |
597
|
|
|
. ' COMMENT=\'Bookmarks\' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', |
598
|
|
|
true, |
599
|
|
|
); |
600
|
|
|
$dummyDbi->addResult( |
601
|
|
|
'-- -------------------------------------------------------- -- --' |
602
|
|
|
. ' Table structure for table `custom_relation_pma` ' |
603
|
|
|
. '-- CREATE TABLE IF NOT EXISTS `custom_relation_pma` ( ' |
604
|
|
|
. '`master_db` varchar(64) NOT NULL default \'\', `master_table` varchar(64) NOT NULL default \'\',' |
605
|
|
|
. ' `master_field` varchar(64) NOT NULL default \'\', `foreign_db` varchar(64) NOT NULL default \'\',' |
606
|
|
|
. ' `foreign_table` varchar(64) NOT NULL default \'\',' |
607
|
|
|
. ' `foreign_field` varchar(64) NOT NULL default \'\',' |
608
|
|
|
. ' PRIMARY KEY (`master_db`,`master_table`,`master_field`),' |
609
|
|
|
. ' KEY `foreign_field` (`foreign_db`,`foreign_table`) ) COMMENT=\'Relation table\'' |
610
|
|
|
. ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', |
611
|
|
|
true, |
612
|
|
|
); |
613
|
|
|
$dummyDbi->addResult( |
614
|
|
|
'-- -------------------------------------------------------- -- --' |
615
|
|
|
. ' Table structure for table `pma__table_info`' |
616
|
|
|
. ' -- CREATE TABLE IF NOT EXISTS `pma__table_info` ( ' |
617
|
|
|
. '`db_name` varchar(64) NOT NULL default \'\', `table_name` varchar(64) NOT NULL default \'\',' |
618
|
|
|
. ' `display_field` varchar(64) NOT NULL default \'\', PRIMARY KEY (`db_name`,`table_name`) )' |
619
|
|
|
. ' COMMENT=\'Table information for phpMyAdmin\' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', |
620
|
|
|
true, |
621
|
|
|
); |
622
|
|
|
|
623
|
|
|
$dummyDbi->addResult( |
624
|
|
|
'-- -------------------------------------------------------- -- --' |
625
|
|
|
. ' Table structure for table `pma__table_coords`' |
626
|
|
|
. ' -- CREATE TABLE IF NOT EXISTS `pma__table_coords` ( ' |
627
|
|
|
. '`db_name` varchar(64) NOT NULL default \'\', `table_name` varchar(64) NOT NULL default \'\',' |
628
|
|
|
. ' `pdf_page_number` int(11) NOT NULL default \'0\', `x` float unsigned NOT NULL default \'0\',' |
629
|
|
|
. ' `y` float unsigned NOT NULL default \'0\',' |
630
|
|
|
. ' PRIMARY KEY (`db_name`,`table_name`,`pdf_page_number`) )' |
631
|
|
|
. ' COMMENT=\'Table coordinates for phpMyAdmin PDF output\'' |
632
|
|
|
. ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', |
633
|
|
|
true, |
634
|
|
|
); |
635
|
|
|
$dummyDbi->addResult( |
636
|
|
|
'-- -------------------------------------------------------- -- --' |
637
|
|
|
. ' Table structure for table `pma__pdf_pages`' |
638
|
|
|
. ' -- CREATE TABLE IF NOT EXISTS `pma__pdf_pages` ( ' |
639
|
|
|
. '`db_name` varchar(64) NOT NULL default \'\', `page_nr` int(10) unsigned NOT NULL auto_increment,' |
640
|
|
|
. ' `page_descr` varchar(50) COLLATE utf8_general_ci NOT NULL default \'\', PRIMARY KEY (`page_nr`),' |
641
|
|
|
. ' KEY `db_name` (`db_name`) ) COMMENT=\'PDF relation pages for phpMyAdmin\'' |
642
|
|
|
. ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', |
643
|
|
|
true, |
644
|
|
|
); |
645
|
|
|
$dummyDbi->addResult( |
646
|
|
|
'-- -------------------------------------------------------- -- --' |
647
|
|
|
. ' Table structure for table `pma__column_info`' |
648
|
|
|
. ' -- CREATE TABLE IF NOT EXISTS `pma__column_info` ( ' |
649
|
|
|
. '`id` int(5) unsigned NOT NULL auto_increment, `db_name` varchar(64) NOT NULL default \'\',' |
650
|
|
|
. ' `table_name` varchar(64) NOT NULL default \'\', `column_name` varchar(64) NOT NULL default \'\',' |
651
|
|
|
. ' `comment` varchar(255) COLLATE utf8_general_ci NOT NULL default \'\',' |
652
|
|
|
. ' `mimetype` varchar(255) COLLATE utf8_general_ci NOT NULL default \'\',' |
653
|
|
|
. ' `transformation` varchar(255) NOT NULL default \'\',' |
654
|
|
|
. ' `transformation_options` varchar(255) NOT NULL default \'\',' |
655
|
|
|
. ' `input_transformation` varchar(255) NOT NULL default \'\',' |
656
|
|
|
. ' `input_transformation_options` varchar(255) NOT NULL default \'\',' |
657
|
|
|
. ' PRIMARY KEY (`id`), UNIQUE KEY `db_name` (`db_name`,`table_name`,`column_name`) )' |
658
|
|
|
. ' COMMENT=\'Column information for phpMyAdmin\' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', |
659
|
|
|
true, |
660
|
|
|
); |
661
|
|
|
$dummyDbi->addResult( |
662
|
|
|
'-- -------------------------------------------------------- -- --' |
663
|
|
|
. ' Table structure for table `pma__history` ' |
664
|
|
|
. '-- CREATE TABLE IF NOT EXISTS `pma__history` ( ' |
665
|
|
|
. '`id` bigint(20) unsigned NOT NULL auto_increment, `username` varchar(64) NOT NULL default \'\',' |
666
|
|
|
. ' `db` varchar(64) NOT NULL default \'\', `table` varchar(64) NOT NULL default \'\',' |
667
|
|
|
. ' `timevalue` timestamp NOT NULL default CURRENT_TIMESTAMP, `sqlquery` text NOT NULL,' |
668
|
|
|
. ' PRIMARY KEY (`id`), KEY `username` (`username`,`db`,`table`,`timevalue`) )' |
669
|
|
|
. ' COMMENT=\'SQL history for phpMyAdmin\' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', |
670
|
|
|
true, |
671
|
|
|
); |
672
|
|
|
$dummyDbi->addResult( |
673
|
|
|
'-- -------------------------------------------------------- -- --' |
674
|
|
|
. ' Table structure for table `pma__recent` ' |
675
|
|
|
. '-- CREATE TABLE IF NOT EXISTS `pma__recent` ( ' |
676
|
|
|
. '`username` varchar(64) NOT NULL, `tables` text NOT NULL, PRIMARY KEY (`username`) )' |
677
|
|
|
. ' COMMENT=\'Recently accessed tables\' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', |
678
|
|
|
true, |
679
|
|
|
); |
680
|
|
|
$dummyDbi->addResult( |
681
|
|
|
'-- -------------------------------------------------------- -- --' |
682
|
|
|
. ' Table structure for table `pma__favorite` ' |
683
|
|
|
. '-- CREATE TABLE IF NOT EXISTS `pma__favorite` ( ' |
684
|
|
|
. '`username` varchar(64) NOT NULL, `tables` text NOT NULL, PRIMARY KEY (`username`) )' |
685
|
|
|
. ' COMMENT=\'Favorite tables\' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', |
686
|
|
|
true, |
687
|
|
|
); |
688
|
|
|
$dummyDbi->addResult( |
689
|
|
|
'-- -------------------------------------------------------- -- --' |
690
|
|
|
. ' Table structure for table `pma__table_uiprefs`' |
691
|
|
|
. ' -- CREATE TABLE IF NOT EXISTS `pma__table_uiprefs` ( ' |
692
|
|
|
. '`username` varchar(64) NOT NULL, `db_name` varchar(64) NOT NULL,' |
693
|
|
|
. ' `table_name` varchar(64) NOT NULL, `prefs` text NOT NULL,' |
694
|
|
|
. ' `last_update` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,' |
695
|
|
|
. ' PRIMARY KEY (`username`,`db_name`,`table_name`) ) COMMENT=\'Tables\'\' UI preferences\'' |
696
|
|
|
. ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', |
697
|
|
|
true, |
698
|
|
|
); |
699
|
|
|
$dummyDbi->addResult( |
700
|
|
|
'-- -------------------------------------------------------- -- --' |
701
|
|
|
. ' Table structure for table `pma__tracking` ' |
702
|
|
|
. '-- CREATE TABLE IF NOT EXISTS `pma__tracking` ( ' |
703
|
|
|
. '`db_name` varchar(64) NOT NULL, `table_name` varchar(64) NOT NULL,' |
704
|
|
|
. ' `version` int(10) unsigned NOT NULL, `date_created` datetime NOT NULL,' |
705
|
|
|
. ' `date_updated` datetime NOT NULL, `schema_snapshot` text NOT NULL,' |
706
|
|
|
. ' `schema_sql` text, `data_sql` longtext, `tracking`' |
707
|
|
|
. ' set(\'UPDATE\',\'REPLACE\',\'INSERT\',\'DELETE\',' |
708
|
|
|
. '\'TRUNCATE\',\'CREATE DATABASE\',\'ALTER DATABASE\',' |
709
|
|
|
. '\'DROP DATABASE\',\'CREATE TABLE\',\'ALTER TABLE\',' |
710
|
|
|
. '\'RENAME TABLE\',\'DROP TABLE\',\'CREATE INDEX\',' |
711
|
|
|
. '\'DROP INDEX\',\'CREATE VIEW\',\'ALTER VIEW\',\'DROP VIEW\')' |
712
|
|
|
. ' default NULL, `tracking_active` int(1) unsigned NOT NULL' |
713
|
|
|
. ' default \'1\', PRIMARY KEY (`db_name`,`table_name`,`version`) )' |
714
|
|
|
. ' COMMENT=\'Database changes tracking for phpMyAdmin\'' |
715
|
|
|
. ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', |
716
|
|
|
true, |
717
|
|
|
); |
718
|
|
|
$dummyDbi->addResult( |
719
|
|
|
'-- -------------------------------------------------------- -- --' |
720
|
|
|
. ' Table structure for table `pma__users` ' |
721
|
|
|
. '-- CREATE TABLE IF NOT EXISTS `pma__users` ( ' |
722
|
|
|
. '`username` varchar(64) NOT NULL, `usergroup` varchar(64) NOT NULL,' |
723
|
|
|
. ' PRIMARY KEY (`username`,`usergroup`) )' |
724
|
|
|
. ' COMMENT=\'Users and their assignments to user groups\'' |
725
|
|
|
. ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', |
726
|
|
|
true, |
727
|
|
|
); |
728
|
|
|
$dummyDbi->addResult( |
729
|
|
|
'-- -------------------------------------------------------- -- --' |
730
|
|
|
. ' Table structure for table `pma__usergroups`' |
731
|
|
|
. ' -- CREATE TABLE IF NOT EXISTS `pma__usergroups` ( ' |
732
|
|
|
. '`usergroup` varchar(64) NOT NULL, `tab` varchar(64) NOT NULL,' |
733
|
|
|
. ' `allowed` enum(\'Y\',\'N\') NOT NULL DEFAULT \'N\',' |
734
|
|
|
. ' PRIMARY KEY (`usergroup`,`tab`,`allowed`) )' |
735
|
|
|
. ' COMMENT=\'User groups with configured menu items\'' |
736
|
|
|
. ' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', |
737
|
|
|
true, |
738
|
|
|
); |
739
|
|
|
$dummyDbi->addResult( |
740
|
|
|
'-- -------------------------------------------------------- -- --' |
741
|
|
|
. ' Table structure for table `pma__navigationhiding`' |
742
|
|
|
. ' -- CREATE TABLE IF NOT EXISTS `pma__navigationhiding` ( ' |
743
|
|
|
. '`username` varchar(64) NOT NULL, `item_name` varchar(64)' |
744
|
|
|
. ' NOT NULL, `item_type` varchar(64) NOT NULL, `db_name` varchar(64) NOT NULL,' |
745
|
|
|
. ' `table_name` varchar(64) NOT NULL,' |
746
|
|
|
. ' PRIMARY KEY (`username`,`item_name`,`item_type`,`db_name`,`table_name`) )' |
747
|
|
|
. ' COMMENT=\'Hidden items of navigation tree\' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', |
748
|
|
|
true, |
749
|
|
|
); |
750
|
|
|
$dummyDbi->addResult( |
751
|
|
|
'-- -------------------------------------------------------- -- --' |
752
|
|
|
. ' Table structure for table `pma__savedsearches`' |
753
|
|
|
. ' -- CREATE TABLE IF NOT EXISTS `pma__savedsearches` ( ' |
754
|
|
|
. '`id` int(5) unsigned NOT NULL auto_increment, `username` varchar(64) NOT NULL default \'\',' |
755
|
|
|
. ' `db_name` varchar(64) NOT NULL default \'\', `search_name` varchar(64) NOT NULL default \'\',' |
756
|
|
|
. ' `search_data` text NOT NULL, PRIMARY KEY (`id`),' |
757
|
|
|
. ' UNIQUE KEY `u_savedsearches_username_dbname` (`username`,`db_name`,`search_name`) )' |
758
|
|
|
. ' COMMENT=\'Saved searches\' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', |
759
|
|
|
true, |
760
|
|
|
); |
761
|
|
|
$dummyDbi->addResult( |
762
|
|
|
'-- -------------------------------------------------------- -- --' |
763
|
|
|
. ' Table structure for table `pma__central_columns`' |
764
|
|
|
. ' -- CREATE TABLE IF NOT EXISTS `pma__central_columns` ( ' |
765
|
|
|
. '`db_name` varchar(64) NOT NULL, `col_name` varchar(64) NOT NULL, `col_type` varchar(64) NOT NULL,' |
766
|
|
|
. ' `col_length` text, `col_collation` varchar(64) NOT NULL, `col_isNull` boolean NOT NULL,' |
767
|
|
|
. ' `col_extra` varchar(255) default \'\', `col_default` text,' |
768
|
|
|
. ' PRIMARY KEY (`db_name`,`col_name`) )' |
769
|
|
|
. ' COMMENT=\'Central list of columns\' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', |
770
|
|
|
true, |
771
|
|
|
); |
772
|
|
|
$dummyDbi->addResult( |
773
|
|
|
'-- -------------------------------------------------------- -- --' |
774
|
|
|
. ' Table structure for table `pma__designer_settings`' |
775
|
|
|
. ' -- CREATE TABLE IF NOT EXISTS `pma__designer_settings` ( ' |
776
|
|
|
. '`username` varchar(64) NOT NULL, `settings_data` text NOT NULL,' |
777
|
|
|
. ' PRIMARY KEY (`username`) )' |
778
|
|
|
. ' COMMENT=\'Settings related to Designer\' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', |
779
|
|
|
true, |
780
|
|
|
); |
781
|
|
|
$dummyDbi->addResult( |
782
|
|
|
'-- -------------------------------------------------------- -- --' |
783
|
|
|
. ' Table structure for table `pma__export_templates`' |
784
|
|
|
. ' -- CREATE TABLE IF NOT EXISTS `pma__export_templates` ( ' |
785
|
|
|
. '`id` int(5) unsigned NOT NULL AUTO_INCREMENT, `username` varchar(64) NOT NULL,' |
786
|
|
|
. ' `export_type` varchar(10) NOT NULL, `template_name` varchar(64) NOT NULL,' |
787
|
|
|
. ' `template_data` text NOT NULL, PRIMARY KEY (`id`),' |
788
|
|
|
. ' UNIQUE KEY `u_user_type_template` (`username`,`export_type`,`template_name`) )' |
789
|
|
|
. ' COMMENT=\'Saved export templates\' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', |
790
|
|
|
true, |
791
|
|
|
); |
792
|
|
|
|
793
|
|
|
self::assertSame('db_pma', $config->selectedServer['pmadb']); |
794
|
|
|
|
795
|
|
|
(new ReflectionProperty(Relation::class, 'cache'))->setValue(null, null); |
796
|
|
|
|
797
|
|
|
$dummyDbi->addSelectDb('db_pma'); |
798
|
|
|
$dummyDbi->addSelectDb('db_pma'); |
799
|
|
|
$relation->fixPmaTables('db_pma', true); |
800
|
|
|
self::assertArrayNotHasKey('message', $GLOBALS); |
801
|
|
|
self::assertSame('db_pma', $config->selectedServer['pmadb']); |
802
|
|
|
|
803
|
|
|
$relationParameters = RelationParameters::fromArray([ |
804
|
|
|
'db' => 'db_pma', |
805
|
|
|
'userconfigwork' => true, |
806
|
|
|
'userconfig' => 'pma__userconfig', |
807
|
|
|
]); |
808
|
|
|
self::assertSame($relationParameters->toArray(), $relation->getRelationParameters()->toArray()); |
809
|
|
|
|
810
|
|
|
$dummyDbi->assertAllQueriesConsumed(); |
811
|
|
|
$dummyDbi->assertAllSelectsConsumed(); |
812
|
|
|
} |
813
|
|
|
|
814
|
|
|
public function testFixPmaTablesNormalFixTablesFails(): void |
815
|
|
|
{ |
816
|
|
|
Current::$database = ''; |
817
|
|
|
$config = Config::getInstance(); |
|
|
|
|
818
|
|
|
$config->selectedServer['user'] = ''; |
819
|
|
|
$config->selectedServer['pmadb'] = ''; |
820
|
|
|
$config->selectedServer['bookmarktable'] = ''; |
821
|
|
|
$config->selectedServer['relation'] = ''; |
822
|
|
|
$config->selectedServer['table_info'] = ''; |
823
|
|
|
$config->selectedServer['table_coords'] = ''; |
824
|
|
|
$config->selectedServer['column_info'] = ''; |
825
|
|
|
$config->selectedServer['pdf_pages'] = ''; |
826
|
|
|
$config->selectedServer['history'] = ''; |
827
|
|
|
$config->selectedServer['recent'] = ''; |
828
|
|
|
$config->selectedServer['favorite'] = ''; |
829
|
|
|
$config->selectedServer['table_uiprefs'] = ''; |
830
|
|
|
$config->selectedServer['tracking'] = ''; |
831
|
|
|
$config->selectedServer['userconfig'] = ''; |
832
|
|
|
$config->selectedServer['users'] = ''; |
833
|
|
|
$config->selectedServer['usergroups'] = ''; |
834
|
|
|
$config->selectedServer['navigationhiding'] = ''; |
835
|
|
|
$config->selectedServer['savedsearches'] = ''; |
836
|
|
|
$config->selectedServer['central_columns'] = ''; |
837
|
|
|
$config->selectedServer['designer_settings'] = ''; |
838
|
|
|
$config->selectedServer['export_templates'] = ''; |
839
|
|
|
|
840
|
|
|
$dummyDbi = $this->createDbiDummy(); |
841
|
|
|
$dbi = $this->createDatabaseInterface($dummyDbi); |
842
|
|
|
|
843
|
|
|
$relation = new Relation($dbi); |
844
|
|
|
|
845
|
|
|
$dummyDbi->removeDefaultResults(); |
846
|
|
|
$dummyDbi->addResult( |
847
|
|
|
'SHOW TABLES FROM `db_pma`;', |
848
|
|
|
[['pma__userconfig']], |
849
|
|
|
['Tables_in_db_pma'], |
850
|
|
|
); |
851
|
|
|
|
852
|
|
|
// Fail the query |
853
|
|
|
$dummyDbi->addErrorCode('MYSQL_ERROR'); |
854
|
|
|
$dummyDbi->addResult( |
855
|
|
|
'-- -------------------------------------------------------- -- --' |
856
|
|
|
. ' Table structure for table `pma__bookmark` ' |
857
|
|
|
. '-- CREATE TABLE IF NOT EXISTS `pma__bookmark` ( ' |
858
|
|
|
. '`id` int(10) unsigned NOT NULL auto_increment,' |
859
|
|
|
. ' `dbase` varchar(255) NOT NULL default \'\',' |
860
|
|
|
. ' `user` varchar(255) NOT NULL default \'\',' |
861
|
|
|
. ' `label` varchar(255) COLLATE utf8_general_ci NOT NULL default \'\',' |
862
|
|
|
. ' `query` text NOT NULL, PRIMARY KEY (`id`) )' |
863
|
|
|
. ' COMMENT=\'Bookmarks\' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', |
864
|
|
|
false, |
865
|
|
|
); |
866
|
|
|
$dummyDbi->addSelectDb('db_pma'); |
867
|
|
|
|
868
|
|
|
self::assertSame('', $config->selectedServer['pmadb']); |
869
|
|
|
|
870
|
|
|
(new ReflectionProperty(Relation::class, 'cache'))->setValue(null, null); |
871
|
|
|
|
872
|
|
|
$relation->fixPmaTables('db_pma', true); |
873
|
|
|
|
874
|
|
|
self::assertArrayHasKey('message', $GLOBALS); |
875
|
|
|
self::assertSame('MYSQL_ERROR', $GLOBALS['message']); |
876
|
|
|
self::assertSame('', $config->selectedServer['pmadb']); |
877
|
|
|
|
878
|
|
|
self::assertNull((new ReflectionProperty(Relation::class, 'cache'))->getValue()); |
879
|
|
|
|
880
|
|
|
$dummyDbi->assertAllQueriesConsumed(); |
881
|
|
|
$dummyDbi->assertAllErrorCodesConsumed(); |
882
|
|
|
$dummyDbi->assertAllSelectsConsumed(); |
883
|
|
|
} |
884
|
|
|
|
885
|
|
|
public function testCreatePmaDatabase(): void |
886
|
|
|
{ |
887
|
|
|
$config = Config::getInstance(); |
|
|
|
|
888
|
|
|
$config->selectedServer['user'] = 'root'; |
889
|
|
|
$config->selectedServer['pmadb'] = 'phpmyadmin'; |
890
|
|
|
|
891
|
|
|
$dummyDbi = $this->createDbiDummy(); |
892
|
|
|
$dbi = $this->createDatabaseInterface($dummyDbi); |
893
|
|
|
|
894
|
|
|
$relation = new Relation($dbi); |
895
|
|
|
|
896
|
|
|
$dummyDbi->removeDefaultResults(); |
897
|
|
|
$dummyDbi->addResult('CREATE DATABASE IF NOT EXISTS `phpmyadmin`', true); |
898
|
|
|
|
899
|
|
|
$dummyDbi->addResult( |
900
|
|
|
'SHOW TABLES FROM `phpmyadmin`;', |
901
|
|
|
[], |
902
|
|
|
); |
903
|
|
|
$dummyDbi->addSelectDb('phpmyadmin'); |
904
|
|
|
|
905
|
|
|
self::assertArrayNotHasKey('errno', $GLOBALS); |
906
|
|
|
|
907
|
|
|
self::assertTrue( |
908
|
|
|
$relation->createPmaDatabase('phpmyadmin'), |
909
|
|
|
); |
910
|
|
|
|
911
|
|
|
self::assertArrayNotHasKey('message', $GLOBALS); |
912
|
|
|
|
913
|
|
|
$dummyDbi->assertAllQueriesConsumed(); |
914
|
|
|
$dummyDbi->assertAllErrorCodesConsumed(); |
915
|
|
|
$dummyDbi->assertAllSelectsConsumed(); |
916
|
|
|
} |
917
|
|
|
|
918
|
|
|
public function testCreatePmaDatabaseFailsError1044(): void |
919
|
|
|
{ |
920
|
|
|
$dummyDbi = $this->createDbiDummy(); |
921
|
|
|
$dbi = $this->createDatabaseInterface($dummyDbi); |
922
|
|
|
|
923
|
|
|
$relation = new Relation($dbi); |
924
|
|
|
|
925
|
|
|
$dummyDbi->removeDefaultResults(); |
926
|
|
|
$dummyDbi->addErrorCode('MYSQL_ERROR'); |
927
|
|
|
$dummyDbi->addResult('CREATE DATABASE IF NOT EXISTS `phpmyadmin`', false); |
928
|
|
|
|
929
|
|
|
$GLOBALS['errno'] = 1044;// ER_DBACCESS_DENIED_ERROR |
930
|
|
|
|
931
|
|
|
self::assertFalse( |
932
|
|
|
$relation->createPmaDatabase('phpmyadmin'), |
933
|
|
|
); |
934
|
|
|
|
935
|
|
|
self::assertArrayHasKey('message', $GLOBALS); |
936
|
|
|
self::assertSame( |
937
|
|
|
'You do not have necessary privileges to create a database named' |
938
|
|
|
. ' \'phpmyadmin\'. You may go to \'Operations\' tab of any' |
939
|
|
|
. ' database to set up the phpMyAdmin configuration storage there.', |
940
|
|
|
$GLOBALS['message'], |
941
|
|
|
); |
942
|
|
|
|
943
|
|
|
$dummyDbi->assertAllQueriesConsumed(); |
944
|
|
|
$dummyDbi->assertAllErrorCodesConsumed(); |
945
|
|
|
} |
946
|
|
|
|
947
|
|
|
public function testCreatePmaDatabaseFailsError1040(): void |
948
|
|
|
{ |
949
|
|
|
$dummyDbi = $this->createDbiDummy(); |
950
|
|
|
$dbi = $this->createDatabaseInterface($dummyDbi); |
951
|
|
|
|
952
|
|
|
$relation = new Relation($dbi); |
953
|
|
|
|
954
|
|
|
$dummyDbi->removeDefaultResults(); |
955
|
|
|
$dummyDbi->addErrorCode('Too many connections'); |
956
|
|
|
$dummyDbi->addResult('CREATE DATABASE IF NOT EXISTS `pma_1040`', false); |
957
|
|
|
|
958
|
|
|
$GLOBALS['errno'] = 1040; |
959
|
|
|
|
960
|
|
|
self::assertFalse( |
961
|
|
|
$relation->createPmaDatabase('pma_1040'), |
962
|
|
|
); |
963
|
|
|
|
964
|
|
|
self::assertArrayHasKey('message', $GLOBALS); |
965
|
|
|
self::assertSame('Too many connections', $GLOBALS['message']); |
966
|
|
|
|
967
|
|
|
$dummyDbi->assertAllQueriesConsumed(); |
968
|
|
|
$dummyDbi->assertAllErrorCodesConsumed(); |
969
|
|
|
} |
970
|
|
|
|
971
|
|
|
public function testGetDefaultPmaTableNames(): void |
972
|
|
|
{ |
973
|
|
|
$dummyDbi = $this->createDbiDummy(); |
974
|
|
|
$dbi = $this->createDatabaseInterface($dummyDbi); |
975
|
|
|
|
976
|
|
|
$relation = new Relation($dbi); |
977
|
|
|
|
978
|
|
|
$data = [ |
979
|
|
|
'pma__bookmark' => implode("\n", [ |
980
|
|
|
'', |
981
|
|
|
'', |
982
|
|
|
'-- --------------------------------------------------------', |
983
|
|
|
'', |
984
|
|
|
'--', |
985
|
|
|
'-- Table structure for table `pma__bookmark`', |
986
|
|
|
'--', |
987
|
|
|
'', |
988
|
|
|
'CREATE TABLE IF NOT EXISTS `pma__bookmark` (', |
989
|
|
|
' `id` int(10) unsigned NOT NULL auto_increment,', |
990
|
|
|
' `dbase` varchar(255) NOT NULL default \'\',', |
991
|
|
|
' `user` varchar(255) NOT NULL default \'\',', |
992
|
|
|
' `label` varchar(255) COLLATE utf8_general_ci NOT NULL default \'\',', |
993
|
|
|
' `query` text NOT NULL,', |
994
|
|
|
' PRIMARY KEY (`id`)', |
995
|
|
|
')', |
996
|
|
|
' COMMENT=\'Bookmarks\'', |
997
|
|
|
' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', |
998
|
|
|
]), |
999
|
|
|
'pma__column_info' => implode("\n", [ |
1000
|
|
|
'', |
1001
|
|
|
'', |
1002
|
|
|
'-- --------------------------------------------------------', |
1003
|
|
|
'', |
1004
|
|
|
'--', |
1005
|
|
|
'-- Table structure for table `pma__column_info`', |
1006
|
|
|
'--', |
1007
|
|
|
'', |
1008
|
|
|
'CREATE TABLE IF NOT EXISTS `pma__column_info` (', |
1009
|
|
|
' `id` int(5) unsigned NOT NULL auto_increment,', |
1010
|
|
|
' `db_name` varchar(64) NOT NULL default \'\',', |
1011
|
|
|
' `table_name` varchar(64) NOT NULL default \'\',', |
1012
|
|
|
' `column_name` varchar(64) NOT NULL default \'\',', |
1013
|
|
|
' `comment` varchar(255) COLLATE utf8_general_ci NOT NULL default \'\',', |
1014
|
|
|
' `mimetype` varchar(255) COLLATE utf8_general_ci NOT NULL default \'\',', |
1015
|
|
|
' `transformation` varchar(255) NOT NULL default \'\',', |
1016
|
|
|
' `transformation_options` varchar(255) NOT NULL default \'\',', |
1017
|
|
|
' `input_transformation` varchar(255) NOT NULL default \'\',', |
1018
|
|
|
' `input_transformation_options` varchar(255) NOT NULL default \'\',', |
1019
|
|
|
' PRIMARY KEY (`id`),', |
1020
|
|
|
' UNIQUE KEY `db_name` (`db_name`,`table_name`,`column_name`)', |
1021
|
|
|
')', |
1022
|
|
|
' COMMENT=\'Column information for phpMyAdmin\'', |
1023
|
|
|
' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', |
1024
|
|
|
]), |
1025
|
|
|
'pma__history' => implode("\n", [ |
1026
|
|
|
'', |
1027
|
|
|
'', |
1028
|
|
|
'-- --------------------------------------------------------', |
1029
|
|
|
'', |
1030
|
|
|
'--', |
1031
|
|
|
'-- Table structure for table `pma__history`', |
1032
|
|
|
'--', |
1033
|
|
|
'', |
1034
|
|
|
'CREATE TABLE IF NOT EXISTS `pma__history` (', |
1035
|
|
|
' `id` bigint(20) unsigned NOT NULL auto_increment,', |
1036
|
|
|
' `username` varchar(64) NOT NULL default \'\',', |
1037
|
|
|
' `db` varchar(64) NOT NULL default \'\',', |
1038
|
|
|
' `table` varchar(64) NOT NULL default \'\',', |
1039
|
|
|
' `timevalue` timestamp NOT NULL default CURRENT_TIMESTAMP,', |
1040
|
|
|
' `sqlquery` text NOT NULL,', |
1041
|
|
|
' PRIMARY KEY (`id`),', |
1042
|
|
|
' KEY `username` (`username`,`db`,`table`,`timevalue`)', |
1043
|
|
|
')', |
1044
|
|
|
' COMMENT=\'SQL history for phpMyAdmin\'', |
1045
|
|
|
' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', |
1046
|
|
|
]), |
1047
|
|
|
'pma__pdf_pages' => implode("\n", [ |
1048
|
|
|
'', |
1049
|
|
|
'', |
1050
|
|
|
'-- --------------------------------------------------------', |
1051
|
|
|
'', |
1052
|
|
|
'--', |
1053
|
|
|
'-- Table structure for table `pma__pdf_pages`', |
1054
|
|
|
'--', |
1055
|
|
|
'', |
1056
|
|
|
'CREATE TABLE IF NOT EXISTS `pma__pdf_pages` (', |
1057
|
|
|
' `db_name` varchar(64) NOT NULL default \'\',', |
1058
|
|
|
' `page_nr` int(10) unsigned NOT NULL auto_increment,', |
1059
|
|
|
' `page_descr` varchar(50) COLLATE utf8_general_ci NOT NULL default \'\',', |
1060
|
|
|
' PRIMARY KEY (`page_nr`),', |
1061
|
|
|
' KEY `db_name` (`db_name`)', |
1062
|
|
|
')', |
1063
|
|
|
' COMMENT=\'PDF relation pages for phpMyAdmin\'', |
1064
|
|
|
' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', |
1065
|
|
|
]), |
1066
|
|
|
'pma__recent' => implode("\n", [ |
1067
|
|
|
'', |
1068
|
|
|
'', |
1069
|
|
|
'-- --------------------------------------------------------', |
1070
|
|
|
'', |
1071
|
|
|
'--', |
1072
|
|
|
'-- Table structure for table `pma__recent`', |
1073
|
|
|
'--', |
1074
|
|
|
'', |
1075
|
|
|
'CREATE TABLE IF NOT EXISTS `pma__recent` (', |
1076
|
|
|
' `username` varchar(64) NOT NULL,', |
1077
|
|
|
' `tables` text NOT NULL,', |
1078
|
|
|
' PRIMARY KEY (`username`)', |
1079
|
|
|
')', |
1080
|
|
|
' COMMENT=\'Recently accessed tables\'', |
1081
|
|
|
' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', |
1082
|
|
|
]), |
1083
|
|
|
'pma__favorite' => implode("\n", [ |
1084
|
|
|
'', |
1085
|
|
|
'', |
1086
|
|
|
'-- --------------------------------------------------------', |
1087
|
|
|
'', |
1088
|
|
|
'--', |
1089
|
|
|
'-- Table structure for table `pma__favorite`', |
1090
|
|
|
'--', |
1091
|
|
|
'', |
1092
|
|
|
'CREATE TABLE IF NOT EXISTS `pma__favorite` (', |
1093
|
|
|
' `username` varchar(64) NOT NULL,', |
1094
|
|
|
' `tables` text NOT NULL,', |
1095
|
|
|
' PRIMARY KEY (`username`)', |
1096
|
|
|
')', |
1097
|
|
|
' COMMENT=\'Favorite tables\'', |
1098
|
|
|
' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', |
1099
|
|
|
]), |
1100
|
|
|
'pma__table_uiprefs' => implode("\n", [ |
1101
|
|
|
'', |
1102
|
|
|
'', |
1103
|
|
|
'-- --------------------------------------------------------', |
1104
|
|
|
'', |
1105
|
|
|
'--', |
1106
|
|
|
'-- Table structure for table `pma__table_uiprefs`', |
1107
|
|
|
'--', |
1108
|
|
|
'', |
1109
|
|
|
'CREATE TABLE IF NOT EXISTS `pma__table_uiprefs` (', |
1110
|
|
|
' `username` varchar(64) NOT NULL,', |
1111
|
|
|
' `db_name` varchar(64) NOT NULL,', |
1112
|
|
|
' `table_name` varchar(64) NOT NULL,', |
1113
|
|
|
' `prefs` text NOT NULL,', |
1114
|
|
|
' `last_update` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,', |
1115
|
|
|
' PRIMARY KEY (`username`,`db_name`,`table_name`)', |
1116
|
|
|
')', |
1117
|
|
|
' COMMENT=\'Tables\'\' UI preferences\'', |
1118
|
|
|
' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', |
1119
|
|
|
]), |
1120
|
|
|
'pma__relation' => implode("\n", [ |
1121
|
|
|
'', |
1122
|
|
|
'', |
1123
|
|
|
'-- --------------------------------------------------------', |
1124
|
|
|
'', |
1125
|
|
|
'--', |
1126
|
|
|
'-- Table structure for table `pma__relation`', |
1127
|
|
|
'--', |
1128
|
|
|
'', |
1129
|
|
|
'CREATE TABLE IF NOT EXISTS `pma__relation` (', |
1130
|
|
|
' `master_db` varchar(64) NOT NULL default \'\',', |
1131
|
|
|
' `master_table` varchar(64) NOT NULL default \'\',', |
1132
|
|
|
' `master_field` varchar(64) NOT NULL default \'\',', |
1133
|
|
|
' `foreign_db` varchar(64) NOT NULL default \'\',', |
1134
|
|
|
' `foreign_table` varchar(64) NOT NULL default \'\',', |
1135
|
|
|
' `foreign_field` varchar(64) NOT NULL default \'\',', |
1136
|
|
|
' PRIMARY KEY (`master_db`,`master_table`,`master_field`),', |
1137
|
|
|
' KEY `foreign_field` (`foreign_db`,`foreign_table`)', |
1138
|
|
|
')', |
1139
|
|
|
' COMMENT=\'Relation table\'', |
1140
|
|
|
' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', |
1141
|
|
|
]), |
1142
|
|
|
'pma__table_coords' => implode("\n", [ |
1143
|
|
|
'', |
1144
|
|
|
'', |
1145
|
|
|
'-- --------------------------------------------------------', |
1146
|
|
|
'', |
1147
|
|
|
'--', |
1148
|
|
|
'-- Table structure for table `pma__table_coords`', |
1149
|
|
|
'--', |
1150
|
|
|
'', |
1151
|
|
|
'CREATE TABLE IF NOT EXISTS `pma__table_coords` (', |
1152
|
|
|
' `db_name` varchar(64) NOT NULL default \'\',', |
1153
|
|
|
' `table_name` varchar(64) NOT NULL default \'\',', |
1154
|
|
|
' `pdf_page_number` int(11) NOT NULL default \'0\',', |
1155
|
|
|
' `x` float unsigned NOT NULL default \'0\',', |
1156
|
|
|
' `y` float unsigned NOT NULL default \'0\',', |
1157
|
|
|
' PRIMARY KEY (`db_name`,`table_name`,`pdf_page_number`)', |
1158
|
|
|
')', |
1159
|
|
|
' COMMENT=\'Table coordinates for phpMyAdmin PDF output\'', |
1160
|
|
|
' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', |
1161
|
|
|
]), |
1162
|
|
|
'pma__table_info' => implode("\n", [ |
1163
|
|
|
'', |
1164
|
|
|
'', |
1165
|
|
|
'-- --------------------------------------------------------', |
1166
|
|
|
'', |
1167
|
|
|
'--', |
1168
|
|
|
'-- Table structure for table `pma__table_info`', |
1169
|
|
|
'--', |
1170
|
|
|
'', |
1171
|
|
|
'CREATE TABLE IF NOT EXISTS `pma__table_info` (', |
1172
|
|
|
' `db_name` varchar(64) NOT NULL default \'\',', |
1173
|
|
|
' `table_name` varchar(64) NOT NULL default \'\',', |
1174
|
|
|
' `display_field` varchar(64) NOT NULL default \'\',', |
1175
|
|
|
' PRIMARY KEY (`db_name`,`table_name`)', |
1176
|
|
|
')', |
1177
|
|
|
' COMMENT=\'Table information for phpMyAdmin\'', |
1178
|
|
|
' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', |
1179
|
|
|
]), |
1180
|
|
|
'pma__tracking' => implode("\n", [ |
1181
|
|
|
'', |
1182
|
|
|
'', |
1183
|
|
|
'-- --------------------------------------------------------', |
1184
|
|
|
'', |
1185
|
|
|
'--', |
1186
|
|
|
'-- Table structure for table `pma__tracking`', |
1187
|
|
|
'--', |
1188
|
|
|
'', |
1189
|
|
|
'CREATE TABLE IF NOT EXISTS `pma__tracking` (', |
1190
|
|
|
' `db_name` varchar(64) NOT NULL,', |
1191
|
|
|
' `table_name` varchar(64) NOT NULL,', |
1192
|
|
|
' `version` int(10) unsigned NOT NULL,', |
1193
|
|
|
' `date_created` datetime NOT NULL,', |
1194
|
|
|
' `date_updated` datetime NOT NULL,', |
1195
|
|
|
' `schema_snapshot` text NOT NULL,', |
1196
|
|
|
' `schema_sql` text,', |
1197
|
|
|
' `data_sql` longtext,', |
1198
|
|
|
' `tracking` set(\'UPDATE\',\'REPLACE\',\'INSERT\',\'DELETE\',' |
1199
|
|
|
. '\'TRUNCATE\',\'CREATE DATABASE\',\'ALTER DATABASE\',\'DROP DATABASE\',' |
1200
|
|
|
. '\'CREATE TABLE\',\'ALTER TABLE\',\'RENAME TABLE\',\'DROP TABLE\',' |
1201
|
|
|
. '\'CREATE INDEX\',\'DROP INDEX\',\'CREATE VIEW\',\'ALTER VIEW\',' |
1202
|
|
|
. '\'DROP VIEW\') default NULL,', |
1203
|
|
|
' `tracking_active` int(1) unsigned NOT NULL default \'1\',', |
1204
|
|
|
' PRIMARY KEY (`db_name`,`table_name`,`version`)', |
1205
|
|
|
')', |
1206
|
|
|
' COMMENT=\'Database changes tracking for phpMyAdmin\'', |
1207
|
|
|
' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', |
1208
|
|
|
]), |
1209
|
|
|
'pma__userconfig' => implode("\n", [ |
1210
|
|
|
'', |
1211
|
|
|
'', |
1212
|
|
|
'-- --------------------------------------------------------', |
1213
|
|
|
'', |
1214
|
|
|
'--', |
1215
|
|
|
'-- Table structure for table `pma__userconfig`', |
1216
|
|
|
'--', |
1217
|
|
|
'', |
1218
|
|
|
'CREATE TABLE IF NOT EXISTS `pma__userconfig` (', |
1219
|
|
|
' `username` varchar(64) NOT NULL,', |
1220
|
|
|
' `timevalue` timestamp NOT NULL default CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,', |
1221
|
|
|
' `config_data` text NOT NULL,', |
1222
|
|
|
' PRIMARY KEY (`username`)', |
1223
|
|
|
')', |
1224
|
|
|
' COMMENT=\'User preferences storage for phpMyAdmin\'', |
1225
|
|
|
' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', |
1226
|
|
|
]), |
1227
|
|
|
'pma__users' => implode("\n", [ |
1228
|
|
|
'', |
1229
|
|
|
'', |
1230
|
|
|
'-- --------------------------------------------------------', |
1231
|
|
|
'', |
1232
|
|
|
'--', |
1233
|
|
|
'-- Table structure for table `pma__users`', |
1234
|
|
|
'--', |
1235
|
|
|
'', |
1236
|
|
|
'CREATE TABLE IF NOT EXISTS `pma__users` (', |
1237
|
|
|
' `username` varchar(64) NOT NULL,', |
1238
|
|
|
' `usergroup` varchar(64) NOT NULL,', |
1239
|
|
|
' PRIMARY KEY (`username`,`usergroup`)', |
1240
|
|
|
')', |
1241
|
|
|
' COMMENT=\'Users and their assignments to user groups\'', |
1242
|
|
|
' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', |
1243
|
|
|
]), |
1244
|
|
|
'pma__usergroups' => implode("\n", [ |
1245
|
|
|
'', |
1246
|
|
|
'', |
1247
|
|
|
'-- --------------------------------------------------------', |
1248
|
|
|
'', |
1249
|
|
|
'--', |
1250
|
|
|
'-- Table structure for table `pma__usergroups`', |
1251
|
|
|
'--', |
1252
|
|
|
'', |
1253
|
|
|
'CREATE TABLE IF NOT EXISTS `pma__usergroups` (', |
1254
|
|
|
' `usergroup` varchar(64) NOT NULL,', |
1255
|
|
|
' `tab` varchar(64) NOT NULL,', |
1256
|
|
|
' `allowed` enum(\'Y\',\'N\') NOT NULL DEFAULT \'N\',', |
1257
|
|
|
' PRIMARY KEY (`usergroup`,`tab`,`allowed`)', |
1258
|
|
|
')', |
1259
|
|
|
' COMMENT=\'User groups with configured menu items\'', |
1260
|
|
|
' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', |
1261
|
|
|
]), |
1262
|
|
|
'pma__navigationhiding' => implode("\n", [ |
1263
|
|
|
'', |
1264
|
|
|
'', |
1265
|
|
|
'-- --------------------------------------------------------', |
1266
|
|
|
'', |
1267
|
|
|
'--', |
1268
|
|
|
'-- Table structure for table `pma__navigationhiding`', |
1269
|
|
|
'--', |
1270
|
|
|
'', |
1271
|
|
|
'CREATE TABLE IF NOT EXISTS `pma__navigationhiding` (', |
1272
|
|
|
' `username` varchar(64) NOT NULL,', |
1273
|
|
|
' `item_name` varchar(64) NOT NULL,', |
1274
|
|
|
' `item_type` varchar(64) NOT NULL,', |
1275
|
|
|
' `db_name` varchar(64) NOT NULL,', |
1276
|
|
|
' `table_name` varchar(64) NOT NULL,', |
1277
|
|
|
' PRIMARY KEY (`username`,`item_name`,`item_type`,`db_name`,`table_name`)', |
1278
|
|
|
')', |
1279
|
|
|
' COMMENT=\'Hidden items of navigation tree\'', |
1280
|
|
|
' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', |
1281
|
|
|
]), |
1282
|
|
|
'pma__savedsearches' => implode("\n", [ |
1283
|
|
|
'', |
1284
|
|
|
'', |
1285
|
|
|
'-- --------------------------------------------------------', |
1286
|
|
|
'', |
1287
|
|
|
'--', |
1288
|
|
|
'-- Table structure for table `pma__savedsearches`', |
1289
|
|
|
'--', |
1290
|
|
|
'', |
1291
|
|
|
'CREATE TABLE IF NOT EXISTS `pma__savedsearches` (', |
1292
|
|
|
' `id` int(5) unsigned NOT NULL auto_increment,', |
1293
|
|
|
' `username` varchar(64) NOT NULL default \'\',', |
1294
|
|
|
' `db_name` varchar(64) NOT NULL default \'\',', |
1295
|
|
|
' `search_name` varchar(64) NOT NULL default \'\',', |
1296
|
|
|
' `search_data` text NOT NULL,', |
1297
|
|
|
' PRIMARY KEY (`id`),', |
1298
|
|
|
' UNIQUE KEY `u_savedsearches_username_dbname` (`username`,`db_name`,`search_name`)', |
1299
|
|
|
')', |
1300
|
|
|
' COMMENT=\'Saved searches\'', |
1301
|
|
|
' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', |
1302
|
|
|
]), |
1303
|
|
|
'pma__central_columns' => implode("\n", [ |
1304
|
|
|
'', |
1305
|
|
|
'', |
1306
|
|
|
'-- --------------------------------------------------------', |
1307
|
|
|
'', |
1308
|
|
|
'--', |
1309
|
|
|
'-- Table structure for table `pma__central_columns`', |
1310
|
|
|
'--', |
1311
|
|
|
'', |
1312
|
|
|
'CREATE TABLE IF NOT EXISTS `pma__central_columns` (', |
1313
|
|
|
' `db_name` varchar(64) NOT NULL,', |
1314
|
|
|
' `col_name` varchar(64) NOT NULL,', |
1315
|
|
|
' `col_type` varchar(64) NOT NULL,', |
1316
|
|
|
' `col_length` text,', |
1317
|
|
|
' `col_collation` varchar(64) NOT NULL,', |
1318
|
|
|
' `col_isNull` boolean NOT NULL,', |
1319
|
|
|
' `col_extra` varchar(255) default \'\',', |
1320
|
|
|
' `col_default` text,', |
1321
|
|
|
' PRIMARY KEY (`db_name`,`col_name`)', |
1322
|
|
|
')', |
1323
|
|
|
' COMMENT=\'Central list of columns\'', |
1324
|
|
|
' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', |
1325
|
|
|
]), |
1326
|
|
|
'pma__designer_settings' => implode("\n", [ |
1327
|
|
|
'', |
1328
|
|
|
'', |
1329
|
|
|
'-- --------------------------------------------------------', |
1330
|
|
|
'', |
1331
|
|
|
'--', |
1332
|
|
|
'-- Table structure for table `pma__designer_settings`', |
1333
|
|
|
'--', |
1334
|
|
|
'', |
1335
|
|
|
'CREATE TABLE IF NOT EXISTS `pma__designer_settings` (', |
1336
|
|
|
' `username` varchar(64) NOT NULL,', |
1337
|
|
|
' `settings_data` text NOT NULL,', |
1338
|
|
|
' PRIMARY KEY (`username`)', |
1339
|
|
|
')', |
1340
|
|
|
' COMMENT=\'Settings related to Designer\'', |
1341
|
|
|
' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', |
1342
|
|
|
]), |
1343
|
|
|
'pma__export_templates' => implode("\n", [ |
1344
|
|
|
'', |
1345
|
|
|
'', |
1346
|
|
|
'-- --------------------------------------------------------', |
1347
|
|
|
'', |
1348
|
|
|
'--', |
1349
|
|
|
'-- Table structure for table `pma__export_templates`', |
1350
|
|
|
'--', |
1351
|
|
|
'', |
1352
|
|
|
'CREATE TABLE IF NOT EXISTS `pma__export_templates` (', |
1353
|
|
|
' `id` int(5) unsigned NOT NULL AUTO_INCREMENT,', |
1354
|
|
|
' `username` varchar(64) NOT NULL,', |
1355
|
|
|
' `export_type` varchar(10) NOT NULL,', |
1356
|
|
|
' `template_name` varchar(64) NOT NULL,', |
1357
|
|
|
' `template_data` text NOT NULL,', |
1358
|
|
|
' PRIMARY KEY (`id`),', |
1359
|
|
|
' UNIQUE KEY `u_user_type_template` (`username`,`export_type`,`template_name`)', |
1360
|
|
|
')', |
1361
|
|
|
' COMMENT=\'Saved export templates\'', |
1362
|
|
|
' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', |
1363
|
|
|
]), |
1364
|
|
|
]; |
1365
|
|
|
|
1366
|
|
|
self::assertSame( |
1367
|
|
|
$data, |
1368
|
|
|
$relation->getCreateTableSqlQueries([]), |
1369
|
|
|
); |
1370
|
|
|
|
1371
|
|
|
$data['pma__export_templates'] = implode("\n", [ |
1372
|
|
|
'', |
1373
|
|
|
'', |
1374
|
|
|
'-- --------------------------------------------------------', |
1375
|
|
|
'', |
1376
|
|
|
'--', |
1377
|
|
|
'-- Table structure for table `db_exporttemplates_pma`', |
1378
|
|
|
'--', |
1379
|
|
|
'', |
1380
|
|
|
'CREATE TABLE IF NOT EXISTS `db_exporttemplates_pma` (', |
1381
|
|
|
' `id` int(5) unsigned NOT NULL AUTO_INCREMENT,', |
1382
|
|
|
' `username` varchar(64) NOT NULL,', |
1383
|
|
|
' `export_type` varchar(10) NOT NULL,', |
1384
|
|
|
' `template_name` varchar(64) NOT NULL,', |
1385
|
|
|
' `template_data` text NOT NULL,', |
1386
|
|
|
' PRIMARY KEY (`id`),', |
1387
|
|
|
' UNIQUE KEY `u_user_type_template` (`username`,`export_type`,`template_name`)', |
1388
|
|
|
')', |
1389
|
|
|
' COMMENT=\'Saved export templates\'', |
1390
|
|
|
' DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;', |
1391
|
|
|
]); |
1392
|
|
|
|
1393
|
|
|
self::assertSame( |
1394
|
|
|
$data, |
1395
|
|
|
$relation->getCreateTableSqlQueries(['pma__export_templates' => 'db_exporttemplates_pma']), |
1396
|
|
|
); |
1397
|
|
|
} |
1398
|
|
|
|
1399
|
|
|
public function testInitRelationParamsCacheDefaultDbNameDbDoesNotExist(): void |
1400
|
|
|
{ |
1401
|
|
|
Current::$database = ''; |
1402
|
|
|
|
1403
|
|
|
$dummyDbi = $this->createDbiDummy(); |
1404
|
|
|
$dbi = $this->createDatabaseInterface($dummyDbi); |
1405
|
|
|
|
1406
|
|
|
$dummyDbi->removeDefaultResults(); |
1407
|
|
|
$dummyDbi->addResult('SHOW TABLES FROM `phpmyadmin`;', false); |
1408
|
|
|
|
1409
|
|
|
$relation = new Relation($dbi); |
1410
|
|
|
$relation->initRelationParamsCache(); |
1411
|
|
|
|
1412
|
|
|
$dummyDbi->assertAllQueriesConsumed(); |
1413
|
|
|
} |
1414
|
|
|
|
1415
|
|
|
public function testInitRelationParamsCacheDefaultDbNameDbExistsServerZero(): void |
1416
|
|
|
{ |
1417
|
|
|
Current::$database = ''; |
1418
|
|
|
Current::$server = 0; |
1419
|
|
|
$config = Config::getInstance(); |
|
|
|
|
1420
|
|
|
$config->selectedServer = []; |
1421
|
|
|
|
1422
|
|
|
$dummyDbi = $this->createDbiDummy(); |
1423
|
|
|
$dbi = $this->createDatabaseInterface($dummyDbi); |
1424
|
|
|
|
1425
|
|
|
$dummyDbi->removeDefaultResults(); |
1426
|
|
|
$dummyDbi->addResult( |
1427
|
|
|
'SHOW TABLES FROM `phpmyadmin`;', |
1428
|
|
|
[['pma__userconfig']], |
1429
|
|
|
['Tables_in_phpmyadmin'], |
1430
|
|
|
); |
1431
|
|
|
|
1432
|
|
|
(new ReflectionProperty(Relation::class, 'cache'))->setValue(null, null); |
1433
|
|
|
|
1434
|
|
|
$relation = new Relation($dbi); |
1435
|
|
|
$relation->initRelationParamsCache(); |
1436
|
|
|
|
1437
|
|
|
// Should all be false for server = 0 |
1438
|
|
|
$relationParameters = RelationParameters::fromArray([]); |
1439
|
|
|
self::assertSame($relationParameters->toArray(), $relation->getRelationParameters()->toArray()); |
1440
|
|
|
|
1441
|
|
|
self::assertEquals([ |
1442
|
|
|
'userconfig' => 'pma__userconfig', |
1443
|
|
|
'pmadb' => false,// This is the expected value for server = 0 |
1444
|
|
|
], $config->selectedServer); |
1445
|
|
|
$dummyDbi->assertAllQueriesConsumed(); |
1446
|
|
|
} |
1447
|
|
|
|
1448
|
|
|
public function testInitRelationParamsCacheDefaultDbNameDbExistsFirstServer(): void |
1449
|
|
|
{ |
1450
|
|
|
Current::$database = ''; |
1451
|
|
|
$config = Config::getInstance(); |
|
|
|
|
1452
|
|
|
$config->selectedServer = []; |
1453
|
|
|
$config->selectedServer['user'] = ''; |
1454
|
|
|
$config->selectedServer['pmadb'] = ''; |
1455
|
|
|
$config->selectedServer['bookmarktable'] = ''; |
1456
|
|
|
$config->selectedServer['relation'] = ''; |
1457
|
|
|
$config->selectedServer['table_info'] = ''; |
1458
|
|
|
$config->selectedServer['table_coords'] = ''; |
1459
|
|
|
$config->selectedServer['column_info'] = ''; |
1460
|
|
|
$config->selectedServer['pdf_pages'] = ''; |
1461
|
|
|
$config->selectedServer['history'] = ''; |
1462
|
|
|
$config->selectedServer['recent'] = ''; |
1463
|
|
|
$config->selectedServer['favorite'] = ''; |
1464
|
|
|
$config->selectedServer['table_uiprefs'] = ''; |
1465
|
|
|
$config->selectedServer['tracking'] = ''; |
1466
|
|
|
$config->selectedServer['userconfig'] = ''; |
1467
|
|
|
$config->selectedServer['users'] = ''; |
1468
|
|
|
$config->selectedServer['usergroups'] = ''; |
1469
|
|
|
$config->selectedServer['navigationhiding'] = ''; |
1470
|
|
|
$config->selectedServer['savedsearches'] = ''; |
1471
|
|
|
$config->selectedServer['central_columns'] = ''; |
1472
|
|
|
$config->selectedServer['designer_settings'] = ''; |
1473
|
|
|
$config->selectedServer['export_templates'] = ''; |
1474
|
|
|
|
1475
|
|
|
$dummyDbi = $this->createDbiDummy(); |
1476
|
|
|
$dbi = $this->createDatabaseInterface($dummyDbi); |
1477
|
|
|
|
1478
|
|
|
$dummyDbi->removeDefaultResults(); |
1479
|
|
|
$dummyDbi->addResult( |
1480
|
|
|
'SHOW TABLES FROM `phpmyadmin`;', |
1481
|
|
|
[['pma__userconfig']], |
1482
|
|
|
['Tables_in_phpmyadmin'], |
1483
|
|
|
); |
1484
|
|
|
|
1485
|
|
|
$dummyDbi->addResult( |
1486
|
|
|
'SHOW TABLES FROM `phpmyadmin`;', |
1487
|
|
|
[['pma__userconfig']], |
1488
|
|
|
['Tables_in_phpmyadmin'], |
1489
|
|
|
); |
1490
|
|
|
|
1491
|
|
|
$dummyDbi->addResult('SELECT NULL FROM `pma__userconfig` LIMIT 0', [], ['NULL']); |
1492
|
|
|
|
1493
|
|
|
(new ReflectionProperty(Relation::class, 'cache'))->setValue(null, null); |
1494
|
|
|
|
1495
|
|
|
$dummyDbi->addSelectDb('phpmyadmin'); |
1496
|
|
|
$relation = new Relation($dbi); |
1497
|
|
|
$relation->initRelationParamsCache(); |
1498
|
|
|
$dummyDbi->assertAllSelectsConsumed(); |
1499
|
|
|
|
1500
|
|
|
// Should all be false for server = 0 |
1501
|
|
|
$relationParameters = RelationParameters::fromArray([ |
1502
|
|
|
'db' => 'phpmyadmin', |
1503
|
|
|
'userconfigwork' => true, |
1504
|
|
|
'userconfig' => 'pma__userconfig', |
1505
|
|
|
]); |
1506
|
|
|
self::assertSame($relationParameters->toArray(), $relation->getRelationParameters()->toArray()); |
1507
|
|
|
|
1508
|
|
|
self::assertSame([ |
1509
|
|
|
'user' => '', |
1510
|
|
|
'pmadb' => 'phpmyadmin', |
1511
|
|
|
'bookmarktable' => '', |
1512
|
|
|
'relation' => '', |
1513
|
|
|
'table_info' => '', |
1514
|
|
|
'table_coords' => '', |
1515
|
|
|
'column_info' => '', |
1516
|
|
|
'pdf_pages' => '', |
1517
|
|
|
'history' => '', |
1518
|
|
|
'recent' => '', |
1519
|
|
|
'favorite' => '', |
1520
|
|
|
'table_uiprefs' => '', |
1521
|
|
|
'tracking' => '', |
1522
|
|
|
'userconfig' => 'pma__userconfig', |
1523
|
|
|
'users' => '', |
1524
|
|
|
'usergroups' => '', |
1525
|
|
|
'navigationhiding' => '', |
1526
|
|
|
'savedsearches' => '', |
1527
|
|
|
'central_columns' => '', |
1528
|
|
|
'designer_settings' => '', |
1529
|
|
|
'export_templates' => '', |
1530
|
|
|
], $config->selectedServer); |
1531
|
|
|
|
1532
|
|
|
$dummyDbi->assertAllQueriesConsumed(); |
1533
|
|
|
} |
1534
|
|
|
|
1535
|
|
|
public function testInitRelationParamsCacheDefaultDbNameDbExistsFirstServerNotWorkingTable(): void |
1536
|
|
|
{ |
1537
|
|
|
Current::$database = ''; |
1538
|
|
|
$config = Config::getInstance(); |
|
|
|
|
1539
|
|
|
$config->selectedServer = []; |
1540
|
|
|
$config->selectedServer['user'] = ''; |
1541
|
|
|
$config->selectedServer['pmadb'] = ''; |
1542
|
|
|
$config->selectedServer['bookmarktable'] = ''; |
1543
|
|
|
$config->selectedServer['relation'] = ''; |
1544
|
|
|
$config->selectedServer['table_info'] = ''; |
1545
|
|
|
$config->selectedServer['table_coords'] = ''; |
1546
|
|
|
$config->selectedServer['column_info'] = ''; |
1547
|
|
|
$config->selectedServer['pdf_pages'] = ''; |
1548
|
|
|
$config->selectedServer['history'] = ''; |
1549
|
|
|
$config->selectedServer['recent'] = ''; |
1550
|
|
|
$config->selectedServer['favorite'] = ''; |
1551
|
|
|
$config->selectedServer['table_uiprefs'] = ''; |
1552
|
|
|
$config->selectedServer['tracking'] = ''; |
1553
|
|
|
$config->selectedServer['userconfig'] = ''; |
1554
|
|
|
$config->selectedServer['users'] = ''; |
1555
|
|
|
$config->selectedServer['usergroups'] = ''; |
1556
|
|
|
$config->selectedServer['navigationhiding'] = ''; |
1557
|
|
|
$config->selectedServer['savedsearches'] = ''; |
1558
|
|
|
$config->selectedServer['central_columns'] = ''; |
1559
|
|
|
$config->selectedServer['designer_settings'] = ''; |
1560
|
|
|
$config->selectedServer['export_templates'] = ''; |
1561
|
|
|
|
1562
|
|
|
$dummyDbi = $this->createDbiDummy(); |
1563
|
|
|
$dbi = $this->createDatabaseInterface($dummyDbi); |
1564
|
|
|
|
1565
|
|
|
$dummyDbi->removeDefaultResults(); |
1566
|
|
|
$dummyDbi->addResult( |
1567
|
|
|
'SHOW TABLES FROM `phpmyadmin`;', |
1568
|
|
|
[['pma__userconfig']], |
1569
|
|
|
['Tables_in_phpmyadmin'], |
1570
|
|
|
); |
1571
|
|
|
|
1572
|
|
|
$dummyDbi->addResult( |
1573
|
|
|
'SHOW TABLES FROM `phpmyadmin`;', |
1574
|
|
|
[['pma__userconfig']], |
1575
|
|
|
['Tables_in_phpmyadmin'], |
1576
|
|
|
); |
1577
|
|
|
|
1578
|
|
|
$dummyDbi->addResult('SELECT NULL FROM `pma__userconfig` LIMIT 0', false); |
1579
|
|
|
|
1580
|
|
|
(new ReflectionProperty(Relation::class, 'cache'))->setValue(null, null); |
1581
|
|
|
|
1582
|
|
|
$dummyDbi->addSelectDb('phpmyadmin'); |
1583
|
|
|
$relation = new Relation($dbi); |
1584
|
|
|
$relation->initRelationParamsCache(); |
1585
|
|
|
$dummyDbi->assertAllSelectsConsumed(); |
1586
|
|
|
|
1587
|
|
|
$relationParameters = RelationParameters::fromArray([ |
1588
|
|
|
'db' => 'phpmyadmin', |
1589
|
|
|
'userconfigwork' => false, |
1590
|
|
|
'userconfig' => 'pma__userconfig', |
1591
|
|
|
]); |
1592
|
|
|
self::assertSame($relationParameters->toArray(), $relation->getRelationParameters()->toArray()); |
1593
|
|
|
|
1594
|
|
|
self::assertSame([ |
1595
|
|
|
'user' => '', |
1596
|
|
|
'pmadb' => 'phpmyadmin', |
1597
|
|
|
'bookmarktable' => '', |
1598
|
|
|
'relation' => '', |
1599
|
|
|
'table_info' => '', |
1600
|
|
|
'table_coords' => '', |
1601
|
|
|
'column_info' => '', |
1602
|
|
|
'pdf_pages' => '', |
1603
|
|
|
'history' => '', |
1604
|
|
|
'recent' => '', |
1605
|
|
|
'favorite' => '', |
1606
|
|
|
'table_uiprefs' => '', |
1607
|
|
|
'tracking' => '', |
1608
|
|
|
'userconfig' => 'pma__userconfig', |
1609
|
|
|
'users' => '', |
1610
|
|
|
'usergroups' => '', |
1611
|
|
|
'navigationhiding' => '', |
1612
|
|
|
'savedsearches' => '', |
1613
|
|
|
'central_columns' => '', |
1614
|
|
|
'designer_settings' => '', |
1615
|
|
|
'export_templates' => '', |
1616
|
|
|
], $config->selectedServer); |
1617
|
|
|
|
1618
|
|
|
$dummyDbi->assertAllQueriesConsumed(); |
1619
|
|
|
} |
1620
|
|
|
|
1621
|
|
|
public function testInitRelationParamsCacheDefaultDbNameDbExistsFirstServerOverride(): void |
1622
|
|
|
{ |
1623
|
|
|
Current::$database = ''; |
1624
|
|
|
$config = Config::getInstance(); |
|
|
|
|
1625
|
|
|
$config->selectedServer = []; |
1626
|
|
|
$config->selectedServer['user'] = ''; |
1627
|
|
|
$config->selectedServer['pmadb'] = 'PMA-storage'; |
1628
|
|
|
$config->selectedServer['bookmarktable'] = ''; |
1629
|
|
|
$config->selectedServer['relation'] = ''; |
1630
|
|
|
$config->selectedServer['table_info'] = ''; |
1631
|
|
|
$config->selectedServer['table_coords'] = ''; |
1632
|
|
|
$config->selectedServer['column_info'] = ''; |
1633
|
|
|
$config->selectedServer['pdf_pages'] = ''; |
1634
|
|
|
$config->selectedServer['history'] = ''; |
1635
|
|
|
$config->selectedServer['recent'] = ''; |
1636
|
|
|
$config->selectedServer['favorite'] = ''; |
1637
|
|
|
$config->selectedServer['table_uiprefs'] = ''; |
1638
|
|
|
$config->selectedServer['tracking'] = ''; |
1639
|
|
|
$config->selectedServer['userconfig'] = 'pma__userconfig_custom'; |
1640
|
|
|
$config->selectedServer['users'] = ''; |
1641
|
|
|
$config->selectedServer['usergroups'] = ''; |
1642
|
|
|
$config->selectedServer['navigationhiding'] = ''; |
1643
|
|
|
$config->selectedServer['savedsearches'] = ''; |
1644
|
|
|
$config->selectedServer['central_columns'] = ''; |
1645
|
|
|
$config->selectedServer['designer_settings'] = ''; |
1646
|
|
|
$config->selectedServer['export_templates'] = ''; |
1647
|
|
|
|
1648
|
|
|
$dummyDbi = $this->createDbiDummy(); |
1649
|
|
|
$dbi = $this->createDatabaseInterface($dummyDbi); |
1650
|
|
|
|
1651
|
|
|
$dummyDbi->removeDefaultResults(); |
1652
|
|
|
$dummyDbi->addResult( |
1653
|
|
|
'SHOW TABLES FROM `PMA-storage`;', |
1654
|
|
|
[['pma__userconfig_custom', 'pma__usergroups']], |
1655
|
|
|
['Tables_in_PMA-storage'], |
1656
|
|
|
); |
1657
|
|
|
|
1658
|
|
|
$dummyDbi->addResult( |
1659
|
|
|
'SHOW TABLES FROM `PMA-storage`;', |
1660
|
|
|
[['pma__userconfig_custom', 'pma__usergroups']], |
1661
|
|
|
['Tables_in_PMA-storage'], |
1662
|
|
|
); |
1663
|
|
|
|
1664
|
|
|
$dummyDbi->addResult('SELECT NULL FROM `pma__userconfig_custom` LIMIT 0', [], ['NULL']); |
1665
|
|
|
|
1666
|
|
|
$dummyDbi->addSelectDb('PMA-storage'); |
1667
|
|
|
|
1668
|
|
|
(new ReflectionProperty(Relation::class, 'cache'))->setValue(null, null); |
1669
|
|
|
|
1670
|
|
|
$relation = new Relation($dbi); |
1671
|
|
|
$relation->initRelationParamsCache(); |
1672
|
|
|
|
1673
|
|
|
self::assertArrayHasKey( |
1674
|
|
|
'relation', |
1675
|
|
|
$relation->getRelationParameters()->toArray(), |
1676
|
|
|
'The cache is expected to be filled because the custom override' |
1677
|
|
|
. 'was understood (pma__userconfig vs pma__userconfig_custom)', |
1678
|
|
|
); |
1679
|
|
|
|
1680
|
|
|
$dummyDbi->assertAllQueriesConsumed(); |
1681
|
|
|
$dummyDbi->assertAllSelectsConsumed(); |
1682
|
|
|
|
1683
|
|
|
$dummyDbi->addResult( |
1684
|
|
|
'SHOW TABLES FROM `PMA-storage`;', |
1685
|
|
|
[['pma__userconfig_custom', 'pma__usergroups']], |
1686
|
|
|
['Tables_in_PMA-storage'], |
1687
|
|
|
); |
1688
|
|
|
|
1689
|
|
|
$dummyDbi->addResult('SELECT NULL FROM `pma__userconfig_custom` LIMIT 0', [], ['NULL']); |
1690
|
|
|
|
1691
|
|
|
$dummyDbi->addSelectDb('PMA-storage'); |
1692
|
|
|
(new ReflectionProperty(Relation::class, 'cache'))->setValue(null, null); |
1693
|
|
|
$relationData = $relation->getRelationParameters(); |
1694
|
|
|
$dummyDbi->assertAllSelectsConsumed(); |
1695
|
|
|
|
1696
|
|
|
$relationParameters = RelationParameters::fromArray([ |
1697
|
|
|
'db' => 'PMA-storage', |
1698
|
|
|
'userconfigwork' => true, |
1699
|
|
|
'userconfig' => 'pma__userconfig_custom', |
1700
|
|
|
]); |
1701
|
|
|
self::assertSame($relationParameters->toArray(), $relationData->toArray()); |
1702
|
|
|
|
1703
|
|
|
self::assertSame([ |
1704
|
|
|
'user' => '', |
1705
|
|
|
'pmadb' => 'PMA-storage', |
1706
|
|
|
'bookmarktable' => '', |
1707
|
|
|
'relation' => '', |
1708
|
|
|
'table_info' => '', |
1709
|
|
|
'table_coords' => '', |
1710
|
|
|
'column_info' => '', |
1711
|
|
|
'pdf_pages' => '', |
1712
|
|
|
'history' => '', |
1713
|
|
|
'recent' => '', |
1714
|
|
|
'favorite' => '', |
1715
|
|
|
'table_uiprefs' => '', |
1716
|
|
|
'tracking' => '', |
1717
|
|
|
'userconfig' => 'pma__userconfig_custom', |
1718
|
|
|
'users' => '', |
1719
|
|
|
'usergroups' => '', |
1720
|
|
|
'navigationhiding' => '', |
1721
|
|
|
'savedsearches' => '', |
1722
|
|
|
'central_columns' => '', |
1723
|
|
|
'designer_settings' => '', |
1724
|
|
|
'export_templates' => '', |
1725
|
|
|
], $config->selectedServer); |
1726
|
|
|
|
1727
|
|
|
$dummyDbi->assertAllQueriesConsumed(); |
1728
|
|
|
} |
1729
|
|
|
|
1730
|
|
|
public function testInitRelationParamsDisabledTracking(): void |
1731
|
|
|
{ |
1732
|
|
|
Current::$database = ''; |
1733
|
|
|
$config = Config::getInstance(); |
|
|
|
|
1734
|
|
|
$config->selectedServer = []; |
1735
|
|
|
$config->selectedServer['user'] = ''; |
1736
|
|
|
$config->selectedServer['pmadb'] = 'PMA-storage'; |
1737
|
|
|
$config->selectedServer['bookmarktable'] = ''; |
1738
|
|
|
$config->selectedServer['relation'] = ''; |
1739
|
|
|
$config->selectedServer['table_info'] = ''; |
1740
|
|
|
$config->selectedServer['table_coords'] = ''; |
1741
|
|
|
$config->selectedServer['column_info'] = ''; |
1742
|
|
|
$config->selectedServer['pdf_pages'] = ''; |
1743
|
|
|
$config->selectedServer['history'] = ''; |
1744
|
|
|
$config->selectedServer['recent'] = ''; |
1745
|
|
|
$config->selectedServer['favorite'] = ''; |
1746
|
|
|
$config->selectedServer['table_uiprefs'] = ''; |
1747
|
|
|
$config->selectedServer['tracking'] = false; |
1748
|
|
|
$config->selectedServer['userconfig'] = ''; |
1749
|
|
|
$config->selectedServer['users'] = ''; |
1750
|
|
|
$config->selectedServer['usergroups'] = ''; |
1751
|
|
|
$config->selectedServer['navigationhiding'] = ''; |
1752
|
|
|
$config->selectedServer['savedsearches'] = ''; |
1753
|
|
|
$config->selectedServer['central_columns'] = ''; |
1754
|
|
|
$config->selectedServer['designer_settings'] = ''; |
1755
|
|
|
$config->selectedServer['export_templates'] = ''; |
1756
|
|
|
|
1757
|
|
|
$dummyDbi = $this->createDbiDummy(); |
1758
|
|
|
$dbi = $this->createDatabaseInterface($dummyDbi); |
1759
|
|
|
|
1760
|
|
|
$dummyDbi->removeDefaultResults(); |
1761
|
|
|
$dummyDbi->addResult( |
1762
|
|
|
'SHOW TABLES FROM `PMA-storage`;', |
1763
|
|
|
[ |
1764
|
|
|
['pma__tracking'], |
1765
|
|
|
], |
1766
|
|
|
['Tables_in_PMA-storage'], |
1767
|
|
|
); |
1768
|
|
|
$dummyDbi->addResult( |
1769
|
|
|
'SHOW TABLES FROM `PMA-storage`;', |
1770
|
|
|
[ |
1771
|
|
|
['pma__tracking'], |
1772
|
|
|
], |
1773
|
|
|
['Tables_in_PMA-storage'], |
1774
|
|
|
); |
1775
|
|
|
|
1776
|
|
|
$dummyDbi->addSelectDb('PMA-storage'); |
1777
|
|
|
|
1778
|
|
|
(new ReflectionProperty(Relation::class, 'cache'))->setValue(null, null); |
1779
|
|
|
|
1780
|
|
|
$relation = new Relation($dbi); |
1781
|
|
|
$relation->initRelationParamsCache(); |
1782
|
|
|
|
1783
|
|
|
/** |
1784
|
|
|
* TODO: Warning! This test doesn't actually test anything. |
1785
|
|
|
* The method above does't initialize Relation param cache. |
1786
|
|
|
* A proper test is needed to verify that the user disabled features result in disabled Relation cache. |
1787
|
|
|
*/ |
1788
|
|
|
self::assertArrayHasKey( |
1789
|
|
|
'relation', |
1790
|
|
|
$relation->getRelationParameters()->toArray(), |
1791
|
|
|
'The cache is expected to be filled because the custom override' |
1792
|
|
|
. 'was understood', |
1793
|
|
|
); |
1794
|
|
|
|
1795
|
|
|
$dummyDbi->assertAllQueriesConsumed(); |
1796
|
|
|
$dummyDbi->assertAllSelectsConsumed(); |
1797
|
|
|
|
1798
|
|
|
$dummyDbi->addResult( |
1799
|
|
|
'SHOW TABLES FROM `PMA-storage`;', |
1800
|
|
|
[ |
1801
|
|
|
[ |
1802
|
|
|
'pma__userconfig_custom', |
1803
|
|
|
'pma__usergroups', |
1804
|
|
|
], |
1805
|
|
|
], |
1806
|
|
|
['Tables_in_PMA-storage'], |
1807
|
|
|
); |
1808
|
|
|
|
1809
|
|
|
$dummyDbi->addSelectDb('PMA-storage'); |
1810
|
|
|
(new ReflectionProperty(Relation::class, 'cache'))->setValue(null, null); |
1811
|
|
|
$relationData = $relation->getRelationParameters(); |
1812
|
|
|
$dummyDbi->assertAllSelectsConsumed(); |
1813
|
|
|
|
1814
|
|
|
$relationParameters = RelationParameters::fromArray([ |
1815
|
|
|
'db' => 'PMA-storage', |
1816
|
|
|
'trackingwork' => false, |
1817
|
|
|
'tracking' => false, |
1818
|
|
|
]); |
1819
|
|
|
self::assertSame($relationParameters->toArray(), $relationData->toArray()); |
1820
|
|
|
self::assertNull($relationParameters->trackingFeature, 'The feature should not be enabled'); |
1821
|
|
|
|
1822
|
|
|
self::assertSame([ |
1823
|
|
|
'user' => '', |
1824
|
|
|
'pmadb' => 'PMA-storage', |
1825
|
|
|
'bookmarktable' => '', |
1826
|
|
|
'relation' => '', |
1827
|
|
|
'table_info' => '', |
1828
|
|
|
'table_coords' => '', |
1829
|
|
|
'column_info' => '', |
1830
|
|
|
'pdf_pages' => '', |
1831
|
|
|
'history' => '', |
1832
|
|
|
'recent' => '', |
1833
|
|
|
'favorite' => '', |
1834
|
|
|
'table_uiprefs' => '', |
1835
|
|
|
'tracking' => false, |
1836
|
|
|
'userconfig' => '', |
1837
|
|
|
'users' => '', |
1838
|
|
|
'usergroups' => '', |
1839
|
|
|
'navigationhiding' => '', |
1840
|
|
|
'savedsearches' => '', |
1841
|
|
|
'central_columns' => '', |
1842
|
|
|
'designer_settings' => '', |
1843
|
|
|
'export_templates' => '', |
1844
|
|
|
], $config->selectedServer); |
1845
|
|
|
|
1846
|
|
|
$dummyDbi->assertAllQueriesConsumed(); |
1847
|
|
|
} |
1848
|
|
|
|
1849
|
|
|
public function testInitRelationParamsDisabledTrackingOthersExist(): void |
1850
|
|
|
{ |
1851
|
|
|
Current::$database = ''; |
1852
|
|
|
$config = Config::getInstance(); |
|
|
|
|
1853
|
|
|
$config->selectedServer = []; |
1854
|
|
|
$config->selectedServer['user'] = ''; |
1855
|
|
|
$config->selectedServer['pmadb'] = 'PMA-storage'; |
1856
|
|
|
$config->selectedServer['bookmarktable'] = ''; |
1857
|
|
|
$config->selectedServer['relation'] = ''; |
1858
|
|
|
$config->selectedServer['table_info'] = ''; |
1859
|
|
|
$config->selectedServer['table_coords'] = ''; |
1860
|
|
|
$config->selectedServer['column_info'] = ''; |
1861
|
|
|
$config->selectedServer['pdf_pages'] = ''; |
1862
|
|
|
$config->selectedServer['history'] = ''; |
1863
|
|
|
$config->selectedServer['recent'] = ''; |
1864
|
|
|
$config->selectedServer['favorite'] = 'pma__favorite_custom'; |
1865
|
|
|
$config->selectedServer['table_uiprefs'] = ''; |
1866
|
|
|
$config->selectedServer['tracking'] = false; |
1867
|
|
|
$config->selectedServer['userconfig'] = ''; |
1868
|
|
|
$config->selectedServer['users'] = ''; |
1869
|
|
|
$config->selectedServer['usergroups'] = ''; |
1870
|
|
|
$config->selectedServer['navigationhiding'] = ''; |
1871
|
|
|
$config->selectedServer['savedsearches'] = ''; |
1872
|
|
|
$config->selectedServer['central_columns'] = ''; |
1873
|
|
|
$config->selectedServer['designer_settings'] = ''; |
1874
|
|
|
$config->selectedServer['export_templates'] = ''; |
1875
|
|
|
|
1876
|
|
|
$dummyDbi = $this->createDbiDummy(); |
1877
|
|
|
$dbi = $this->createDatabaseInterface($dummyDbi); |
1878
|
|
|
DatabaseInterface::$instance = $dbi; |
1879
|
|
|
|
1880
|
|
|
$dummyDbi->removeDefaultResults(); |
1881
|
|
|
$dummyDbi->addSelectDb('PMA-storage'); |
1882
|
|
|
$dummyDbi->addResult( |
1883
|
|
|
'SHOW TABLES FROM `PMA-storage`;', |
1884
|
|
|
[ |
1885
|
|
|
['pma__favorite_custom'], |
1886
|
|
|
], |
1887
|
|
|
['Tables_in_PMA-storage'], |
1888
|
|
|
); |
1889
|
|
|
|
1890
|
|
|
$dummyDbi->addResult( |
1891
|
|
|
'SHOW TABLES FROM `PMA-storage`;', |
1892
|
|
|
[ |
1893
|
|
|
['pma__favorite_custom'], |
1894
|
|
|
], |
1895
|
|
|
['Tables_in_PMA-storage'], |
1896
|
|
|
); |
1897
|
|
|
|
1898
|
|
|
$dummyDbi->addResult('SELECT NULL FROM `pma__favorite_custom` LIMIT 0', [], ['NULL']); |
1899
|
|
|
|
1900
|
|
|
$_SESSION['tmpval'] = []; |
1901
|
|
|
(new ReflectionProperty(Relation::class, 'cache'))->setValue(null, null); |
1902
|
|
|
(new ReflectionProperty(RecentFavoriteTables::class, 'instances'))->setValue(null, []); |
1903
|
|
|
|
1904
|
|
|
$relation = new Relation($dbi); |
1905
|
|
|
$relation->initRelationParamsCache(); |
1906
|
|
|
|
1907
|
|
|
self::assertArrayHasKey( |
1908
|
|
|
'relation', |
1909
|
|
|
$relation->getRelationParameters()->toArray(), |
1910
|
|
|
'The cache is expected to be filled because the custom override' |
1911
|
|
|
. 'was understood', |
1912
|
|
|
); |
1913
|
|
|
|
1914
|
|
|
$dummyDbi->assertAllQueriesConsumed(); |
1915
|
|
|
$dummyDbi->assertAllSelectsConsumed(); |
1916
|
|
|
|
1917
|
|
|
$relationData = $relation->getRelationParameters(); |
1918
|
|
|
$dummyDbi->assertAllSelectsConsumed(); |
1919
|
|
|
|
1920
|
|
|
$relationParameters = RelationParameters::fromArray([ |
1921
|
|
|
'db' => 'PMA-storage', |
1922
|
|
|
'trackingwork' => false, |
1923
|
|
|
'tracking' => false, |
1924
|
|
|
'favorite' => 'pma__favorite_custom', |
1925
|
|
|
'favoritework' => true, |
1926
|
|
|
]); |
1927
|
|
|
self::assertSame($relationParameters->toArray(), $relationData->toArray()); |
1928
|
|
|
self::assertNull($relationParameters->trackingFeature, 'The feature should not be enabled'); |
1929
|
|
|
|
1930
|
|
|
self::assertSame([ |
1931
|
|
|
'user' => '', |
1932
|
|
|
'pmadb' => 'PMA-storage', |
1933
|
|
|
'bookmarktable' => '', |
1934
|
|
|
'relation' => '', |
1935
|
|
|
'table_info' => '', |
1936
|
|
|
'table_coords' => '', |
1937
|
|
|
'column_info' => '', |
1938
|
|
|
'pdf_pages' => '', |
1939
|
|
|
'history' => '', |
1940
|
|
|
'recent' => '', |
1941
|
|
|
'favorite' => 'pma__favorite_custom', |
1942
|
|
|
'table_uiprefs' => '', |
1943
|
|
|
'tracking' => false, |
1944
|
|
|
'userconfig' => '', |
1945
|
|
|
'users' => '', |
1946
|
|
|
'usergroups' => '', |
1947
|
|
|
'navigationhiding' => '', |
1948
|
|
|
'savedsearches' => '', |
1949
|
|
|
'central_columns' => '', |
1950
|
|
|
'designer_settings' => '', |
1951
|
|
|
'export_templates' => '', |
1952
|
|
|
], $config->selectedServer); |
1953
|
|
|
|
1954
|
|
|
$dummyDbi->assertAllQueriesConsumed(); |
1955
|
|
|
} |
1956
|
|
|
|
1957
|
|
|
public function testArePmadbTablesDefinedAndArePmadbTablesAllDisabled(): void |
1958
|
|
|
{ |
1959
|
|
|
$config = Config::getInstance(); |
|
|
|
|
1960
|
|
|
$config->selectedServer['bookmarktable'] = ''; |
1961
|
|
|
$config->selectedServer['relation'] = ''; |
1962
|
|
|
$config->selectedServer['table_info'] = ''; |
1963
|
|
|
$config->selectedServer['table_coords'] = ''; |
1964
|
|
|
$config->selectedServer['column_info'] = ''; |
1965
|
|
|
$config->selectedServer['pdf_pages'] = ''; |
1966
|
|
|
$config->selectedServer['history'] = ''; |
1967
|
|
|
$config->selectedServer['recent'] = ''; |
1968
|
|
|
$config->selectedServer['favorite'] = ''; |
1969
|
|
|
$config->selectedServer['table_uiprefs'] = ''; |
1970
|
|
|
$config->selectedServer['tracking'] = ''; |
1971
|
|
|
$config->selectedServer['userconfig'] = ''; |
1972
|
|
|
$config->selectedServer['users'] = ''; |
1973
|
|
|
$config->selectedServer['usergroups'] = ''; |
1974
|
|
|
$config->selectedServer['navigationhiding'] = ''; |
1975
|
|
|
$config->selectedServer['savedsearches'] = ''; |
1976
|
|
|
$config->selectedServer['central_columns'] = ''; |
1977
|
|
|
$config->selectedServer['designer_settings'] = ''; |
1978
|
|
|
$config->selectedServer['export_templates'] = ''; |
1979
|
|
|
|
1980
|
|
|
$dbi = $this->createDatabaseInterface(); |
1981
|
|
|
DatabaseInterface::$instance = $dbi; |
1982
|
|
|
|
1983
|
|
|
(new ReflectionProperty(Relation::class, 'cache'))->setValue(null, null); |
1984
|
|
|
|
1985
|
|
|
$relation = new Relation($dbi); |
1986
|
|
|
|
1987
|
|
|
self::assertFalse($relation->arePmadbTablesDefined()); |
1988
|
|
|
self::assertFalse($relation->arePmadbTablesAllDisabled()); |
1989
|
|
|
|
1990
|
|
|
$config->selectedServer['bookmarktable'] = ''; |
1991
|
|
|
$config->selectedServer['relation'] = ''; |
1992
|
|
|
$config->selectedServer['table_info'] = ''; |
1993
|
|
|
$config->selectedServer['table_coords'] = ''; |
1994
|
|
|
$config->selectedServer['column_info'] = ''; |
1995
|
|
|
$config->selectedServer['pdf_pages'] = ''; |
1996
|
|
|
$config->selectedServer['history'] = ''; |
1997
|
|
|
$config->selectedServer['recent'] = ''; |
1998
|
|
|
$config->selectedServer['favorite'] = 'pma__favorite_custom'; |
1999
|
|
|
$config->selectedServer['table_uiprefs'] = ''; |
2000
|
|
|
$config->selectedServer['tracking'] = false; |
2001
|
|
|
$config->selectedServer['userconfig'] = ''; |
2002
|
|
|
$config->selectedServer['users'] = ''; |
2003
|
|
|
$config->selectedServer['usergroups'] = ''; |
2004
|
|
|
$config->selectedServer['navigationhiding'] = ''; |
2005
|
|
|
$config->selectedServer['savedsearches'] = ''; |
2006
|
|
|
$config->selectedServer['central_columns'] = ''; |
2007
|
|
|
$config->selectedServer['designer_settings'] = ''; |
2008
|
|
|
$config->selectedServer['export_templates'] = ''; |
2009
|
|
|
|
2010
|
|
|
self::assertFalse($relation->arePmadbTablesDefined()); |
2011
|
|
|
self::assertFalse($relation->arePmadbTablesAllDisabled()); |
2012
|
|
|
|
2013
|
|
|
$config->selectedServer['bookmarktable'] = 'pma__bookmark'; |
2014
|
|
|
$config->selectedServer['relation'] = 'pma__relation'; |
2015
|
|
|
$config->selectedServer['table_info'] = 'pma__table_info'; |
2016
|
|
|
$config->selectedServer['table_coords'] = 'pma__table_coords'; |
2017
|
|
|
$config->selectedServer['pdf_pages'] = 'pma__pdf_pages'; |
2018
|
|
|
$config->selectedServer['column_info'] = 'pma__column_info'; |
2019
|
|
|
$config->selectedServer['history'] = 'pma__history'; |
2020
|
|
|
$config->selectedServer['table_uiprefs'] = 'pma__table_uiprefs'; |
2021
|
|
|
$config->selectedServer['tracking'] = 'pma__tracking'; |
2022
|
|
|
$config->selectedServer['userconfig'] = 'pma__userconfig'; |
2023
|
|
|
$config->selectedServer['recent'] = 'pma__recent'; |
2024
|
|
|
$config->selectedServer['favorite'] = 'pma__favorite'; |
2025
|
|
|
$config->selectedServer['users'] = 'pma__users'; |
2026
|
|
|
$config->selectedServer['usergroups'] = 'pma__usergroups'; |
2027
|
|
|
$config->selectedServer['navigationhiding'] = 'pma__navigationhiding'; |
2028
|
|
|
$config->selectedServer['savedsearches'] = 'pma__savedsearches'; |
2029
|
|
|
$config->selectedServer['central_columns'] = 'pma__central_columns'; |
2030
|
|
|
$config->selectedServer['designer_settings'] = 'pma__designer_settings'; |
2031
|
|
|
$config->selectedServer['export_templates'] = 'pma__export_templates'; |
2032
|
|
|
|
2033
|
|
|
self::assertTrue($relation->arePmadbTablesDefined()); |
2034
|
|
|
self::assertFalse($relation->arePmadbTablesAllDisabled()); |
2035
|
|
|
|
2036
|
|
|
$config->selectedServer['bookmarktable'] = 'pma__bookmark'; |
2037
|
|
|
$config->selectedServer['relation'] = 'pma__relation'; |
2038
|
|
|
$config->selectedServer['table_info'] = 'pma__table_info'; |
2039
|
|
|
$config->selectedServer['table_coords'] = 'pma__table_coords'; |
2040
|
|
|
$config->selectedServer['pdf_pages'] = 'pma__pdf_pages'; |
2041
|
|
|
$config->selectedServer['column_info'] = 'pma__column_info'; |
2042
|
|
|
$config->selectedServer['history'] = 'custom_name'; |
2043
|
|
|
$config->selectedServer['table_uiprefs'] = 'pma__table_uiprefs'; |
2044
|
|
|
$config->selectedServer['tracking'] = 'pma__tracking'; |
2045
|
|
|
$config->selectedServer['userconfig'] = 'pma__userconfig'; |
2046
|
|
|
$config->selectedServer['recent'] = 'pma__recent'; |
2047
|
|
|
$config->selectedServer['favorite'] = 'pma__favorite'; |
2048
|
|
|
$config->selectedServer['users'] = 'pma__users'; |
2049
|
|
|
$config->selectedServer['usergroups'] = 'pma__usergroups'; |
2050
|
|
|
$config->selectedServer['navigationhiding'] = 'pma__navigationhiding'; |
2051
|
|
|
$config->selectedServer['savedsearches'] = 'pma__savedsearches'; |
2052
|
|
|
$config->selectedServer['central_columns'] = 'pma__central_columns'; |
2053
|
|
|
$config->selectedServer['designer_settings'] = 'pma__designer_settings'; |
2054
|
|
|
$config->selectedServer['export_templates'] = 'pma__export_templates'; |
2055
|
|
|
|
2056
|
|
|
self::assertTrue($relation->arePmadbTablesDefined()); |
2057
|
|
|
self::assertFalse($relation->arePmadbTablesAllDisabled()); |
2058
|
|
|
|
2059
|
|
|
$config->selectedServer['bookmarktable'] = 'pma__bookmark'; |
2060
|
|
|
$config->selectedServer['relation'] = 'pma__relation'; |
2061
|
|
|
$config->selectedServer['table_info'] = 'pma__table_info'; |
2062
|
|
|
$config->selectedServer['table_coords'] = 'pma__table_coords'; |
2063
|
|
|
$config->selectedServer['pdf_pages'] = 'pma__pdf_pages'; |
2064
|
|
|
$config->selectedServer['column_info'] = 'pma__column_info'; |
2065
|
|
|
$config->selectedServer['history'] = 'pma__history'; |
2066
|
|
|
$config->selectedServer['table_uiprefs'] = 'pma__table_uiprefs'; |
2067
|
|
|
$config->selectedServer['tracking'] = 'pma__tracking'; |
2068
|
|
|
$config->selectedServer['userconfig'] = ''; |
2069
|
|
|
$config->selectedServer['recent'] = 'pma__recent'; |
2070
|
|
|
$config->selectedServer['favorite'] = 'pma__favorite'; |
2071
|
|
|
$config->selectedServer['users'] = 'pma__users'; |
2072
|
|
|
$config->selectedServer['usergroups'] = 'pma__usergroups'; |
2073
|
|
|
$config->selectedServer['navigationhiding'] = 'pma__navigationhiding'; |
2074
|
|
|
$config->selectedServer['savedsearches'] = 'pma__savedsearches'; |
2075
|
|
|
$config->selectedServer['central_columns'] = 'pma__central_columns'; |
2076
|
|
|
$config->selectedServer['designer_settings'] = 'pma__designer_settings'; |
2077
|
|
|
$config->selectedServer['export_templates'] = 'pma__export_templates'; |
2078
|
|
|
|
2079
|
|
|
self::assertFalse($relation->arePmadbTablesDefined()); |
2080
|
|
|
self::assertFalse($relation->arePmadbTablesAllDisabled()); |
2081
|
|
|
|
2082
|
|
|
$config->selectedServer['bookmarktable'] = false; //'pma__bookmark'; |
2083
|
|
|
$config->selectedServer['relation'] = false; //'pma__relation'; |
2084
|
|
|
$config->selectedServer['table_info'] = false; //'pma__table_info'; |
2085
|
|
|
$config->selectedServer['table_coords'] = false; //'pma__table_coords'; |
2086
|
|
|
$config->selectedServer['pdf_pages'] = false; //'pma__pdf_pages'; |
2087
|
|
|
$config->selectedServer['column_info'] = false; //'pma__column_info'; |
2088
|
|
|
$config->selectedServer['history'] = false; //'pma__history'; |
2089
|
|
|
$config->selectedServer['table_uiprefs'] = false; //'pma__table_uiprefs'; |
2090
|
|
|
$config->selectedServer['tracking'] = false; //'pma__tracking'; |
2091
|
|
|
$config->selectedServer['userconfig'] = false; //'pma__userconfig'; |
2092
|
|
|
$config->selectedServer['recent'] = false; //'pma__recent'; |
2093
|
|
|
$config->selectedServer['favorite'] = false; //'pma__favorite'; |
2094
|
|
|
$config->selectedServer['users'] = false; //'pma__users'; |
2095
|
|
|
$config->selectedServer['usergroups'] = false; //'pma__usergroups'; |
2096
|
|
|
$config->selectedServer['navigationhiding'] = false; //'pma__navigationhiding'; |
2097
|
|
|
$config->selectedServer['savedsearches'] = false; //'pma__savedsearches'; |
2098
|
|
|
$config->selectedServer['central_columns'] = false; //'pma__central_columns'; |
2099
|
|
|
$config->selectedServer['designer_settings'] = false; //'pma__designer_settings'; |
2100
|
|
|
$config->selectedServer['export_templates'] = false; //'pma__export_templates'; |
2101
|
|
|
|
2102
|
|
|
self::assertFalse($relation->arePmadbTablesDefined()); |
2103
|
|
|
self::assertTrue($relation->arePmadbTablesAllDisabled()); |
2104
|
|
|
} |
2105
|
|
|
|
2106
|
|
|
/** |
2107
|
|
|
* @param array<string, bool|string> $params |
2108
|
|
|
* @param string[] $queries |
2109
|
|
|
*/ |
2110
|
|
|
#[DataProvider('providerForTestRenameTable')] |
2111
|
|
|
public function testRenameTable(array $params, array $queries): void |
2112
|
|
|
{ |
2113
|
|
|
$dummyDbi = $this->createDbiDummy(); |
2114
|
|
|
$dbi = $this->createDatabaseInterface($dummyDbi); |
2115
|
|
|
|
2116
|
|
|
$relation = new Relation($dbi); |
2117
|
|
|
|
2118
|
|
|
$relationParameters = RelationParameters::fromArray($params); |
2119
|
|
|
(new ReflectionProperty(Relation::class, 'cache'))->setValue(null, $relationParameters); |
2120
|
|
|
|
2121
|
|
|
foreach ($queries as $query) { |
2122
|
|
|
$dummyDbi->addResult($query, true); |
2123
|
|
|
} |
2124
|
|
|
|
2125
|
|
|
$relation->renameTable('db_1', 'db_2', 'table_1', 'table_2'); |
2126
|
|
|
|
2127
|
|
|
$dummyDbi->assertAllQueriesConsumed(); |
2128
|
|
|
} |
2129
|
|
|
|
2130
|
|
|
/** |
2131
|
|
|
* @return array<int, array<int, array<int|string, bool|string>>> |
2132
|
|
|
* @psalm-return list<array{array<string, bool|string>, string[]}> |
2133
|
|
|
*/ |
2134
|
|
|
public static function providerForTestRenameTable(): array |
2135
|
|
|
{ |
2136
|
|
|
// phpcs:disable Generic.Files.LineLength.TooLong |
2137
|
|
|
return [ |
2138
|
|
|
[ |
2139
|
|
|
['user' => 'user', 'db' => 'pmadb', 'commwork' => true, 'column_info' => 'column_info'], |
2140
|
|
|
['UPDATE `pmadb`.`column_info` SET db_name = \'db_2\', table_name = \'table_2\' WHERE db_name = \'db_1\' AND table_name = \'table_1\''], |
2141
|
|
|
], |
2142
|
|
|
[ |
2143
|
|
|
['user' => 'user', 'db' => 'pmadb', 'displaywork' => true, 'relation' => 'relation', 'table_info' => 'table_info'], |
2144
|
|
|
['UPDATE `pmadb`.`table_info` SET db_name = \'db_2\', table_name = \'table_2\' WHERE db_name = \'db_1\' AND table_name = \'table_1\''], |
2145
|
|
|
], |
2146
|
|
|
[ |
2147
|
|
|
['user' => 'user', 'db' => 'pmadb', 'relwork' => true, 'relation' => 'relation'], |
2148
|
|
|
[ |
2149
|
|
|
'UPDATE `pmadb`.`relation` SET foreign_db = \'db_2\', foreign_table = \'table_2\' WHERE foreign_db = \'db_1\' AND foreign_table = \'table_1\'', |
2150
|
|
|
'UPDATE `pmadb`.`relation` SET master_db = \'db_2\', master_table = \'table_2\' WHERE master_db = \'db_1\' AND master_table = \'table_1\'', |
2151
|
|
|
], |
2152
|
|
|
], |
2153
|
|
|
[ |
2154
|
|
|
['user' => 'user', 'db' => 'pmadb', 'pdfwork' => true, 'pdf_pages' => 'pdf_pages', 'table_coords' => 'table_coords'], |
2155
|
|
|
['DELETE FROM `pmadb`.`table_coords` WHERE db_name = \'db_1\' AND table_name = \'table_1\''], |
2156
|
|
|
], |
2157
|
|
|
[ |
2158
|
|
|
['user' => 'user', 'db' => 'pmadb', 'uiprefswork' => true, 'table_uiprefs' => 'table_uiprefs'], |
2159
|
|
|
['UPDATE `pmadb`.`table_uiprefs` SET db_name = \'db_2\', table_name = \'table_2\' WHERE db_name = \'db_1\' AND table_name = \'table_1\''], |
2160
|
|
|
], |
2161
|
|
|
[ |
2162
|
|
|
['user' => 'user', 'db' => 'pmadb', 'navwork' => true, 'navigationhiding' => 'navigationhiding'], |
2163
|
|
|
[ |
2164
|
|
|
'UPDATE `pmadb`.`navigationhiding` SET db_name = \'db_2\', table_name = \'table_2\' WHERE db_name = \'db_1\' AND table_name = \'table_1\'', |
2165
|
|
|
'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\'', |
2166
|
|
|
], |
2167
|
|
|
], |
2168
|
|
|
]; |
2169
|
|
|
// phpcs:enable |
2170
|
|
|
} |
2171
|
|
|
|
2172
|
|
|
public function testRenameTableEscaping(): void |
2173
|
|
|
{ |
2174
|
|
|
$dummyDbi = $this->createDbiDummy(); |
2175
|
|
|
$dbi = $this->createDatabaseInterface($dummyDbi); |
2176
|
|
|
|
2177
|
|
|
$relation = new Relation($dbi); |
2178
|
|
|
|
2179
|
|
|
$relationParameters = RelationParameters::fromArray([ |
2180
|
|
|
'user' => 'user', |
2181
|
|
|
'db' => 'pma`db', |
2182
|
|
|
'pdfwork' => true, |
2183
|
|
|
'pdf_pages' => 'pdf_pages', |
2184
|
|
|
'table_coords' => 'table`coords', |
2185
|
|
|
]); |
2186
|
|
|
(new ReflectionProperty(Relation::class, 'cache'))->setValue(null, $relationParameters); |
2187
|
|
|
|
2188
|
|
|
$dummyDbi->addResult( |
2189
|
|
|
'UPDATE `pma``db`.`table``coords` SET db_name = \'db\\\'1\', table_name = \'table\\\'2\'' |
2190
|
|
|
. ' WHERE db_name = \'db\\\'1\' AND table_name = \'table\\\'1\'', |
2191
|
|
|
true, |
2192
|
|
|
); |
2193
|
|
|
|
2194
|
|
|
$relation->renameTable('db\'1', 'db\'1', 'table\'1', 'table\'2'); |
2195
|
|
|
|
2196
|
|
|
$dummyDbi->assertAllQueriesConsumed(); |
2197
|
|
|
} |
2198
|
|
|
} |
2199
|
|
|
|
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.