Skip to content

Commit

Permalink
Merge 3ad189b into 3a01452
Browse files Browse the repository at this point in the history
  • Loading branch information
csware committed Mar 5, 2021
2 parents 3a01452 + 3ad189b commit 2f4060e
Show file tree
Hide file tree
Showing 3 changed files with 191 additions and 4 deletions.
6 changes: 3 additions & 3 deletions libraries/classes/Menu.php
Expand Up @@ -201,20 +201,20 @@ private function getBreadcrumbs(): string
$server['url'] = Util::getUrlForOption(
$cfg['DefaultTabServer'],
'server'
);
) ?? '/';

if (strlen($this->db) > 0) {
$database['name'] = $this->db;
$database['url'] = Util::getUrlForOption(
$cfg['DefaultTabDatabase'],
'database'
);
) ?? '/';
if (strlen((string) $this->table) > 0) {
$table['name'] = $this->table;
$table['url'] = Util::getUrlForOption(
$cfg['DefaultTabTable'],
'table'
);
) ?? '/';
/** @var Table $tableObj */
$tableObj = $dbi->getTable($this->db, $this->table);
$table['is_view'] = $tableObj->isView();
Expand Down
16 changes: 15 additions & 1 deletion libraries/classes/Util.php
Expand Up @@ -1742,7 +1742,7 @@ public static function getScriptNameForOption($target, string $location): string
{
$url = self::getUrlForOption($target, $location);
if ($url === null) {
return '/';
return './';
}

return Url::getFromRoute($url);
Expand All @@ -1767,26 +1767,35 @@ public static function getUrlForOption($target, string $location): ?string
// Values for $cfg['DefaultTabServer']
switch ($target) {
case 'welcome':
case 'index.php':
return '/';
case 'databases':
case 'server_databases.php':
return '/server/databases';
case 'status':
case 'server_status.php':
return '/server/status';
case 'variables':
case 'server_variables.php':
return '/server/variables';
case 'privileges':
case 'server_privileges.php':
return '/server/privileges';
}
} elseif ($location === 'database') {
// Values for $cfg['DefaultTabDatabase']
switch ($target) {
case 'structure':
case 'db_structure.php':
return '/database/structure';
case 'sql':
case 'db_sql.php':
return '/database/sql';
case 'search':
case 'db_search.php':
return '/database/search';
case 'operations':
case 'db_operations.php':
return '/database/operations';
}
} elseif ($location === 'table') {
Expand All @@ -1795,14 +1804,19 @@ public static function getUrlForOption($target, string $location): ?string
// $cfg['NavigationTreeDefaultTabTable2']
switch ($target) {
case 'structure':
case 'tbl_structure.php':
return '/table/structure';
case 'sql':
case 'tbl_sql.php':
return '/table/sql';
case 'search':
case 'tbl_select.php':
return '/table/search';
case 'insert':
case 'tbl_change.php':
return '/table/change';
case 'browse':
case 'sql.php':
return '/sql';
}
}
Expand Down
173 changes: 173 additions & 0 deletions test/classes/UtilTest.php
Expand Up @@ -2600,4 +2600,177 @@ public function testCurrentUserHasNotUserPrivilegeAndNotDbPrivilegeAndNotTablePr
$this->assertFalse(Util::currentUserHasPrivilege('EVENT', 'my_data_base', 'my_data_table'));
$GLOBALS['dbi'] = $oldDbi;
}

/**
* @return array[]
*/
public function dataProviderScriptNames(): array
{
// target
// location
// function output
return [
[
'structure', // Notice the typo on db_structure.php
'databasesss',
'./',// Fallback to a relative path, impossible to build a valid route link
],
[
'db_structures.php', // Notice the typo on databases
'database',
'./',// Fallback to a relative path, impossible to build a valid route link
],
[
'tbl_structure.php', // Support the legacy value
'table',
'index.php?route=/table/structure&lang=en',
],
[
'structure',
'table',
'index.php?route=/table/structure&lang=en',
],
[
'tbl_sql.php', // Support the legacy value
'table',
'index.php?route=/table/sql&lang=en',
],
[
'sql',
'table',
'index.php?route=/table/sql&lang=en',
],
[
'tbl_select.php', // Support the legacy value
'table',
'index.php?route=/table/search&lang=en',
],
[
'search',
'table',
'index.php?route=/table/search&lang=en',
],
[
'tbl_change.php', // Support the legacy value
'table',
'index.php?route=/table/change&lang=en',
],
[
'insert',
'table',
'index.php?route=/table/change&lang=en',
],
[
'sql.php', // Support the legacy value
'table',
'index.php?route=/sql&lang=en',
],
[
'browse',
'table',
'index.php?route=/sql&lang=en',
],
[
'db_structure.php', // Support the legacy value
'database',
'index.php?route=/database/structure&lang=en',
],
[
'structure',
'database',
'index.php?route=/database/structure&lang=en',
],
[
'db_sql.php', // Support the legacy value
'database',
'index.php?route=/database/sql&lang=en',
],
[
'sql',
'database',
'index.php?route=/database/sql&lang=en',
],
[
'db_search.php', // Support the legacy value
'database',
'index.php?route=/database/search&lang=en',
],
[
'search',
'database',
'index.php?route=/database/search&lang=en',
],
[
'db_operations.php', // Support the legacy value
'database',
'index.php?route=/database/operations&lang=en',
],
[
'operations',
'database',
'index.php?route=/database/operations&lang=en',
],
[
'index.php', // Support the legacy value
'server',
'index.php?route=/&lang=en',
],
[
'welcome',
'server',
'index.php?route=/&lang=en',
],
[
'server_databases.php', // Support the legacy value
'server',
'index.php?route=/server/databases&lang=en',
],
[
'databases',
'server',
'index.php?route=/server/databases&lang=en',
],
[
'server_status.php', // Support the legacy value
'server',
'index.php?route=/server/status&lang=en',
],
[
'status',
'server',
'index.php?route=/server/status&lang=en',
],
[
'server_variables.php', // Support the legacy value
'server',
'index.php?route=/server/variables&lang=en',
],
[
'variables',
'server',
'index.php?route=/server/variables&lang=en',
],
[
'server_privileges.php', // Support the legacy value
'server',
'index.php?route=/server/privileges&lang=en',
],
[
'privileges',
'server',
'index.php?route=/server/privileges&lang=en',
],
];
}

/**
* @dataProvider dataProviderScriptNames
*/
public function testGetScriptNameForOption(string $target, string $location, string $finalLink): void
{
$this->assertSame(
$finalLink,
Util::getScriptNameForOption($target, $location)
);
}
}

0 comments on commit 2f4060e

Please sign in to comment.