|
6 | 6 |
|
7 | 7 | use PhpMyAdmin\DatabaseInterface; |
8 | 8 | use PhpMyAdmin\Html\Generator; |
| 9 | +use PhpMyAdmin\Message; |
9 | 10 | use PhpMyAdmin\Tests\AbstractTestCase; |
| 11 | +use PhpMyAdmin\Tests\Stubs\DbiDummy; |
10 | 12 | use PhpMyAdmin\Types; |
11 | 13 | use PhpMyAdmin\Util; |
| 14 | +use PhpMyAdmin\Utils\SessionCache; |
12 | 15 |
|
13 | 16 | use function __; |
14 | 17 | use function _pgettext; |
@@ -433,4 +436,70 @@ public static function providerForTestGetDefaultFunctionForField(): array |
433 | 436 | [['True_Type' => '', 'first_timestamp' => false, 'Key' => 'PRI', 'Type' => 'char(36)'], true, 'UUID'], |
434 | 437 | ]; |
435 | 438 | } |
| 439 | + |
| 440 | + public function testGetMessage(): void |
| 441 | + { |
| 442 | + $GLOBALS['cfg']['ShowSQL'] = true; |
| 443 | + $GLOBALS['display_query'] = null; |
| 444 | + $GLOBALS['unparsed_sql'] = null; |
| 445 | + $GLOBALS['sql_query'] = 'SELECT 1;'; |
| 446 | + $usingBookmarkMessage = Message::notice('Bookmark message'); |
| 447 | + $GLOBALS['using_bookmark_message'] = $usingBookmarkMessage; |
| 448 | + $GLOBALS['dbi'] = DatabaseInterface::load(new DbiDummy()); |
| 449 | + $GLOBALS['db'] = 'test_db'; |
| 450 | + $GLOBALS['table'] = 'test_table'; |
| 451 | + $GLOBALS['server'] = 2; |
| 452 | + $GLOBALS['special_message'] = 'Message [em]two[/em].'; |
| 453 | + SessionCache::set('profiling_supported', true); |
| 454 | + |
| 455 | + // phpcs:disable Generic.Files.LineLength.TooLong |
| 456 | + $expected = <<<'HTML' |
| 457 | +<div class="alert alert-primary" role="alert"> |
| 458 | + <img src="themes/dot.gif" title="" alt="" class="icon ic_s_notice"> Bookmark message |
| 459 | +</div> |
| 460 | +<div class="result_query"> |
| 461 | +<div class="alert alert-primary" role="alert">Message <em>one</em>.Message <em>two</em>.</div><div class="sqlOuter"><code class="sql"><pre> |
| 462 | +SELECT 1; |
| 463 | +</pre></code></div><div class="tools d-print-none"><form action="index.php?route=/sql&server=2&lang=en" method="post"><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"><input type="hidden" name="sql_query" value="SELECT 1;"><input type="hidden" name="profiling_form" value="1"><input type="checkbox" name="profiling" id="profilingCheckbox" class="autosubmit"> <label for="profilingCheckbox">Profiling</label></form> [ <a href="#" class="inline_edit_sql">Edit inline</a> ] [ <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">Edit</a> ] [ <a href="index.php" data-post="route=/import&db=test_db&table=test_table&sql_query=EXPLAIN+SELECT+1%3B&server=2&lang=en">Explain SQL</a> ] [ <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">Create PHP code</a> ] [ <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">Refresh</a> ]</div></div> |
| 464 | +HTML; |
| 465 | + // phpcs:enable |
| 466 | + |
| 467 | + $this->assertSame($expected, Generator::getMessage('Message [em]one[/em].')); |
| 468 | + $this->assertArrayNotHasKey('using_bookmark_message', $GLOBALS); |
| 469 | + $this->assertArrayNotHasKey('special_message', $GLOBALS); |
| 470 | + SessionCache::remove('profiling_supported'); |
| 471 | + } |
| 472 | + |
| 473 | + public function testGetMessage2(): void |
| 474 | + { |
| 475 | + $GLOBALS['cfg']['ShowSQL'] = true; |
| 476 | + $GLOBALS['cfg']['SQLQuery']['Edit'] = false; |
| 477 | + $GLOBALS['cfg']['SQLQuery']['Refresh'] = true; |
| 478 | + $GLOBALS['display_query'] = 'EXPLAIN SELECT 1;'; |
| 479 | + $GLOBALS['unparsed_sql'] = null; |
| 480 | + $GLOBALS['sql_query'] = null; |
| 481 | + $GLOBALS['dbi'] = DatabaseInterface::load(new DbiDummy()); |
| 482 | + $GLOBALS['db'] = 'test_db'; |
| 483 | + $GLOBALS['table'] = 'test_table'; |
| 484 | + $GLOBALS['server'] = 2; |
| 485 | + $GLOBALS['show_as_php'] = true; |
| 486 | + $GLOBALS['special_message'] = 'Message [em]two[/em].'; |
| 487 | + SessionCache::set('profiling_supported', true); |
| 488 | + |
| 489 | + // phpcs:disable Generic.Files.LineLength.TooLong |
| 490 | + $expected = <<<'HTML' |
| 491 | +<div class="result_query"> |
| 492 | +<div class="alert alert-success" role="alert"> |
| 493 | + <img src="themes/dot.gif" title="" alt="" class="icon ic_s_success"> Message <em>one</em>. Message <em>two</em>. |
| 494 | +</div> |
| 495 | +<div class="sqlOuter"><code class="php"><pre> |
| 496 | +$sql = "EXPLAIN SELECT 1;"; |
| 497 | +</pre></code></div><div class="tools d-print-none"><form action="index.php?route=/sql&server=2&lang=en" method="post"><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"><input type="hidden" name="sql_query" value="EXPLAIN SELECT 1;"></form> [ <a href="index.php" data-post="route=/import&db=test_db&table=test_table&sql_query=SELECT+1%3B&server=2&lang=en">Skip Explain SQL</a>] [ <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">Without PHP code</a> ] [ <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">Submit query</a> ]</div></div> |
| 498 | +HTML; |
| 499 | + // phpcs:enable |
| 500 | + |
| 501 | + $this->assertSame($expected, Generator::getMessage(Message::success('Message [em]one[/em].'))); |
| 502 | + $this->assertArrayNotHasKey('special_message', $GLOBALS); |
| 503 | + SessionCache::remove('profiling_supported'); |
| 504 | + } |
436 | 505 | } |
0 commit comments