Skip to content

Commit

Permalink
Merge branch 'QA_5_2'
Browse files Browse the repository at this point in the history
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
  • Loading branch information
MauricioFauth committed Feb 21, 2023
2 parents 07af957 + a174a41 commit d5b068b
Show file tree
Hide file tree
Showing 8 changed files with 236 additions and 13 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ phpMyAdmin - ChangeLog
- issue #17364 Fix error when trying to import a status monitor chart arrangement
- issue #18106 Fix renaming database with a view
- issue #18120 Fix bug with numerical tables during renaming database
- issue #16851 Fix ($cfg['Order']) default column order doesn't have have any effect since phpMyAdmin 4.2.0

5.2.1 (2023-02-07)
- issue #17522 Fix case where the routes cache file is invalid
Expand Down
15 changes: 10 additions & 5 deletions libraries/classes/Display/Results.php
Original file line number Diff line number Diff line change
Expand Up @@ -1430,11 +1430,16 @@ private function getSingleAndMultiSortUrls(
? 0
: count($sortExpressionNoDirection);
$sortExpressionNoDirection[$specialIndex] = Util::backquote($currentName);
$isTimeOrDate = $fieldsMeta->isType(FieldMetadata::TYPE_TIME)
|| $fieldsMeta->isType(FieldMetadata::TYPE_DATE)
|| $fieldsMeta->isType(FieldMetadata::TYPE_DATETIME)
|| $fieldsMeta->isType(FieldMetadata::TYPE_TIMESTAMP);
$sortDirection[$specialIndex] = $isTimeOrDate ? self::DESCENDING_SORT_DIR : self::ASCENDING_SORT_DIR;
// Set the direction to the config value
$sortDirection[$specialIndex] = $GLOBALS['cfg']['Order'];
// Or perform SMART mode
if ($GLOBALS['cfg']['Order'] === self::SMART_SORT_ORDER) {
$isTimeOrDate = $fieldsMeta->isType(FieldMetadata::TYPE_TIME)
|| $fieldsMeta->isType(FieldMetadata::TYPE_DATE)
|| $fieldsMeta->isType(FieldMetadata::TYPE_DATETIME)
|| $fieldsMeta->isType(FieldMetadata::TYPE_TIMESTAMP);
$sortDirection[$specialIndex] = $isTimeOrDate ? self::DESCENDING_SORT_DIR : self::ASCENDING_SORT_DIR;
}
}

$sortExpressionNoDirection = array_filter($sortExpressionNoDirection);
Expand Down
12 changes: 8 additions & 4 deletions libraries/classes/Header.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,12 @@ public function __construct()
$this->bodyId = '';
$this->title = '';
$this->console = new Console(new Relation($GLOBALS['dbi']), $this->template);
$this->menu = new Menu($GLOBALS['dbi'], $GLOBALS['db'] ?? '', $GLOBALS['table'] ?? '');
$this->menuEnabled = true;
$this->menuEnabled = false;
if ($GLOBALS['dbi'] !== null) {
$this->menuEnabled = true;
$this->menu = new Menu($GLOBALS['dbi'], $GLOBALS['db'] ?? '', $GLOBALS['table'] ?? '');
}

$this->warningsEnabled = true;
$this->scripts = new Scripts();
$this->addDefaultScripts();
Expand Down Expand Up @@ -150,8 +154,8 @@ public function getJsParams(): array
'LoginCookieValidity' => $GLOBALS['cfg']['LoginCookieValidity'],
'session_gc_maxlifetime' => (int) ini_get('session.gc_maxlifetime'),
'logged_in' => isset($GLOBALS['dbi']) ? $GLOBALS['dbi']->isConnected() : false,
'is_https' => $GLOBALS['config']->isHttps(),
'rootPath' => $GLOBALS['config']->getRootPath(),
'is_https' => $GLOBALS['config'] !== null && $GLOBALS['config']->isHttps(),
'rootPath' => $GLOBALS['config'] !== null && $GLOBALS['config']->getRootPath(),
'arg_separator' => Url::getArgSeparator(),
'version' => Version::VERSION,
];
Expand Down
4 changes: 2 additions & 2 deletions libraries/classes/ResponseRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,9 @@ private function getDisplay(): string
// and, in this case, the header will be
// in the content part of the request
return (new Template())->render('base', [
'header' => $this->header->getDisplay(),
'header' => $this->header?->getDisplay() ?? '',
'content' => $this->HTML,
'footer' => $this->footer->getDisplay(),
'footer' => $this->footer?->getDisplay() ?? '',
]);
}

Expand Down
2 changes: 1 addition & 1 deletion libraries/classes/Url.php
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ public static function buildHttpQuery($params, $encrypt = true)

$separator = self::getArgSeparator();

if (! $encrypt || ! $GLOBALS['config']->get('URLQueryEncryption')) {
if (! $encrypt || $GLOBALS['config'] === null || ! $GLOBALS['config']->get('URLQueryEncryption')) {
return http_build_query($params, '', $separator);
}

Expand Down
20 changes: 20 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -7625,6 +7625,11 @@ parameters:
count: 1
path: libraries/classes/ReplicationInfo.php

-
message: "#^Expression on left side of \\?\\? is not nullable\\.$#"
count: 2
path: libraries/classes/ResponseRenderer.php

-
message: "#^Foreach overwrites \\$value with its value variable\\.$#"
count: 1
Expand All @@ -7640,6 +7645,16 @@ parameters:
count: 1
path: libraries/classes/ResponseRenderer.php

-
message: "#^Using nullsafe method call on non\\-nullable type PhpMyAdmin\\\\Footer\\. Use \\-\\> instead\\.$#"
count: 1
path: libraries/classes/ResponseRenderer.php

-
message: "#^Using nullsafe method call on non\\-nullable type PhpMyAdmin\\\\Header\\. Use \\-\\> instead\\.$#"
count: 1
path: libraries/classes/ResponseRenderer.php

-
message: "#^Casting to array\\<string, mixed\\> something that's already array\\<string, mixed\\>\\.$#"
count: 4
Expand Down Expand Up @@ -10300,6 +10315,11 @@ parameters:
count: 1
path: test/classes/Display/ResultsTest.php

-
message: "#^Method PhpMyAdmin\\\\Tests\\\\Display\\\\ResultsTest\\:\\:dataProviderSortOrder\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: test/classes/Display/ResultsTest.php

-
message: "#^Method PhpMyAdmin\\\\Tests\\\\Display\\\\ResultsTest\\:\\:providerSetConfigParamsForDisplayTable\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
Expand Down
31 changes: 30 additions & 1 deletion psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6969,6 +6969,7 @@
<code>$sortExpressionNoDirection</code>
</InvalidArgument>
<InvalidArrayOffset>
<code><![CDATA[$GLOBALS['cfg']['Order']]]></code>
<code><![CDATA[$GLOBALS['cfg']['RowActionType']]]></code>
<code><![CDATA[$GLOBALS['is_header_sent']]]></code>
<code><![CDATA[$GLOBALS['row']]]></code>
Expand Down Expand Up @@ -7018,6 +7019,10 @@
<code>$row[$i]</code>
<code>$row[$i]</code>
<code>$sessionMaxRows</code>
<code>$sortDirection[$index]</code>
<code>$sortDirection[$index]</code>
<code>$sortDirection[$index]</code>
<code>$sortDirection[$index]</code>
<code>$sortExpressionNoDirection[$indexInExpression]</code>
<code>$sortExpressionNoDirection[$indexInExpression]</code>
<code>$sortExpressionNoDirection[$indexInExpression]</code>
Expand Down Expand Up @@ -7220,6 +7225,7 @@
<code>$relationalDisplay</code>
<code><![CDATA[$rowInfo[mb_strtolower($fieldsMeta[$m]->orgname)]]]></code>
<code>$sessionMaxRows</code>
<code>$sortDirection[$specialIndex]</code>
<code>$sqlQuery</code>
<code>$sqlQueryAdd</code>
<code>$tableCreateTime</code>
Expand Down Expand Up @@ -8723,6 +8729,17 @@
<PossiblyInvalidArgument>
<code>$message</code>
</PossiblyInvalidArgument>
<PossiblyNullArgument>
<code><![CDATA[$GLOBALS['dbi']]]></code>
</PossiblyNullArgument>
<PropertyNotSetInConstructor>
<code>$menu</code>
</PropertyNotSetInConstructor>
<RedundantCondition>
<code><![CDATA[$GLOBALS['config'] !== null]]></code>
<code><![CDATA[$GLOBALS['config'] !== null]]></code>
<code><![CDATA[$GLOBALS['dbi'] !== null]]></code>
</RedundantCondition>
<RedundantFunctionCall>
<code>strtolower</code>
</RedundantFunctionCall>
Expand Down Expand Up @@ -13719,11 +13736,17 @@
<code><![CDATA[(string) $GLOBALS['table']]]></code>
</RedundantCast>
<RedundantCondition>
<code><![CDATA[$this->footer?->getDisplay()]]></code>
<code><![CDATA[$this->header?->getDisplay()]]></code>
<code><![CDATA[is_scalar($GLOBALS['db'])]]></code>
<code><![CDATA[is_scalar($GLOBALS['table'])]]></code>
<code><![CDATA[isset($GLOBALS['db']) && is_scalar($GLOBALS['db'])]]></code>
<code><![CDATA[isset($GLOBALS['table']) && is_scalar($GLOBALS['table'])]]></code>
</RedundantCondition>
<TypeDoesNotContainNull>
<code><![CDATA[$this->footer]]></code>
<code><![CDATA[$this->header]]></code>
</TypeDoesNotContainNull>
<TypeDoesNotContainType>
<code><![CDATA['']]></code>
<code><![CDATA['']]></code>
Expand Down Expand Up @@ -15551,7 +15574,6 @@
}]]></code>
</MixedReturnStatement>
<PossiblyNullReference>
<code>get</code>
<code>get</code>
<code>getCookie</code>
</PossiblyNullReference>
Expand Down Expand Up @@ -16916,6 +16938,8 @@
<code><![CDATA[$_SESSION['tmpval']['relational_display']]]></code>
</MixedArrayAssignment>
<MixedAssignment>
<code>$data</code>
<code>$data</code>
<code>$output</code>
<code>$output</code>
<code>$output</code>
Expand All @@ -16928,6 +16952,11 @@
<code>array</code>
<code>array</code>
</MixedInferredReturnType>
<PossiblyInvalidArgument>
<code>testGetSingleAndMultiSortUrls</code>
<code>testGetSingleAndMultiSortUrls</code>
<code>testGetSingleAndMultiSortUrls</code>
</PossiblyInvalidArgument>
</file>
<file src="test/classes/Engines/PbxtTest.php">
<MixedInferredReturnType>
Expand Down
164 changes: 164 additions & 0 deletions test/classes/Display/ResultsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
use const MYSQLI_TYPE_DECIMAL;
use const MYSQLI_TYPE_LONG;
use const MYSQLI_TYPE_STRING;
use const MYSQLI_TYPE_TIME;
use const MYSQLI_TYPE_TIMESTAMP;

/**
Expand Down Expand Up @@ -1804,4 +1805,167 @@ public function testGetTable2(): void

$this->assertEquals($tableTemplate, $actual);
}

/**
* @return array[]
*/
public function dataProviderSortOrder(): array
{
return [
'Default date' => [
'SMART',
'DESC',// date types are DESC in SMART mode
MYSQLI_TYPE_DATE,
],
'ASC date' => [
'ASC',
'ASC',// do as config says
MYSQLI_TYPE_DATE,
],
'DESC date' => [
'DESC',
'DESC',// do as config says
MYSQLI_TYPE_DATE,
],
'Default date-time' => [
'SMART',
'DESC',// date time types are DESC in SMART mode
MYSQLI_TYPE_DATETIME,
],
'ASC date-time' => [
'ASC',
'ASC',// do as config says
MYSQLI_TYPE_DATETIME,
],
'DESC date-time' => [
'DESC',
'DESC',// do as config says
MYSQLI_TYPE_DATETIME,
],
'Default time' => [
'SMART',
'DESC',// time types are DESC in SMART mode
MYSQLI_TYPE_TIME,
],
'ASC time' => [
'ASC',
'ASC',// do as config says
MYSQLI_TYPE_TIME,
],
'DESC time' => [
'DESC',
'DESC',// do as config says
MYSQLI_TYPE_TIME,
],
'Default timestamp' => [
'SMART',
'DESC',// timestamp types are DESC in SMART mode
MYSQLI_TYPE_TIMESTAMP,
],
'ASC timestamp' => [
'ASC',
'ASC',// do as config says
MYSQLI_TYPE_TIMESTAMP,
],
'DESC timestamp' => [
'DESC',
'DESC',// do as config says
MYSQLI_TYPE_TIMESTAMP,
],
'Default string' => [
'SMART',
'ASC',// string types are ASC in SMART mode
MYSQLI_TYPE_STRING,
],
'ASC string' => [
'ASC',
'ASC',// do as config says
MYSQLI_TYPE_STRING,
],
'DESC string' => [
'DESC',
'DESC',// do as config says
MYSQLI_TYPE_STRING,
],
];
}

/**
* @dataProvider dataProviderSortOrder
*/
public function testGetSingleAndMultiSortUrls(
string $orderSetting,
string $querySortDirection,
int $metaType
): void {
$GLOBALS['cfg']['Order'] = $orderSetting;

$data = $this->callFunction(
$this->object,
DisplayResults::class,
'getSingleAndMultiSortUrls',
[
['`Country`.`Code` ASC'], // sortExpression,
['`Country`.`Code`'], // sortExpressionNoDirection,
'`Country`.',
'FoundedIn',
['ASC'], // sortDirection,
new FieldMetadata($metaType, 0, (object) []),
]
);

$this->assertSame([
"\n" . 'ORDER BY `Country`.`FoundedIn` ' . $querySortDirection, // singleSortOrder
"\n" . 'ORDER BY `Country`.`Code` ASC, `Country`.`FoundedIn` ' . $querySortDirection, // sortOrderColumns
'', // orderImg
], $data);

$data = $this->callFunction(
$this->object,
DisplayResults::class,
'getSingleAndMultiSortUrls',
[
['`Country`.`Code` ASC'], // sortExpression,
['`Country`.`Code`'], // sortExpressionNoDirection,
'`Country`.',
'Code2',
['ASC'], // sortDirection,
new FieldMetadata($metaType, 0, (object) []),
]
);

$this->assertSame([
"\n" . 'ORDER BY `Country`.`Code2` ' . $querySortDirection, // singleSortOrder
"\n" . 'ORDER BY `Country`.`Code` ASC, `Country`.`Code2` ' . $querySortDirection, // sortOrderColumns
'', // orderImg
], $data);

$data = $this->callFunction(
$this->object,
DisplayResults::class,
'getSingleAndMultiSortUrls',
[
[
'`Country`.`Continent` DESC","`Country`.`Region` ASC',
'`Country`.`Population` ASC',
], // sortExpression,
[
'`Country`.`Continent`',
'`Country`.`Region`',
'`Country`.`Population`',
], // sortExpressionNoDirection,
'`Country`.',
'Code2',
['DESC', 'ASC', 'ASC'], // sortDirection,
new FieldMetadata($metaType, 0, (object) []),
]
);

$this->assertSame([
"\n" . 'ORDER BY `Country`.`Code2` ' . $querySortDirection, // singleSortOrder
"\n" . 'ORDER BY `Country`.`Continent` DESC, `Country`.`Region` ASC'
. ', `Country`.`Population` ASC, `Country`.`Code2` ' . $querySortDirection, // sortOrderColumns
'', // orderImg
], $data);
}
}

0 comments on commit d5b068b

Please sign in to comment.