|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace PhpMyAdmin\Tests\Html; |
|
6
|
|
|
|
|
7
|
|
|
use PhpMyAdmin\Config; |
|
8
|
|
|
use PhpMyAdmin\Current; |
|
9
|
|
|
use PhpMyAdmin\Dbal\DatabaseInterface; |
|
10
|
|
|
use PhpMyAdmin\Html\Generator; |
|
11
|
|
|
use PhpMyAdmin\Message; |
|
12
|
|
|
use PhpMyAdmin\Sql; |
|
13
|
|
|
use PhpMyAdmin\Tests\AbstractTestCase; |
|
14
|
|
|
use PhpMyAdmin\Types; |
|
15
|
|
|
use PhpMyAdmin\Url; |
|
16
|
|
|
use PhpMyAdmin\Utils\SessionCache; |
|
17
|
|
|
use PHPUnit\Framework\Attributes\CoversClass; |
|
|
|
|
|
|
18
|
|
|
use PHPUnit\Framework\Attributes\DataProvider; |
|
|
|
|
|
|
19
|
|
|
use PHPUnit\Framework\Attributes\Medium; |
|
|
|
|
|
|
20
|
|
|
|
|
21
|
|
|
use function __; |
|
22
|
|
|
use function _pgettext; |
|
23
|
|
|
use function htmlspecialchars; |
|
24
|
|
|
use function urlencode; |
|
25
|
|
|
|
|
26
|
|
|
#[CoversClass(Generator::class)] |
|
27
|
|
|
#[Medium] |
|
28
|
|
|
class GeneratorTest extends AbstractTestCase |
|
29
|
|
|
{ |
|
30
|
|
|
/** |
|
31
|
|
|
* Set up the test. |
|
32
|
|
|
*/ |
|
33
|
|
|
protected function setUp(): void |
|
34
|
|
|
{ |
|
35
|
|
|
parent::setUp(); |
|
36
|
|
|
|
|
37
|
|
|
$this->setLanguage(); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Test for getDbLink |
|
42
|
|
|
*/ |
|
43
|
|
|
public function testGetDbLinkNull(): void |
|
44
|
|
|
{ |
|
45
|
|
|
Current::$database = 'test_db'; |
|
46
|
|
|
Current::$server = 99; |
|
47
|
|
|
$database = Current::$database; |
|
48
|
|
|
self::assertSame( |
|
49
|
|
|
'<a href="' |
|
50
|
|
|
. Url::getFromRoute(Config::getInstance()->settings['DefaultTabDatabase']) |
|
|
|
|
|
|
51
|
|
|
. '&db=' . $database |
|
52
|
|
|
. '&server=99&lang=en" ' |
|
53
|
|
|
. 'title="Jump to database “' |
|
54
|
|
|
. htmlspecialchars($database) . '”.">' |
|
55
|
|
|
. htmlspecialchars($database) . '</a>', |
|
56
|
|
|
Generator::getDbLink(''), |
|
57
|
|
|
); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Test for getDbLink |
|
62
|
|
|
*/ |
|
63
|
|
|
public function testGetDbLink(): void |
|
64
|
|
|
{ |
|
65
|
|
|
Current::$server = 99; |
|
66
|
|
|
$database = 'test_database'; |
|
67
|
|
|
self::assertSame( |
|
68
|
|
|
'<a href="' . Url::getFromRoute(Config::getInstance()->settings['DefaultTabDatabase']) |
|
|
|
|
|
|
69
|
|
|
. '&db=' . $database |
|
70
|
|
|
. '&server=99&lang=en" title="Jump to database “' |
|
71
|
|
|
. htmlspecialchars($database) . '”.">' |
|
72
|
|
|
. htmlspecialchars($database) . '</a>', |
|
73
|
|
|
Generator::getDbLink($database), |
|
74
|
|
|
); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* Test for getDbLink |
|
79
|
|
|
*/ |
|
80
|
|
|
public function testGetDbLinkWithSpecialChars(): void |
|
81
|
|
|
{ |
|
82
|
|
|
Current::$server = 99; |
|
83
|
|
|
$database = 'test&data\'base'; |
|
84
|
|
|
self::assertSame( |
|
85
|
|
|
'<a href="' |
|
86
|
|
|
. Url::getFromRoute(Config::getInstance()->settings['DefaultTabDatabase']) |
|
|
|
|
|
|
87
|
|
|
. '&db=' |
|
88
|
|
|
. htmlspecialchars(urlencode($database)) |
|
89
|
|
|
. '&server=99&lang=en" title="Jump to database “' |
|
90
|
|
|
. htmlspecialchars($database) . '”.">' |
|
91
|
|
|
. htmlspecialchars($database) . '</a>', |
|
92
|
|
|
Generator::getDbLink($database), |
|
93
|
|
|
); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* Test for Util::getIcon |
|
98
|
|
|
*/ |
|
99
|
|
|
public function testGetIconWithoutActionLinksMode(): void |
|
100
|
|
|
{ |
|
101
|
|
|
Config::getInstance()->settings['ActionLinksMode'] = 'text'; |
|
|
|
|
|
|
102
|
|
|
|
|
103
|
|
|
self::assertSame( |
|
104
|
|
|
'<span class="text-nowrap"></span>', |
|
105
|
|
|
Generator::getIcon('b_comment'), |
|
106
|
|
|
); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* Test for Util::getIcon |
|
111
|
|
|
*/ |
|
112
|
|
|
public function testGetIconWithActionLinksMode(): void |
|
113
|
|
|
{ |
|
114
|
|
|
Config::getInstance()->settings['ActionLinksMode'] = 'icons'; |
|
|
|
|
|
|
115
|
|
|
|
|
116
|
|
|
self::assertSame( |
|
117
|
|
|
'<span class="text-nowrap"><img src="themes/dot.gif" title="" alt="" class="icon ic_b_comment"></span>', |
|
118
|
|
|
Generator::getIcon('b_comment'), |
|
119
|
|
|
); |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
/** |
|
123
|
|
|
* Test for Util::getIcon |
|
124
|
|
|
*/ |
|
125
|
|
|
public function testGetIconAlternate(): void |
|
126
|
|
|
{ |
|
127
|
|
|
Config::getInstance()->settings['ActionLinksMode'] = 'icons'; |
|
|
|
|
|
|
128
|
|
|
$alternateText = 'alt_str'; |
|
129
|
|
|
|
|
130
|
|
|
self::assertSame( |
|
131
|
|
|
'<span class="text-nowrap"><img src="themes/dot.gif" title="' |
|
132
|
|
|
. $alternateText . '" alt="' . $alternateText |
|
133
|
|
|
. '" class="icon ic_b_comment"></span>', |
|
134
|
|
|
Generator::getIcon('b_comment', $alternateText), |
|
135
|
|
|
); |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
/** |
|
139
|
|
|
* Test for Util::getIcon |
|
140
|
|
|
*/ |
|
141
|
|
|
public function testGetIconWithForceText(): void |
|
142
|
|
|
{ |
|
143
|
|
|
Config::getInstance()->settings['ActionLinksMode'] = 'icons'; |
|
|
|
|
|
|
144
|
|
|
$alternateText = 'alt_str'; |
|
145
|
|
|
|
|
146
|
|
|
// Here we are checking for an icon embedded inside a span (i.e not a menu |
|
147
|
|
|
// bar icon |
|
148
|
|
|
self::assertSame( |
|
149
|
|
|
'<span class="text-nowrap"><img src="themes/dot.gif" title="' |
|
150
|
|
|
. $alternateText . '" alt="' . $alternateText |
|
151
|
|
|
. '" class="icon ic_b_comment"> ' . $alternateText . '</span>', |
|
152
|
|
|
Generator::getIcon('b_comment', $alternateText, true, false), |
|
153
|
|
|
); |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
/** |
|
157
|
|
|
* Test for showPHPDocumentation |
|
158
|
|
|
*/ |
|
159
|
|
|
public function testShowPHPDocumentation(): void |
|
160
|
|
|
{ |
|
161
|
|
|
Config::getInstance()->settings['ServerDefault'] = 0; |
|
|
|
|
|
|
162
|
|
|
|
|
163
|
|
|
$target = 'docu'; |
|
164
|
|
|
$lang = _pgettext('PHP documentation language', 'en'); |
|
165
|
|
|
$expected = '<a href="index.php?route=/url&url=https%3A%2F%2Fwww.php.net%2Fmanual%2F' . $lang |
|
166
|
|
|
. '%2F' . $target . '" target="documentation">' |
|
167
|
|
|
. '<img src="themes/dot.gif" title="' . __('Documentation') . '" alt="' |
|
168
|
|
|
. __('Documentation') . '" class="icon ic_b_help"></a>'; |
|
169
|
|
|
|
|
170
|
|
|
self::assertSame( |
|
171
|
|
|
$expected, |
|
172
|
|
|
Generator::showPHPDocumentation($target), |
|
173
|
|
|
); |
|
174
|
|
|
} |
|
175
|
|
|
|
|
176
|
|
|
/** |
|
177
|
|
|
* Test for Generator::linkOrButton |
|
178
|
|
|
* |
|
179
|
|
|
* @param mixed[] $params params |
|
180
|
|
|
* @param int $limit limit |
|
181
|
|
|
* @param string $match match |
|
182
|
|
|
*/ |
|
183
|
|
|
#[DataProvider('linksOrButtons')] |
|
184
|
|
|
public function testLinkOrButton(array $params, int $limit, string $match): void |
|
185
|
|
|
{ |
|
186
|
|
|
$config = Config::getInstance(); |
|
|
|
|
|
|
187
|
|
|
$restore = $config->settings['LinkLengthLimit'] ?? 1000; |
|
188
|
|
|
$config->settings['LinkLengthLimit'] = $limit; |
|
189
|
|
|
try { |
|
190
|
|
|
$result = Generator::linkOrButton(...$params); |
|
191
|
|
|
self::assertSame($match, $result); |
|
192
|
|
|
} finally { |
|
193
|
|
|
$config->settings['LinkLengthLimit'] = $restore; |
|
194
|
|
|
} |
|
195
|
|
|
} |
|
196
|
|
|
|
|
197
|
|
|
/** |
|
198
|
|
|
* Data provider for Generator::linkOrButton test |
|
199
|
|
|
* |
|
200
|
|
|
* @return array<int, array{array<string, string>[]|string[]|null[]|bool[], int, string}> |
|
|
|
|
|
|
201
|
|
|
*/ |
|
202
|
|
|
public static function linksOrButtons(): array |
|
203
|
|
|
{ |
|
204
|
|
|
return [ |
|
205
|
|
|
[['index.php', null, 'text'], 1000, '<a href="index.php" >text</a>'], |
|
206
|
|
|
[ |
|
207
|
|
|
['index.php', ['some' => 'parameter'], 'text'], |
|
208
|
|
|
20, |
|
209
|
|
|
'<a href="index.php" data-post="some=parameter&lang=en">text</a>', |
|
210
|
|
|
], |
|
211
|
|
|
[['index.php', null, 'text', [], 'target'], 1000, '<a href="index.php" target="target">text</a>'], |
|
212
|
|
|
[ |
|
213
|
|
|
[ |
|
214
|
|
|
'https://mariadb.org/explain_analyzer/analyze/?client=phpMyAdmin&raw_explain=%2B---%2B', |
|
215
|
|
|
null, |
|
216
|
|
|
'text', |
|
217
|
|
|
[], |
|
218
|
|
|
'target', |
|
219
|
|
|
], |
|
220
|
|
|
10, |
|
221
|
|
|
// This is not the behavior we want for the analyser feature, next test will disable the limit |
|
222
|
|
|
'<a href="https://mariadb.org/explain_analyzer/analyze/"' |
|
223
|
|
|
. ' data-post="client=phpMyAdmin&raw_explain=%2B---%2B" target="target">text</a>', |
|
224
|
|
|
], |
|
225
|
|
|
[ |
|
226
|
|
|
[ |
|
227
|
|
|
'https://mariadb.org/explain_analyzer/analyze/?client=phpMyAdmin&raw_explain=%2B---%2B', |
|
228
|
|
|
null, |
|
229
|
|
|
'text', |
|
230
|
|
|
[], |
|
231
|
|
|
'target', |
|
232
|
|
|
false, |
|
233
|
|
|
], |
|
234
|
|
|
10, |
|
235
|
|
|
'<a href="https://mariadb.org/explain_analyzer/analyze/?client=phpMyAdmin&raw_explain=%2B---%2B"' |
|
236
|
|
|
. ' target="target">text</a>', |
|
237
|
|
|
], |
|
238
|
|
|
[ |
|
239
|
|
|
['index.php?route=/url&url=http://phpmyadmin.net/', null, 'text', [], '_blank'], |
|
240
|
|
|
1000, |
|
241
|
|
|
'<a href="index.php?route=/url&url=http://phpmyadmin.net/" target="_blank"' |
|
242
|
|
|
. ' rel="noopener noreferrer">text</a>', |
|
243
|
|
|
], |
|
244
|
|
|
[ |
|
245
|
|
|
['index.php?route=/server/databases', ['some' => 'parameter'], 'text'], |
|
246
|
|
|
20, |
|
247
|
|
|
'<a href="index.php" data-post="route=/server/databases&some=parameter&lang=en">text</a>', |
|
248
|
|
|
], |
|
249
|
|
|
[ |
|
250
|
|
|
['index.php?route=/server/databases', null, 'text'], |
|
251
|
|
|
20, |
|
252
|
|
|
'<a href="index.php" data-post="route=/server/databases">text</a>', |
|
253
|
|
|
], |
|
254
|
|
|
[ |
|
255
|
|
|
['index.php?route=/server/databases', ['some' => 'parameter'], 'text'], |
|
256
|
|
|
100, |
|
257
|
|
|
'<a href="index.php?route=/server/databases&some=parameter&lang=en" >text</a>', |
|
258
|
|
|
], |
|
259
|
|
|
[ |
|
260
|
|
|
['index.php?route=/server/databases', null, 'text'], |
|
261
|
|
|
100, |
|
262
|
|
|
'<a href="index.php?route=/server/databases" >text</a>', |
|
263
|
|
|
], |
|
264
|
|
|
[ |
|
265
|
|
|
[ |
|
266
|
|
|
'index.php', |
|
267
|
|
|
null, |
|
268
|
|
|
'text', |
|
269
|
|
|
['title' => '"'], |
|
270
|
|
|
], |
|
271
|
|
|
100, |
|
272
|
|
|
'<a href="index.php" title=""">text</a>', |
|
273
|
|
|
], |
|
274
|
|
|
]; |
|
275
|
|
|
} |
|
276
|
|
|
|
|
277
|
|
|
public function testFormatSql(): void |
|
278
|
|
|
{ |
|
279
|
|
|
self::assertSame( |
|
280
|
|
|
'<pre><code class="sql" dir="ltr">' |
|
281
|
|
|
. 'SELECT 1 < 2' |
|
282
|
|
|
. '</code></pre>', |
|
283
|
|
|
Generator::formatSql('SELECT 1 < 2'), |
|
284
|
|
|
); |
|
285
|
|
|
|
|
286
|
|
|
Config::getInstance()->settings['MaxCharactersInDisplayedSQL'] = 6; |
|
|
|
|
|
|
287
|
|
|
|
|
288
|
|
|
self::assertSame( |
|
289
|
|
|
'<pre><code class="sql" dir="ltr">' |
|
290
|
|
|
. 'SELECT[...]' |
|
291
|
|
|
. '</code></pre>', |
|
292
|
|
|
Generator::formatSql('SELECT 1 < 2', true), |
|
293
|
|
|
); |
|
294
|
|
|
} |
|
295
|
|
|
|
|
296
|
|
|
/** |
|
297
|
|
|
* Test for getServerSSL |
|
298
|
|
|
*/ |
|
299
|
|
|
public function testGetServerSSL(): void |
|
300
|
|
|
{ |
|
301
|
|
|
$sslNotUsed = '<span class="">SSL is not being used</span>' |
|
302
|
|
|
. ' <a href="index.php?route=/url&url=https%3A%2F%2Fdocs.phpmyadmin.net%2Fen%2Flatest%2Fsetup.html%23ssl"' |
|
303
|
|
|
. ' target="documentation"><img src="themes/dot.gif" title="Documentation" alt="Documentation"' |
|
304
|
|
|
. ' class="icon ic_b_help"></a>'; |
|
305
|
|
|
|
|
306
|
|
|
$sslNotUsedCaution = '<span class="text-danger">SSL is not being used</span>' |
|
307
|
|
|
. ' <a href="index.php?route=/url&url=https%3A%2F%2Fdocs.phpmyadmin.net%2Fen%2Flatest%2Fsetup.html%23ssl"' |
|
308
|
|
|
. ' target="documentation"><img src="themes/dot.gif" title="Documentation" alt="Documentation"' |
|
309
|
|
|
. ' class="icon ic_b_help"></a>'; |
|
310
|
|
|
|
|
311
|
|
|
$config = Config::getInstance(); |
|
|
|
|
|
|
312
|
|
|
$config->selectedServer = ['ssl' => false, 'host' => '127.0.0.1']; |
|
313
|
|
|
self::assertSame( |
|
314
|
|
|
$sslNotUsed, |
|
315
|
|
|
Generator::getServerSSL(), |
|
316
|
|
|
); |
|
317
|
|
|
|
|
318
|
|
|
$config->selectedServer = ['ssl' => false, 'host' => 'custom.host']; |
|
319
|
|
|
$config->settings['MysqlSslWarningSafeHosts'] = ['localhost', '127.0.0.1']; |
|
320
|
|
|
|
|
321
|
|
|
self::assertSame( |
|
322
|
|
|
$sslNotUsedCaution, |
|
323
|
|
|
Generator::getServerSSL(), |
|
324
|
|
|
); |
|
325
|
|
|
|
|
326
|
|
|
$config->selectedServer = ['ssl' => false, 'host' => 'custom.host']; |
|
327
|
|
|
$config->settings['MysqlSslWarningSafeHosts'] = ['localhost', '127.0.0.1', 'custom.host']; |
|
328
|
|
|
|
|
329
|
|
|
self::assertSame( |
|
330
|
|
|
$sslNotUsed, |
|
331
|
|
|
Generator::getServerSSL(), |
|
332
|
|
|
); |
|
333
|
|
|
|
|
334
|
|
|
$config->selectedServer = ['ssl' => false, 'ssl_verify' => true, 'host' => 'custom.host']; |
|
335
|
|
|
|
|
336
|
|
|
self::assertSame( |
|
337
|
|
|
$sslNotUsed, |
|
338
|
|
|
Generator::getServerSSL(), |
|
339
|
|
|
); |
|
340
|
|
|
|
|
341
|
|
|
$config->selectedServer = ['ssl' => true, 'ssl_verify' => false, 'host' => 'custom.host']; |
|
342
|
|
|
|
|
343
|
|
|
self::assertSame( |
|
344
|
|
|
'<span class="text-danger">SSL is used with disabled verification</span>' |
|
345
|
|
|
. ' <a href="index.php?route=/url&url=https%3A%2F%2Fdocs.phpmyadmin.net%2Fen%2Flatest%2Fsetup.html%23ssl"' |
|
346
|
|
|
. ' target="documentation"><img src="themes/dot.gif" title="Documentation" alt="Documentation"' |
|
347
|
|
|
. ' class="icon ic_b_help"></a>', |
|
348
|
|
|
Generator::getServerSSL(), |
|
349
|
|
|
); |
|
350
|
|
|
|
|
351
|
|
|
$config->selectedServer = ['ssl' => true, 'ssl_verify' => true, 'host' => 'custom.host']; |
|
352
|
|
|
|
|
353
|
|
|
self::assertSame( |
|
354
|
|
|
'<span class="text-danger">SSL is used without certification authority</span>' |
|
355
|
|
|
. ' <a href="index.php?route=/url&url=https%3A%2F%2Fdocs.phpmyadmin.net%2Fen%2Flatest%2Fsetup.html%23ssl"' |
|
356
|
|
|
. ' target="documentation"><img src="themes/dot.gif" title="Documentation" alt="Documentation"' |
|
357
|
|
|
. ' class="icon ic_b_help"></a>', |
|
358
|
|
|
Generator::getServerSSL(), |
|
359
|
|
|
); |
|
360
|
|
|
|
|
361
|
|
|
$config->selectedServer = [ |
|
362
|
|
|
'ssl' => true, |
|
363
|
|
|
'ssl_verify' => true, |
|
364
|
|
|
'ssl_ca' => '/etc/ssl/ca.crt', |
|
365
|
|
|
'host' => 'custom.host', |
|
366
|
|
|
]; |
|
367
|
|
|
|
|
368
|
|
|
self::assertSame( |
|
369
|
|
|
'<span class="">SSL is used</span>' |
|
370
|
|
|
. ' <a href="index.php?route=/url&url=https%3A%2F%2Fdocs.phpmyadmin.net%2Fen%2Flatest%2Fsetup.html%23ssl"' |
|
371
|
|
|
. ' target="documentation"><img src="themes/dot.gif" title="Documentation" alt="Documentation"' |
|
372
|
|
|
. ' class="icon ic_b_help"></a>', |
|
373
|
|
|
Generator::getServerSSL(), |
|
374
|
|
|
); |
|
375
|
|
|
} |
|
376
|
|
|
|
|
377
|
|
|
/** |
|
378
|
|
|
* Test for Generator::getDefaultFunctionForField |
|
379
|
|
|
*/ |
|
380
|
|
|
#[DataProvider('providerForTestGetDefaultFunctionForField')] |
|
381
|
|
|
public function testGetDefaultFunctionForField( |
|
382
|
|
|
string $trueType, |
|
383
|
|
|
bool $firstTimestamp, |
|
384
|
|
|
string|null $defaultValue, |
|
385
|
|
|
string $extra, |
|
386
|
|
|
bool $isNull, |
|
387
|
|
|
string $key, |
|
388
|
|
|
string $type, |
|
389
|
|
|
bool $insertMode, |
|
390
|
|
|
string $expected, |
|
391
|
|
|
): void { |
|
392
|
|
|
$dbiStub = self::createStub(DatabaseInterface::class); |
|
393
|
|
|
$dbiStub->types = new Types($dbiStub); |
|
|
|
|
|
|
394
|
|
|
$dbiStub->method('getVersion')->willReturn(50700); |
|
395
|
|
|
|
|
396
|
|
|
DatabaseInterface::$instance = $dbiStub; |
|
397
|
|
|
|
|
398
|
|
|
$result = Generator::getDefaultFunctionForField( |
|
399
|
|
|
$trueType, |
|
400
|
|
|
$firstTimestamp, |
|
401
|
|
|
$defaultValue, |
|
402
|
|
|
$extra, |
|
403
|
|
|
$isNull, |
|
404
|
|
|
$key, |
|
405
|
|
|
$type, |
|
406
|
|
|
$insertMode, |
|
407
|
|
|
); |
|
408
|
|
|
|
|
409
|
|
|
self::assertSame($expected, $result); |
|
410
|
|
|
} |
|
411
|
|
|
|
|
412
|
|
|
/** |
|
413
|
|
|
* Data provider for Generator::getDefaultFunctionForField test |
|
414
|
|
|
* |
|
415
|
|
|
* @return array{string, bool, string|null, string, bool, string, string, bool, string}[] |
|
|
|
|
|
|
416
|
|
|
*/ |
|
417
|
|
|
public static function providerForTestGetDefaultFunctionForField(): array |
|
418
|
|
|
{ |
|
419
|
|
|
return [ |
|
420
|
|
|
[ |
|
421
|
|
|
'GEOMETRY', |
|
422
|
|
|
false, |
|
423
|
|
|
null, |
|
424
|
|
|
'', |
|
425
|
|
|
false, |
|
426
|
|
|
'', |
|
427
|
|
|
'', |
|
428
|
|
|
true, |
|
429
|
|
|
'ST_GeomFromText', |
|
430
|
|
|
], |
|
431
|
|
|
[ |
|
432
|
|
|
'timestamp', |
|
433
|
|
|
true, |
|
434
|
|
|
null, |
|
435
|
|
|
'', |
|
436
|
|
|
false, |
|
437
|
|
|
'', |
|
438
|
|
|
'', |
|
439
|
|
|
true, |
|
440
|
|
|
'NOW', |
|
441
|
|
|
], |
|
442
|
|
|
[ |
|
443
|
|
|
'uuid', |
|
444
|
|
|
false, |
|
445
|
|
|
null, |
|
446
|
|
|
'', |
|
447
|
|
|
false, |
|
448
|
|
|
'', |
|
449
|
|
|
'', |
|
450
|
|
|
true, |
|
451
|
|
|
'', |
|
452
|
|
|
], |
|
453
|
|
|
[ |
|
454
|
|
|
'', |
|
455
|
|
|
false, |
|
456
|
|
|
null, |
|
457
|
|
|
'', |
|
458
|
|
|
false, |
|
459
|
|
|
'PRI', |
|
460
|
|
|
'char(36)', |
|
461
|
|
|
true, |
|
462
|
|
|
'UUID', |
|
463
|
|
|
], |
|
464
|
|
|
]; |
|
465
|
|
|
} |
|
466
|
|
|
|
|
467
|
|
|
public function testGetMessage(): void |
|
468
|
|
|
{ |
|
469
|
|
|
Config::getInstance()->settings['ShowSQL'] = true; |
|
|
|
|
|
|
470
|
|
|
Current::$displayQuery = null; |
|
471
|
|
|
Current::$sqlQuery = 'SELECT 1;'; |
|
472
|
|
|
Sql::$usingBookmarkMessage = Message::notice('Bookmark message'); |
|
473
|
|
|
DatabaseInterface::$instance = $this->createDatabaseInterface(); |
|
474
|
|
|
Current::$database = 'test_db'; |
|
475
|
|
|
Current::$table = 'test_table'; |
|
476
|
|
|
Current::$server = 2; |
|
477
|
|
|
Sql::$showAsPhp = null; |
|
478
|
|
|
SessionCache::set('profiling_supported', true); |
|
479
|
|
|
|
|
480
|
|
|
// phpcs:disable Generic.Files.LineLength.TooLong |
|
481
|
|
|
$expected = <<<'HTML' |
|
482
|
|
|
<div class="alert alert-primary" role="alert"> |
|
483
|
|
|
<img src="themes/dot.gif" title="" alt="" class="icon ic_s_notice"> Bookmark message |
|
484
|
|
|
</div> |
|
485
|
|
|
<div class="card mb-3 result_query"> |
|
486
|
|
|
<div class="alert alert-primary border-top-0 border-start-0 border-end-0 rounded-bottom-0 mb-0" role="alert"> |
|
487
|
|
|
<img src="themes/dot.gif" title="" alt="" class="icon ic_s_notice"> Message <em>one</em>. |
|
488
|
|
|
</div> |
|
489
|
|
|
<div class="card-body sqlOuter"><pre><code class="sql" dir="ltr">SELECT 1;</code></pre></div> |
|
490
|
|
|
<div class="card-footer tools d-print-none"> |
|
491
|
|
|
<div class="row align-items-center"> |
|
492
|
|
|
<div class="col-auto"> |
|
493
|
|
|
<form action="index.php?route=/sql&db=test_db&table=test_table&server=2&lang=en" method="post" class="disableAjax"> |
|
494
|
|
|
<input type="hidden" name="db" value="test_db"><input type="hidden" name="table" value="test_table"><input type="hidden" name="server" value="2"><input type="hidden" name="lang" value="en"><input type="hidden" name="token" value="token"> |
|
495
|
|
|
<input type="hidden" name="sql_query" value="SELECT 1;"> |
|
496
|
|
|
<input type="hidden" name="profiling_form" value="1"> |
|
497
|
|
|
<div class="form-check form-switch"> |
|
498
|
|
|
<input type="checkbox" name="profiling" id="profilingCheckbox" role="switch" class="form-check-input autosubmit"> |
|
499
|
|
|
<label class="form-check-label" for="profilingCheckbox">Profiling</label> |
|
500
|
|
|
</div> |
|
501
|
|
|
</form></div> |
|
502
|
|
|
<div class="col-auto"><a href="#" class="btn btn-link inline_edit_sql">Edit inline</a></div> |
|
503
|
|
|
<div class="col-auto"><a href="index.php" data-post="route=/table/sql&db=test_db&table=test_table&sql_query=SELECT+1%3B&show_query=1&server=2&lang=en" class="btn btn-link">Edit</a></div> |
|
504
|
|
|
<div class="col-auto"><a href="index.php" data-post="route=/import&db=test_db&table=test_table&sql_query=EXPLAIN+SELECT+1%3B&server=2&lang=en" class="btn btn-link">Explain SQL</a></div> |
|
505
|
|
|
<div class="col-auto"><a href="index.php" data-post="route=/import&db=test_db&table=test_table&sql_query=SELECT+1%3B&show_query=1&show_as_php=1&server=2&lang=en" class="btn btn-link">Create PHP code</a></div> |
|
506
|
|
|
<div class="col-auto"><a href="index.php" data-post="route=/sql&db=test_db&table=test_table&sql_query=SELECT+1%3B&show_query=1&server=2&lang=en" class="btn btn-link">Refresh</a></div> |
|
507
|
|
|
</div></div></div> |
|
508
|
|
|
HTML; |
|
509
|
|
|
// phpcs:enable |
|
510
|
|
|
|
|
511
|
|
|
self::assertSame($expected, Generator::getMessage('Message [em]one[/em].')); |
|
512
|
|
|
SessionCache::remove('profiling_supported'); |
|
513
|
|
|
} |
|
514
|
|
|
|
|
515
|
|
|
public function testGetMessage2(): void |
|
516
|
|
|
{ |
|
517
|
|
|
$config = Config::getInstance(); |
|
|
|
|
|
|
518
|
|
|
$config->settings['ShowSQL'] = true; |
|
519
|
|
|
$config->settings['SQLQuery']['Edit'] = false; |
|
520
|
|
|
$config->settings['SQLQuery']['Refresh'] = true; |
|
521
|
|
|
Current::$displayQuery = 'EXPLAIN SELECT 1;'; |
|
522
|
|
|
Current::$sqlQuery = ''; |
|
523
|
|
|
DatabaseInterface::$instance = $this->createDatabaseInterface(); |
|
524
|
|
|
Current::$database = 'test_db'; |
|
525
|
|
|
Current::$table = 'test_table'; |
|
526
|
|
|
Current::$server = 2; |
|
527
|
|
|
Sql::$showAsPhp = true; |
|
528
|
|
|
SessionCache::set('profiling_supported', true); |
|
529
|
|
|
|
|
530
|
|
|
// phpcs:disable Generic.Files.LineLength.TooLong |
|
531
|
|
|
$expected = <<<'HTML' |
|
532
|
|
|
<div class="card mb-3 result_query"> |
|
533
|
|
|
<div class="alert alert-success border-top-0 border-start-0 border-end-0 rounded-bottom-0 mb-0" role="alert"> |
|
534
|
|
|
<img src="themes/dot.gif" title="" alt="" class="icon ic_s_success"> Message <em>one</em>. |
|
535
|
|
|
</div> |
|
536
|
|
|
<div class="card-body sqlOuter"><pre><code class="php" dir="ltr">$sql = "EXPLAIN SELECT 1;";</code></pre></div> |
|
537
|
|
|
<div class="card-footer tools d-print-none"> |
|
538
|
|
|
<div class="row align-items-center"> |
|
539
|
|
|
<div class="col-auto"> |
|
540
|
|
|
<form action="index.php?route=/sql&db=test_db&table=test_table&server=2&lang=en" method="post" class="disableAjax"> |
|
541
|
|
|
<input type="hidden" name="db" value="test_db"><input type="hidden" name="table" value="test_table"><input type="hidden" name="server" value="2"><input type="hidden" name="lang" value="en"><input type="hidden" name="token" value="token"> |
|
542
|
|
|
<input type="hidden" name="sql_query" value="EXPLAIN SELECT 1;"> |
|
543
|
|
|
</form></div> |
|
544
|
|
|
<div class="col-auto"><a href="index.php" data-post="route=/import&db=test_db&table=test_table&sql_query=SELECT+1%3B&server=2&lang=en" class="btn btn-link">Skip Explain SQL</a></div> |
|
545
|
|
|
<div class="col-auto"><a href="index.php" data-post="route=/import&db=test_db&table=test_table&sql_query=EXPLAIN+SELECT+1%3B&show_query=1&server=2&lang=en" class="btn btn-link">Without PHP code</a></div> |
|
546
|
|
|
<div class="col-auto"><a href="index.php" data-post="route=/import&db=test_db&table=test_table&sql_query=EXPLAIN+SELECT+1%3B&show_query=1&server=2&lang=en" class="btn btn-link">Submit query</a></div> |
|
547
|
|
|
</div></div></div> |
|
548
|
|
|
HTML; |
|
549
|
|
|
// phpcs:enable |
|
550
|
|
|
|
|
551
|
|
|
self::assertSame($expected, Generator::getMessage(Message::success('Message [em]one[/em].'))); |
|
552
|
|
|
SessionCache::remove('profiling_supported'); |
|
553
|
|
|
} |
|
554
|
|
|
} |
|
555
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths