diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon
index 7622a87284..86fd4d008a 100644
--- a/phpstan-baseline.neon
+++ b/phpstan-baseline.neon
@@ -16320,16 +16320,6 @@ parameters:
count: 6
path: tests/unit/Plugins/Import/ImportLdiTest.php
- -
- message: "#^Class PhpMyAdmin\\\\Tests\\\\Plugins\\\\Import\\\\ImportOdsTest has an uninitialized property \\$dbi\\. Give it default value or assign it in the constructor\\.$#"
- count: 1
- path: tests/unit/Plugins/Import/ImportOdsTest.php
-
- -
- message: "#^Class PhpMyAdmin\\\\Tests\\\\Plugins\\\\Import\\\\ImportOdsTest has an uninitialized property \\$dummyDbi\\. Give it default value or assign it in the constructor\\.$#"
- count: 1
- path: tests/unit/Plugins/Import/ImportOdsTest.php
-
-
message: "#^Parameter \\#2 \\$haystack of static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertStringContainsString\\(\\) expects string, mixed given\\.$#"
count: 3
diff --git a/psalm-baseline.xml b/psalm-baseline.xml
index e2e4e98f69..52c84d5e2d 100644
--- a/psalm-baseline.xml
+++ b/psalm-baseline.xml
@@ -8671,11 +8671,6 @@
-
-
-
-
-
@@ -14246,11 +14241,6 @@
-
-
-
-
-
@@ -14260,24 +14250,11 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/src/Plugins/Import/ImportOds.php b/src/Plugins/Import/ImportOds.php
index eb422c062d..39847e46f1 100644
--- a/src/Plugins/Import/ImportOds.php
+++ b/src/Plugins/Import/ImportOds.php
@@ -40,6 +40,11 @@ use const LIBXML_COMPACT;
*/
class ImportOds extends ImportPlugin
{
+ private bool $recognizePercentages = false;
+ private bool $recognizeCurrency = false;
+ private bool $includeEmptyRows = false;
+ private bool $hasColumnNames = false;
+
/** @psalm-return non-empty-lowercase-string */
public function getName(): string
{
@@ -99,6 +104,10 @@ class ImportOds extends ImportPlugin
public function setImportOptions(ServerRequest $request): void
{
+ $this->recognizePercentages = $request->getParsedBodyParam('ods_recognize_percentages') !== null;
+ $this->recognizeCurrency = $request->getParsedBodyParam('ods_recognize_currency') !== null;
+ $this->includeEmptyRows = $request->getParsedBodyParam('ods_empty_rows') !== null;
+ $this->hasColumnNames = $request->getParsedBodyParam('ods_col_names') !== null;
}
/**
@@ -163,7 +172,7 @@ class ImportOds extends ImportPlugin
}
}
- $tables = $this->readSheets($sheets, isset($_REQUEST['ods_col_names']));
+ $tables = $this->readSheets($sheets, $this->hasColumnNames);
/* Obtain the best-fit MySQL types for each column */
$analyses = array_map($this->import->analyzeTable(...), $tables);
@@ -194,16 +203,14 @@ class ImportOds extends ImportPlugin
protected function getValue(SimpleXMLElement $cellAttrs, SimpleXMLElement $text): float|string
{
if (
- isset($_REQUEST['ods_recognize_percentages'])
- && $_REQUEST['ods_recognize_percentages']
+ $this->recognizePercentages
&& (string) $cellAttrs['value-type'] === 'percentage'
) {
return (float) $cellAttrs['value'];
}
if (
- isset($_REQUEST['ods_recognize_currency'])
- && $_REQUEST['ods_recognize_currency']
+ $this->recognizeCurrency
&& (string) $cellAttrs['value-type'] === 'currency'
) {
return (float) $cellAttrs['value'];
@@ -302,7 +309,7 @@ class ImportOds extends ImportPlugin
$maxCols = max(count($tempRow), $maxCols);
/* Don't include a row that is full of NULL values */
- if ($_REQUEST['ods_empty_rows'] ?? false) {
+ if ($this->includeEmptyRows) {
foreach ($tempRow as $cell) {
if ((string) $cell !== 'NULL') {
$tempRows[] = $tempRow;
diff --git a/tests/unit/Plugins/Import/ImportLdiTest.php b/tests/unit/Plugins/Import/ImportLdiTest.php
index 7df694ecfe..24ade069dc 100644
--- a/tests/unit/Plugins/Import/ImportLdiTest.php
+++ b/tests/unit/Plugins/Import/ImportLdiTest.php
@@ -30,7 +30,6 @@ class ImportLdiTest extends AbstractTestCase
{
parent::setUp();
- DatabaseInterface::$instance = $this->createDatabaseInterface();
ImportSettings::$charsetConversion = false;
ImportSettings::$maxSqlLength = 0;
$GLOBALS['sql_query'] = '';
diff --git a/tests/unit/Plugins/Import/ImportMediawikiTest.php b/tests/unit/Plugins/Import/ImportMediawikiTest.php
index 594571b295..d1f0faf4eb 100644
--- a/tests/unit/Plugins/Import/ImportMediawikiTest.php
+++ b/tests/unit/Plugins/Import/ImportMediawikiTest.php
@@ -4,7 +4,6 @@ declare(strict_types=1);
namespace PhpMyAdmin\Tests\Plugins\Import;
-use PhpMyAdmin\Config;
use PhpMyAdmin\Current;
use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\File;
@@ -30,7 +29,6 @@ class ImportMediawikiTest extends AbstractTestCase
{
parent::setUp();
- DatabaseInterface::$instance = $this->createDatabaseInterface();
$GLOBALS['error'] = null;
ImportSettings::$timeoutPassed = false;
ImportSettings::$maximumTime = 0;
@@ -44,17 +42,14 @@ class ImportMediawikiTest extends AbstractTestCase
ImportSettings::$runQuery = false;
ImportSettings::$goSql = false;
ImportSettings::$importType = 'database';
- $this->object = new ImportMediawiki();
-
- //setting
ImportSettings::$finished = false;
ImportSettings::$readLimit = 100000000;
ImportSettings::$offset = 0;
- Config::getInstance()->selectedServer['DisableIS'] = false;
-
ImportSettings::$importFile = 'tests/test_data/phpmyadmin.mediawiki';
$GLOBALS['import_text'] = 'ImportMediawiki_Test';
ImportSettings::$readMultiply = 10;
+
+ $this->object = new ImportMediawiki();
}
/**
@@ -98,9 +93,6 @@ class ImportMediawikiTest extends AbstractTestCase
*/
public function testDoImport(): void
{
- //$import_notice will show the import detail result
-
- //Mock DBI
$dbi = $this->getMockBuilder(DatabaseInterface::class)
->disableOriginalConstructor()
->getMock();
@@ -139,7 +131,6 @@ class ImportMediawikiTest extends AbstractTestCase
public function testDoImportWithEmptyTable(): void
{
- //Mock DBI
$dbi = $this->getMockBuilder(DatabaseInterface::class)
->disableOriginalConstructor()
->getMock();
diff --git a/tests/unit/Plugins/Import/ImportOdsTest.php b/tests/unit/Plugins/Import/ImportOdsTest.php
index 11a806edec..c108dbf6fc 100644
--- a/tests/unit/Plugins/Import/ImportOdsTest.php
+++ b/tests/unit/Plugins/Import/ImportOdsTest.php
@@ -8,10 +8,10 @@ use PhpMyAdmin\Config;
use PhpMyAdmin\Current;
use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\File;
+use PhpMyAdmin\Http\Factory\ServerRequestFactory;
use PhpMyAdmin\Import\ImportSettings;
use PhpMyAdmin\Plugins\Import\ImportOds;
use PhpMyAdmin\Tests\AbstractTestCase;
-use PhpMyAdmin\Tests\Stubs\DbiDummy;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Medium;
@@ -25,10 +25,6 @@ use function str_repeat;
#[Medium]
class ImportOdsTest extends AbstractTestCase
{
- protected DatabaseInterface $dbi;
-
- protected DbiDummy $dummyDbi;
-
protected ImportOds $object;
/**
@@ -39,7 +35,6 @@ class ImportOdsTest extends AbstractTestCase
{
parent::setUp();
- DatabaseInterface::$instance = $this->createDatabaseInterface();
$GLOBALS['error'] = null;
ImportSettings::$timeoutPassed = false;
ImportSettings::$maximumTime = 0;
@@ -51,22 +46,21 @@ class ImportOdsTest extends AbstractTestCase
ImportSettings::$runQuery = false;
$GLOBALS['sql_query'] = '';
ImportSettings::$goSql = false;
- $this->object = new ImportOds();
-
- //setting
ImportSettings::$finished = false;
ImportSettings::$readLimit = 100000000;
ImportSettings::$offset = 0;
Config::getInstance()->selectedServer['DisableIS'] = false;
-
- /**
- * Load interface for zip extension.
- */
ImportSettings::$readMultiply = 10;
+ $this->object = new ImportOds();
+
//variable for Ods
- $_REQUEST['ods_recognize_percentages'] = true;
- $_REQUEST['ods_recognize_currency'] = true;
+ $request = ServerRequestFactory::create()->createServerRequest('POST', 'http://example.com/')
+ ->withParsedBody([
+ 'ods_recognize_percentages' => 'yes',
+ 'ods_recognize_currency' => 'yes',
+ ]);
+ $this->object->setImportOptions($request);
}
/**
@@ -105,23 +99,24 @@ class ImportOdsTest extends AbstractTestCase
*/
public function testDoImport(): void
{
- //$sql_query_disabled will show the import SQL detail
- //$import_notice will show the import detail result
-
- ImportSettings::$sqlQueryDisabled = false;
+ ImportSettings::$sqlQueryDisabled = false; //will show the import SQL detail
ImportSettings::$importFile = 'tests/test_data/db_test.ods';
- $_REQUEST['ods_empty_rows'] = true;
- $this->dummyDbi = $this->createDbiDummy();
- $this->dbi = $this->createDatabaseInterface($this->dummyDbi);
- DatabaseInterface::$instance = $this->dbi;
+ $request = ServerRequestFactory::create()->createServerRequest('POST', 'http://example.com/')
+ ->withParsedBody([
+ 'ods_recognize_percentages' => 'yes',
+ 'ods_recognize_currency' => 'yes',
+ 'ods_empty_rows' => 'yes',
+ ]);
+ $this->object->setImportOptions($request);
+
+ DatabaseInterface::$instance = $this->createDatabaseInterface();
$importHandle = new File(ImportSettings::$importFile);
$importHandle->setDecompressContent(true);
$importHandle->open();
- //Test function called
$this->object->doImport($importHandle);
self::assertStringContainsString(
@@ -134,7 +129,7 @@ class ImportOdsTest extends AbstractTestCase
$GLOBALS['sql_query'],
);
- //asset that all databases and tables are imported
+ //assert that all databases and tables are imported
self::assertStringContainsString(
'The following structures have either been created or altered.',
ImportSettings::$importNotice,
@@ -144,14 +139,17 @@ class ImportOdsTest extends AbstractTestCase
self::assertStringContainsString('Go to table: `pma_bookmark`', ImportSettings::$importNotice);
self::assertStringContainsString('Edit settings for `pma_bookmark`', ImportSettings::$importNotice);
- //asset that the import process is finished
+ //assert that the import process is finished
self::assertTrue(ImportSettings::$finished);
}
- /** @return mixed[] */
+ /** @return array> */
public static function dataProviderOdsEmptyRows(): array
{
- return ['remove empty columns' => [true], 'keep empty columns' => [false]];
+ return [
+ 'remove empty columns' => ['yes'],
+ 'keep empty columns' => [null],
+ ];
}
/**
@@ -159,20 +157,21 @@ class ImportOdsTest extends AbstractTestCase
*/
#[DataProvider('dataProviderOdsEmptyRows')]
#[RequiresPhpExtension('simplexml')]
- public function testDoImportDataset2(bool $odsEmptyRowsMode): void
+ public function testDoImportDataset2(string|null $odsEmptyRowsMode): void
{
- //$sql_query_disabled will show the import SQL detail
- //$import_notice will show the import detail result
-
- ImportSettings::$sqlQueryDisabled = false;
+ ImportSettings::$sqlQueryDisabled = false; //will show the import SQL detail
ImportSettings::$importFile = 'tests/test_data/import-slim.ods.xml';
- $_REQUEST['ods_col_names'] = true;
- $_REQUEST['ods_empty_rows'] = $odsEmptyRowsMode;
+ $request = ServerRequestFactory::create()->createServerRequest('POST', 'http://example.com/')
+ ->withParsedBody([
+ 'ods_recognize_percentages' => 'yes',
+ 'ods_recognize_currency' => 'yes',
+ 'ods_col_names' => 'yes',
+ 'ods_empty_rows' => $odsEmptyRowsMode,
+ ]);
+ $this->object->setImportOptions($request);
- $this->dummyDbi = $this->createDbiDummy();
- $this->dbi = $this->createDatabaseInterface($this->dummyDbi);
- DatabaseInterface::$instance = $this->dbi;
+ DatabaseInterface::$instance = $this->createDatabaseInterface();
$importHandle = new File(ImportSettings::$importFile);
$importHandle->setDecompressContent(false);// Not compressed
@@ -183,12 +182,11 @@ class ImportOdsTest extends AbstractTestCase
$endOfSql = ');';
- if (! $odsEmptyRowsMode) {
+ if ($odsEmptyRowsMode === null) {
$fullCols = 'NULL' . str_repeat(', NULL', 18);// 19 empty cells
$endOfSql = '),' . "\n" . ' (' . $fullCols . '),' . "\n" . ' (' . $fullCols . ');';
}
- //Test function called
$this->object->doImport($importHandle);
self::assertSame(
@@ -240,12 +238,12 @@ class ImportOdsTest extends AbstractTestCase
. ' (\'0.05\'),' . "\n"
. ' (\'true\'),' . "\n"
. ' (\'12\')'
- . ($odsEmptyRowsMode ? '' : ',' . "\n" . ' (NULL)')
- . ($odsEmptyRowsMode ? ';' : ',' . "\n" . ' (NULL);'),
+ . ($odsEmptyRowsMode !== null ? '' : ',' . "\n" . ' (NULL)')
+ . ($odsEmptyRowsMode !== null ? ';' : ',' . "\n" . ' (NULL);'),
$GLOBALS['sql_query'],
);
- //asset that all databases and tables are imported
+ //assert that all databases and tables are imported
self::assertStringContainsString(
'The following structures have either been created or altered.',
ImportSettings::$importNotice,
@@ -255,7 +253,7 @@ class ImportOdsTest extends AbstractTestCase
self::assertStringContainsString('Go to table: `Shop`', ImportSettings::$importNotice);
self::assertStringContainsString('Edit settings for `Shop`', ImportSettings::$importNotice);
- //asset that the import process is finished
+ //assert that the import process is finished
self::assertTrue(ImportSettings::$finished);
}
}
diff --git a/tests/unit/Plugins/Import/ImportShpTest.php b/tests/unit/Plugins/Import/ImportShpTest.php
index be4d1b9b36..7433c92566 100644
--- a/tests/unit/Plugins/Import/ImportShpTest.php
+++ b/tests/unit/Plugins/Import/ImportShpTest.php
@@ -4,7 +4,6 @@ declare(strict_types=1);
namespace PhpMyAdmin\Tests\Plugins\Import;
-use PhpMyAdmin\Config;
use PhpMyAdmin\Current;
use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\File;
@@ -35,7 +34,6 @@ class ImportShpTest extends AbstractTestCase
parent::setUp();
$GLOBALS['error'] = null;
- $GLOBALS['buffer'] = null;
ImportSettings::$maximumTime = 0;
ImportSettings::$charsetConversion = false;
$GLOBALS['eof'] = null;
@@ -46,15 +44,11 @@ class ImportShpTest extends AbstractTestCase
ImportSettings::$executedQueries = 0;
ImportSettings::$runQuery = false;
ImportSettings::$goSql = false;
-
- //setting
ImportSettings::$importType = 'table';
ImportSettings::$finished = false;
ImportSettings::$readLimit = 100000000;
ImportSettings::$offset = 0;
- Config::getInstance()->selectedServer['DisableIS'] = false;
- //Mock DBI
$dbi = $this->getMockBuilder(DatabaseInterface::class)
->disableOriginalConstructor()
->getMock();
@@ -62,7 +56,6 @@ class ImportShpTest extends AbstractTestCase
$this->object = new ImportShp();
- $GLOBALS['compression'] = 'application/zip';
ImportSettings::$readMultiply = 10;
Current::$database = '';
Current::$table = '';
@@ -126,13 +119,9 @@ class ImportShpTest extends AbstractTestCase
#[Group('32bit-incompatible')]
public function testImportOsm(): void
{
- //$sql_query_disabled will show the import SQL detail
- //$import_notice will show the import detail result
-
- ImportSettings::$sqlQueryDisabled = false;
+ ImportSettings::$sqlQueryDisabled = false; //will show the import SQL detail
Current::$database = '';
- //Test function called
$this->runImport('tests/test_data/dresden_osm.shp.zip');
$this->assertMessages(ImportSettings::$importNotice);
@@ -160,16 +149,11 @@ class ImportShpTest extends AbstractTestCase
#[Group('32bit-incompatible')]
public function testDoImport(): void
{
- //$sql_query_disabled will show the import SQL detail
- //$import_notice will show the import detail result
-
- ImportSettings::$sqlQueryDisabled = false;
+ ImportSettings::$sqlQueryDisabled = false; //will show the import SQL detail
Current::$database = '';
- //Test function called
$this->runImport('tests/test_data/timezone.shp.zip');
- // asset that all sql are executed
self::assertStringContainsString(
'CREATE DATABASE IF NOT EXISTS `SHP_DB` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci',
$GLOBALS['sql_query'],
@@ -201,7 +185,7 @@ class ImportShpTest extends AbstractTestCase
self::assertStringContainsString("GeomFromText('POINT(1294523.1759236", $GLOBALS['sql_query']);
- //asset that all databases and tables are imported
+ //assert that all databases and tables are imported
$this->assertMessages(ImportSettings::$importNotice);
}
@@ -221,7 +205,7 @@ class ImportShpTest extends AbstractTestCase
self::assertStringContainsString('Go to table: `TBL_NAME`', $importNotice);
self::assertStringContainsString('Edit settings for `TBL_NAME`', $importNotice);
- //asset that the import process is finished
+ //assert that the import process is finished
self::assertTrue(ImportSettings::$finished);
}
}
diff --git a/tests/unit/Plugins/Import/ImportSqlTest.php b/tests/unit/Plugins/Import/ImportSqlTest.php
index dbd46c41c4..6ac575c991 100644
--- a/tests/unit/Plugins/Import/ImportSqlTest.php
+++ b/tests/unit/Plugins/Import/ImportSqlTest.php
@@ -4,7 +4,6 @@ declare(strict_types=1);
namespace PhpMyAdmin\Tests\Plugins\Import;
-use PhpMyAdmin\Config;
use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\File;
use PhpMyAdmin\Import\ImportSettings;
@@ -27,7 +26,6 @@ class ImportSqlTest extends AbstractTestCase
{
parent::setUp();
- DatabaseInterface::$instance = $this->createDatabaseInterface();
$GLOBALS['error'] = null;
ImportSettings::$timeoutPassed = false;
ImportSettings::$maximumTime = 0;
@@ -38,19 +36,14 @@ class ImportSqlTest extends AbstractTestCase
ImportSettings::$executedQueries = 0;
ImportSettings::$runQuery = false;
ImportSettings::$goSql = false;
-
- $this->object = new ImportSql();
-
- //setting
ImportSettings::$finished = false;
ImportSettings::$readLimit = 100000000;
ImportSettings::$offset = 0;
- Config::getInstance()->selectedServer['DisableIS'] = false;
-
ImportSettings::$importFile = 'tests/test_data/pma_bookmark.sql';
$GLOBALS['import_text'] = 'ImportSql_Test';
- $GLOBALS['compression'] = 'none';
ImportSettings::$readMultiply = 10;
+
+ $this->object = new ImportSql();
}
/**
@@ -69,11 +62,8 @@ class ImportSqlTest extends AbstractTestCase
*/
public function testDoImport(): void
{
- //$sql_query_disabled will show the import SQL detail
+ ImportSettings::$sqlQueryDisabled = false; // will show the import SQL detail
- ImportSettings::$sqlQueryDisabled = false;
-
- //Mock DBI
$dbi = $this->getMockBuilder(DatabaseInterface::class)
->disableOriginalConstructor()
->getMock();
@@ -82,10 +72,8 @@ class ImportSqlTest extends AbstractTestCase
$importHandle = new File(ImportSettings::$importFile);
$importHandle->open();
- //Test function called
$this->object->doImport($importHandle);
- //asset that all sql are executed
self::assertStringContainsString('SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"', $GLOBALS['sql_query']);
self::assertStringContainsString('CREATE TABLE IF NOT EXISTS `pma_bookmark`', $GLOBALS['sql_query']);
self::assertStringContainsString(
diff --git a/tests/unit/Plugins/Import/ImportXmlTest.php b/tests/unit/Plugins/Import/ImportXmlTest.php
index 7c34f99eed..4e507824b2 100644
--- a/tests/unit/Plugins/Import/ImportXmlTest.php
+++ b/tests/unit/Plugins/Import/ImportXmlTest.php
@@ -4,7 +4,6 @@ declare(strict_types=1);
namespace PhpMyAdmin\Tests\Plugins\Import;
-use PhpMyAdmin\Config;
use PhpMyAdmin\Current;
use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\File;
@@ -33,7 +32,6 @@ class ImportXmlTest extends AbstractTestCase
{
parent::setUp();
- DatabaseInterface::$instance = $this->createDatabaseInterface();
$GLOBALS['error'] = null;
ImportSettings::$timeoutPassed = false;
ImportSettings::$maximumTime = 0;
@@ -46,19 +44,14 @@ class ImportXmlTest extends AbstractTestCase
ImportSettings::$executedQueries = 0;
ImportSettings::$runQuery = false;
ImportSettings::$goSql = false;
-
- $this->object = new ImportXml();
-
- //setting
ImportSettings::$finished = false;
ImportSettings::$readLimit = 100000000;
ImportSettings::$offset = 0;
- Config::getInstance()->selectedServer['DisableIS'] = false;
-
ImportSettings::$importFile = 'tests/test_data/phpmyadmin_importXML_For_Testing.xml';
$GLOBALS['import_text'] = 'ImportXml_Test';
- $GLOBALS['compression'] = 'none';
ImportSettings::$readMultiply = 10;
+
+ $this->object = new ImportXml();
}
/**
@@ -103,9 +96,6 @@ class ImportXmlTest extends AbstractTestCase
#[RequiresPhpExtension('simplexml')]
public function testDoImport(): void
{
- //$import_notice will show the import detail result
-
- //Mock DBI
$dbi = $this->getMockBuilder(DatabaseInterface::class)
->disableOriginalConstructor()
->getMock();
@@ -114,7 +104,6 @@ class ImportXmlTest extends AbstractTestCase
$importHandle = new File(ImportSettings::$importFile);
$importHandle->open();
- //Test function called
$this->object->doImport($importHandle);
// If import successfully, PMA will show all databases and tables
@@ -130,7 +119,6 @@ class ImportXmlTest extends AbstractTestCase
pma_bookmarktest (Structure) (Options)
*/
- //asset that all databases and tables are imported
self::assertStringContainsString(
'The following structures have either been created or altered.',
ImportSettings::$importNotice,