Skip to content

Commit 59131b5

Browse files
committed
Merge branch 'QA_5_2'
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
2 parents 1039557 + 50bca5c commit 59131b5

3 files changed

Lines changed: 85 additions & 15 deletions

File tree

ChangeLog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ phpMyAdmin - ChangeLog
4747
- issue Fix colspan for actions column on database table list
4848
- issue Fix double encoding on User Groups pages
4949
- issue Fix list of users of an user group not showing up
50+
- issue Fix duplicate query params in the SQL message card
5051

5152
5.2.1 (2023-02-07)
5253
- issue #17522 Fix case where the routes cache file is invalid

libraries/classes/Html/Generator.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -527,12 +527,12 @@ public static function getMessage(
527527
$urlParams['db'] = $GLOBALS['db'];
528528
if (strlen($GLOBALS['table']) > 0) {
529529
$urlParams['table'] = $GLOBALS['table'];
530-
$editLink = Url::getFromRoute('/table/sql');
530+
$editLinkRoute = '/table/sql';
531531
} else {
532-
$editLink = Url::getFromRoute('/database/sql');
532+
$editLinkRoute = '/database/sql';
533533
}
534534
} else {
535-
$editLink = Url::getFromRoute('/server/sql');
535+
$editLinkRoute = '/server/sql';
536536
}
537537

538538
// Want to have the query explained
@@ -546,16 +546,16 @@ public static function getMessage(
546546
$explainParams['sql_query'] = 'EXPLAIN ' . $sqlQuery;
547547
$explainLink = ' [&nbsp;'
548548
. self::linkOrButton(
549-
Url::getFromRoute('/import'),
550-
$explainParams,
549+
Url::getFromRoute('/import', $explainParams),
550+
null,
551551
__('Explain SQL'),
552552
) . '&nbsp;]';
553553
} elseif (preg_match('@^EXPLAIN[[:space:]]+SELECT[[:space:]]+@i', $sqlQuery)) {
554554
$explainParams['sql_query'] = mb_substr($sqlQuery, 8);
555555
$explainLink = ' [&nbsp;'
556556
. self::linkOrButton(
557-
Url::getFromRoute('/import'),
558-
$explainParams,
557+
Url::getFromRoute('/import', $explainParams),
558+
null,
559559
__('Skip Explain SQL'),
560560
) . ']';
561561
}
@@ -568,7 +568,7 @@ public static function getMessage(
568568
// to edit it (unless it's enormous, see linkOrButton() )
569569
if (! empty($GLOBALS['cfg']['SQLQuery']['Edit']) && empty($GLOBALS['show_as_php'])) {
570570
$editLink = ' [&nbsp;'
571-
. self::linkOrButton($editLink, $urlParams, __('Edit'))
571+
. self::linkOrButton(Url::getFromRoute($editLinkRoute, $urlParams), null, __('Edit'))
572572
. '&nbsp;]';
573573
} else {
574574
$editLink = '';
@@ -580,16 +580,16 @@ public static function getMessage(
580580
if (! empty($GLOBALS['show_as_php'])) {
581581
$phpLink = ' [&nbsp;'
582582
. self::linkOrButton(
583-
Url::getFromRoute('/import'),
584-
$urlParams,
583+
Url::getFromRoute('/import', $urlParams),
584+
null,
585585
__('Without PHP code'),
586586
)
587587
. '&nbsp;]';
588588

589589
$phpLink .= ' [&nbsp;'
590590
. self::linkOrButton(
591-
Url::getFromRoute('/import'),
592-
$urlParams,
591+
Url::getFromRoute('/import', $urlParams),
592+
null,
593593
__('Submit query'),
594594
)
595595
. '&nbsp;]';
@@ -598,8 +598,8 @@ public static function getMessage(
598598
$phpParams['show_as_php'] = 1;
599599
$phpLink = ' [&nbsp;'
600600
. self::linkOrButton(
601-
Url::getFromRoute('/import'),
602-
$phpParams,
601+
Url::getFromRoute('/import', $phpParams),
602+
null,
603603
__('Create PHP code'),
604604
)
605605
. '&nbsp;]';
@@ -616,7 +616,7 @@ public static function getMessage(
616616
) {
617617
$refreshLink = Url::getFromRoute('/sql', $urlParams);
618618
$refreshLink = ' [&nbsp;'
619-
. self::linkOrButton($refreshLink, $urlParams, __('Refresh')) . '&nbsp;]';
619+
. self::linkOrButton($refreshLink, null, __('Refresh')) . '&nbsp;]';
620620
} else {
621621
$refreshLink = '';
622622
}

test/classes/Html/GeneratorTest.php

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@
66

77
use PhpMyAdmin\DatabaseInterface;
88
use PhpMyAdmin\Html\Generator;
9+
use PhpMyAdmin\Message;
910
use PhpMyAdmin\Tests\AbstractTestCase;
11+
use PhpMyAdmin\Tests\Stubs\DbiDummy;
1012
use PhpMyAdmin\Types;
1113
use PhpMyAdmin\Util;
14+
use PhpMyAdmin\Utils\SessionCache;
1215

1316
use function __;
1417
use function _pgettext;
@@ -433,4 +436,70 @@ public static function providerForTestGetDefaultFunctionForField(): array
433436
[['True_Type' => '', 'first_timestamp' => false, 'Key' => 'PRI', 'Type' => 'char(36)'], true, 'UUID'],
434437
];
435438
}
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> [&nbsp;<a href="#" class="inline_edit_sql">Edit inline</a>&nbsp;] [&nbsp;<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>&nbsp;] [&nbsp;<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>&nbsp;] [&nbsp;<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>&nbsp;] [&nbsp;<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>&nbsp;]</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> [&nbsp;<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>] [&nbsp;<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>&nbsp;] [&nbsp;<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>&nbsp;]</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+
}
436505
}

0 commit comments

Comments
 (0)