You've already forked phpmyadmin
mirror of
https://github.com/phpmyadmin/phpmyadmin.git
synced 2026-10-23 18:29:15 +03:00
QA_5_2 still lives in libraries/classes/ and test/classes/; master moved to src/ and tests/unit/. Seven files therefore arrived as "deleted by us" and had to be ported by hand rather than merged. Upstream commit roll-call (060391b9a7..3d2594b2d3, 15 non-merge commits). The 5 merge commits in that range were checked with `git show --cc` and are all empty, so they contribute no content of their own:366d165982ported Strip port from host in processes privileges link544839869dported Test coverage for the port-stripping80638e8371ported Add LIMIT 0 when fetching metadata (4 of 7 hunks; see below for the 3 that do not apply)3b46e5b869ported Fix Uncaught ReferenceError: CodeMirror is not defined8525d24e09already in Fix search of INET4 with = operator1730b7c0bfno-op Remove useless parentheses6c1568b15bskipped Move getColumnMapFromSql into the methodafaeacecc9,cae0175274,64c6890d6c,669f8d17bc,eee3cd458a,9c8246a127,5f1ae11fc4,111993769enot taken Translated using Weblate (lv, vi) Conflict resolutions, file by file: * src/Server/Status/Processes.php Ported366d165982(#20315 / #19841): expose a 'user_host' row key holding the host with any `:port` suffix stripped. Adapted to master's lower-cased array keys from array_change_key_case(). * resources/templates/server/status/processes/list.twig The privileges link now uses row.user_host instead of row.host, so the hostname matches mysql.user.Host, which never contains a port. * src/Plugins/Transformations/{Input/Text_Plain_{Json,Sql,Xml}Editor, Output/Text_Plain_{Json,Sql,Xml}}.php Ported3b46e5b869. Kept master's Config::getInstance()->config->CodemirrorEnable accessor and expressed the HTTP_USER_AGENT check with Core::getEnv() rather than $_SERVER, to match the same #20159 guard already present in src/Header.php:225. * src/SystemDatabase.php Ported the memory part of #20426 only: getColumnMapFromSql() now wraps the query as `SELECT * FROM (...) AS tmp LIMIT 0` (80638e8371) so a large VIEW cannot exhaust memory while only its column metadata is wanted. This is where libraries/classes/DatabaseInterface.php's hunk landed: the method moved from the DBAL to SystemDatabase on master. Deliberately did NOT port6c1568b15b"Move getColumnMapFromSql into the method": that commit exists to stop 5.2's CreateController from running the view query when there is no transformation data, but master already only calls it inside `if ($pmaTransformationData !== false)` (src/Controllers/View/CreateController.php:205), and getExistingTransformationData() returns false precisely when browserTransformationFeature is null. Porting the signature churn would have degraded master's SystemColumn[] API for no behaviour gain, so src/Controllers/View/CreateController.php is left untouched and that commit's phpstan/psalm baseline hunks are moot. * src/Table/Table.php Ported80638e8371: getColumnsMeta() uses `LIMIT 0` instead of `LIMIT 1`. * src/Table/Search.php Resolved as ours. QA_5_2's8525d24e09is the same fix master already carries via725a767cc5(#20398 / #20395), only expressed against the refactored $needsQuoting code. No change needed. * tests/unit/Controllers/Server/Status/Processes/RefreshControllerTest.php Ported544839869d: covers both that the Host column still shows the port and that the privileges link does not. Added the trailing comma PHPCS (SlevomatCodingStandard.Functions.RequireTrailingCommaInCall) requires. * tests/unit/Stubs/DbiDummy.php Two fixtures updated, both kept in master's compact single-line style: the PROCESSLIST row now returns 'Host1:12345' to exercise port stripping (544839869d), and the `testdb`.`mytable` select moved from LIMIT 1 to LIMIT 0 (80638e8371). * tests/unit/Table/TableTest.php and tests/unit/SystemDatabaseTest.php Expected queries updated for the two changes above (`LIMIT 0`, and `SELECT * FROM (PMA_sql_query) AS tmp LIMIT 0`). The latter is where test/classes/DatabaseInterfaceTest.php's hunk landed, following the method from the DBAL to SystemDatabase. * tests/unit/Table/ColumnsDefinitionTest.php Not a conflicted file, but a master-only fixture that had to follow Table::getColumnsMeta(): the query is now `LIMIT 0` and returns no rows. Incoming changes with no master counterpart: * libraries/classes/Dbal/DbalInterface.php Dropped. The interface does not exist on master, so 80638e8371's rename of its getColumnMapFromSql() parameter has nothing to apply to. * test/classes/Http/Factory/ServerRequestFactoryTest.php1730b7c0bfis a no-op here: master's tests/unit/Http/Factory/ServerRequestFactoryTest.php contains no `(new ReflectionMethod(ServerRequestFactory...))` construct at all, the test having been rewritten. Note that rename detection wrongly paired this file with tests/unit/Http/Factory/UriFactoryTest.php, which was therefore resolved as ours and is unchanged. * phpstan-baseline.neon, psalm-baseline.xml Resolved as ours; the baselines are branch-specific. * resources/po/lv.po, resources/po/vi.po Resolved as ours, dropping the 8 Weblate commits listed above. This matches how all eight previous "Merge branch 'QA_5_2'" commits were resolved (6f427d8785,ccf4064698,fe4be26eeb,055f071473,28cd3776d2,3b4defeb35,ff06deaca2all have a zero-file po diff against their first parent); master runs its own Weblate component. Also removed the empty libraries/ and test/ directories the merge left behind. Verification: `phpunit --testsuite unit` 5668 tests / 18476 assertions OK, `phpcs` clean, `phpstan analyse` reports no errors. `psalm` reports one UnusedBaselineEntry for src/Utils/HttpRequest.php, which is pre-existing on master (neither that file nor psalm-baseline.xml is touched by this merge). Signed-off-by: William Desportes <williamdes@wdes.fr> Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
150 lines
4.8 KiB
PHP
150 lines
4.8 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace PhpMyAdmin\Tests;
|
|
|
|
use PhpMyAdmin\Config;
|
|
use PhpMyAdmin\ConfigStorage\Relation;
|
|
use PhpMyAdmin\ConfigStorage\RelationParameters;
|
|
use PhpMyAdmin\Dbal\DatabaseInterface;
|
|
use PhpMyAdmin\SystemColumn;
|
|
use PhpMyAdmin\SystemDatabase;
|
|
use PhpMyAdmin\Tests\Stubs\DummyResult;
|
|
use PHPUnit\Framework\Attributes\AllowMockObjectsWithoutExpectations;
|
|
use PHPUnit\Framework\Attributes\CoversClass;
|
|
use ReflectionProperty;
|
|
|
|
use const MYSQLI_TYPE_STRING;
|
|
|
|
#[CoversClass(SystemDatabase::class)]
|
|
#[CoversClass(SystemColumn::class)]
|
|
#[AllowMockObjectsWithoutExpectations]
|
|
class SystemDatabaseTest extends AbstractTestCase
|
|
{
|
|
/**
|
|
* SystemDatabase instance
|
|
*/
|
|
private SystemDatabase $sysDb;
|
|
|
|
/**
|
|
* Setup function for test cases
|
|
*/
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
|
|
/**
|
|
* SET these to avoid undefine d index error
|
|
*/
|
|
Config::getInstance()->selectedServer['pmadb'] = '';
|
|
|
|
$dbi = $this->createMock(DatabaseInterface::class);
|
|
|
|
$dbi->method('tryQuery')->willReturn($this->createStub(DummyResult::class));
|
|
|
|
$dbi->method('quoteString')
|
|
->willReturnCallback(static fn (string $string): string => "'" . $string . "'");
|
|
|
|
$relationParameters = RelationParameters::fromArray([
|
|
RelationParameters::TABLE_COORDS => 'table_name',
|
|
RelationParameters::DISPLAY_WORK => true,
|
|
RelationParameters::DATABASE => 'information_schema',
|
|
RelationParameters::TABLE_INFO => 'table_info',
|
|
RelationParameters::REL_WORK => true,
|
|
RelationParameters::COMM_WORK => true,
|
|
RelationParameters::PDF_WORK => true,
|
|
RelationParameters::MIME_WORK => true,
|
|
RelationParameters::COLUMN_INFO => 'column_info',
|
|
RelationParameters::RELATION => 'relation',
|
|
]);
|
|
(new ReflectionProperty(Relation::class, 'cache'))->setValue(null, $relationParameters);
|
|
|
|
$this->sysDb = new SystemDatabase($dbi);
|
|
}
|
|
|
|
/**
|
|
* Tests for PMA_getExistingTransformationData() method.
|
|
*/
|
|
public function testPMAGetExistingTransformationData(): void
|
|
{
|
|
$db = 'PMA_db';
|
|
$ret = $this->sysDb->getExistingTransformationData($db);
|
|
|
|
//validate that is the same as $dbi->tryQuery
|
|
self::assertInstanceOf(DummyResult::class, $ret);
|
|
}
|
|
|
|
/**
|
|
* Tests for PMA_getNewTransformationDataSql() method.
|
|
*/
|
|
public function testPMAGetNewTransformationDataSql(): void
|
|
{
|
|
$resultStub = $this->createMock(DummyResult::class);
|
|
|
|
$resultStub->method('fetchAssoc')->willReturn([
|
|
'table_name' => 'table_name',
|
|
'column_name' => 'column_name',
|
|
'comment' => 'comment',
|
|
'mimetype' => 'mimetype',
|
|
'transformation' => 'transformation',
|
|
'transformation_options' => 'transformation_options',
|
|
]);
|
|
|
|
$db = 'PMA_db';
|
|
$columnMap = [new SystemColumn('table_name', 'column_name', null)];
|
|
$viewName = 'view_name';
|
|
|
|
$ret = $this->sysDb->getNewTransformationDataSql($resultStub, $columnMap, $viewName, $db);
|
|
|
|
$sql = 'INSERT INTO `information_schema`.`column_info` '
|
|
. '(`db_name`, `table_name`, `column_name`, `comment`, `mimetype`, '
|
|
. '`transformation`, `transformation_options`) VALUES '
|
|
. "('PMA_db', 'view_name', 'column_name', 'comment', 'mimetype', "
|
|
. "'transformation', 'transformation_options')";
|
|
|
|
self::assertSame($sql, $ret);
|
|
}
|
|
|
|
public function testGetColumnMapFromSql(): void
|
|
{
|
|
$dummyDbi = $this->createDbiDummy();
|
|
$dbi = $this->createDatabaseInterface($dummyDbi);
|
|
|
|
$dummyDbi->addResult(
|
|
'SELECT * FROM (PMA_sql_query) AS tmp LIMIT 0',
|
|
true,
|
|
[],
|
|
[
|
|
FieldHelper::fromArray([
|
|
'type' => MYSQLI_TYPE_STRING,
|
|
'table' => 'meta1_table',
|
|
'name' => 'meta1_name',
|
|
]),
|
|
FieldHelper::fromArray([
|
|
'type' => MYSQLI_TYPE_STRING,
|
|
'table' => 'meta2_table',
|
|
'name' => 'meta2_name',
|
|
]),
|
|
],
|
|
);
|
|
|
|
$sqlQuery = 'PMA_sql_query';
|
|
$viewColumns = ['view_columns1', 'view_columns2'];
|
|
|
|
$systemDatabase = new SystemDatabase($dbi);
|
|
$columnMap = $systemDatabase->getColumnMapFromSql($sqlQuery, $viewColumns);
|
|
|
|
self::assertEquals(
|
|
new SystemColumn('meta1_table', 'meta1_name', 'view_columns1'),
|
|
$columnMap[0],
|
|
);
|
|
self::assertEquals(
|
|
new SystemColumn('meta2_table', 'meta2_name', 'view_columns2'),
|
|
$columnMap[1],
|
|
);
|
|
|
|
$dummyDbi->assertAllQueriesConsumed();
|
|
}
|
|
}
|