Extract dependencies from Import\Import class
Uses DI instead. Signed-off-by: Maurício Meneghini Fauth <mauricio@mfauth.net>
This commit is contained in:
parent
77cd124a6e
commit
7fc625738b
@ -124,7 +124,10 @@ return [
|
||||
],
|
||||
HttpRequest::class => ['class' => HttpRequest::class],
|
||||
ResponseFactory::class => ['class' => ResponseFactory::class, 'factory' => [ResponseFactory::class, 'create']],
|
||||
Import::class => ['class' => Import::class],
|
||||
Import::class => [
|
||||
'class' => Import::class,
|
||||
'arguments' => [DatabaseInterface::class, ResponseRenderer::class, Config::class],
|
||||
],
|
||||
SimulateDml::class => ['class' => SimulateDml::class, 'arguments' => [DatabaseInterface::class]],
|
||||
InsertEdit::class => [
|
||||
'class' => InsertEdit::class,
|
||||
|
||||
@ -7059,24 +7059,6 @@ parameters:
|
||||
count: 1
|
||||
path: src/Import/Ajax.php
|
||||
|
||||
-
|
||||
message: '''
|
||||
#^Call to deprecated method getInstance\(\) of class PhpMyAdmin\\Config\:
|
||||
Use dependency injection instead\.$#
|
||||
'''
|
||||
identifier: staticMethod.deprecated
|
||||
count: 4
|
||||
path: src/Import/Import.php
|
||||
|
||||
-
|
||||
message: '''
|
||||
#^Call to deprecated method getInstance\(\) of class PhpMyAdmin\\Dbal\\DatabaseInterface\:
|
||||
Use dependency injection instead\.$#
|
||||
'''
|
||||
identifier: staticMethod.deprecated
|
||||
count: 5
|
||||
path: src/Import/Import.php
|
||||
|
||||
-
|
||||
message: '#^Cannot access property \$precision on int\|PhpMyAdmin\\Import\\DecimalSize\.$#'
|
||||
identifier: property.nonObject
|
||||
@ -9645,6 +9627,15 @@ parameters:
|
||||
Use dependency injection instead\.$#
|
||||
'''
|
||||
identifier: staticMethod.deprecated
|
||||
count: 2
|
||||
path: src/Plugins/Import/ImportShp.php
|
||||
|
||||
-
|
||||
message: '''
|
||||
#^Call to deprecated method getInstance\(\) of class PhpMyAdmin\\Dbal\\DatabaseInterface\:
|
||||
Use dependency injection instead\.$#
|
||||
'''
|
||||
identifier: staticMethod.deprecated
|
||||
count: 1
|
||||
path: src/Plugins/Import/ImportShp.php
|
||||
|
||||
@ -9921,6 +9912,24 @@ parameters:
|
||||
count: 1
|
||||
path: src/Plugins/Import/Upload/UploadSession.php
|
||||
|
||||
-
|
||||
message: '''
|
||||
#^Call to deprecated method getInstance\(\) of class PhpMyAdmin\\Config\:
|
||||
Use dependency injection instead\.$#
|
||||
'''
|
||||
identifier: staticMethod.deprecated
|
||||
count: 1
|
||||
path: src/Plugins/ImportPlugin.php
|
||||
|
||||
-
|
||||
message: '''
|
||||
#^Call to deprecated method getInstance\(\) of class PhpMyAdmin\\Dbal\\DatabaseInterface\:
|
||||
Use dependency injection instead\.$#
|
||||
'''
|
||||
identifier: staticMethod.deprecated
|
||||
count: 1
|
||||
path: src/Plugins/ImportPlugin.php
|
||||
|
||||
-
|
||||
message: '#^Cannot cast mixed to string\.$#'
|
||||
identifier: cast.string
|
||||
|
||||
@ -4931,17 +4931,6 @@
|
||||
<ArgumentTypeCoercion>
|
||||
<code><![CDATA[$sqlDelimiter]]></code>
|
||||
</ArgumentTypeCoercion>
|
||||
<DeprecatedMethod>
|
||||
<code><![CDATA[Config::getInstance()]]></code>
|
||||
<code><![CDATA[Config::getInstance()]]></code>
|
||||
<code><![CDATA[Config::getInstance()]]></code>
|
||||
<code><![CDATA[Config::getInstance()]]></code>
|
||||
<code><![CDATA[DatabaseInterface::getInstance()]]></code>
|
||||
<code><![CDATA[DatabaseInterface::getInstance()]]></code>
|
||||
<code><![CDATA[DatabaseInterface::getInstance()]]></code>
|
||||
<code><![CDATA[DatabaseInterface::getInstance()]]></code>
|
||||
<code><![CDATA[DatabaseInterface::getInstance()]]></code>
|
||||
</DeprecatedMethod>
|
||||
<DocblockTypeContradiction>
|
||||
<code><![CDATA[$nameArray === false]]></code>
|
||||
</DocblockTypeContradiction>
|
||||
@ -6509,6 +6498,8 @@
|
||||
<file src="src/Plugins/Import/ImportShp.php">
|
||||
<DeprecatedMethod>
|
||||
<code><![CDATA[Config::getInstance()]]></code>
|
||||
<code><![CDATA[Config::getInstance()]]></code>
|
||||
<code><![CDATA[DatabaseInterface::getInstance()]]></code>
|
||||
</DeprecatedMethod>
|
||||
<MixedArgument>
|
||||
<code><![CDATA[$dbfFilePath]]></code>
|
||||
@ -6681,6 +6672,10 @@
|
||||
</UnusedClass>
|
||||
</file>
|
||||
<file src="src/Plugins/ImportPlugin.php">
|
||||
<DeprecatedMethod>
|
||||
<code><![CDATA[Config::getInstance()]]></code>
|
||||
<code><![CDATA[DatabaseInterface::getInstance()]]></code>
|
||||
</DeprecatedMethod>
|
||||
<PossiblyUnusedReturnValue>
|
||||
<code><![CDATA[string[]]]></code>
|
||||
</PossiblyUnusedReturnValue>
|
||||
|
||||
@ -85,7 +85,7 @@ final readonly class ImportController implements InvocableController
|
||||
|
||||
$timeoutPassed = $_REQUEST['timeout_passed'] ?? null;
|
||||
$localImportFile = $_REQUEST['local_import_file'] ?? null;
|
||||
$compressions = Import::getCompressions();
|
||||
$compressions = Import::getCompressions($this->config);
|
||||
|
||||
$charsets = Charsets::getCharsets($this->dbi, $this->config->selectedServer['DisableIS']);
|
||||
|
||||
@ -126,7 +126,7 @@ final readonly class ImportController implements InvocableController
|
||||
'charsets' => $charsets,
|
||||
'is_foreign_key_check' => ForeignKey::isCheckEnabled(),
|
||||
'user_upload_dir' => Util::userDir($this->config->config->UploadDir),
|
||||
'local_files' => Import::getLocalFiles($importList),
|
||||
'local_files' => Import::getLocalFiles($this->config, $importList),
|
||||
]);
|
||||
|
||||
return $this->response->response();
|
||||
|
||||
@ -70,7 +70,7 @@ final readonly class ImportController implements InvocableController
|
||||
|
||||
$timeoutPassed = $_REQUEST['timeout_passed'] ?? null;
|
||||
$localImportFile = $_REQUEST['local_import_file'] ?? null;
|
||||
$compressions = Import::getCompressions();
|
||||
$compressions = Import::getCompressions($this->config);
|
||||
|
||||
$charsets = Charsets::getCharsets($this->dbi, $this->config->selectedServer['DisableIS']);
|
||||
|
||||
@ -111,7 +111,7 @@ final readonly class ImportController implements InvocableController
|
||||
'charsets' => $charsets,
|
||||
'is_foreign_key_check' => ForeignKey::isCheckEnabled(),
|
||||
'user_upload_dir' => Util::userDir($this->config->config->UploadDir),
|
||||
'local_files' => Import::getLocalFiles($importList),
|
||||
'local_files' => Import::getLocalFiles($this->config, $importList),
|
||||
]);
|
||||
|
||||
return $this->response->response();
|
||||
|
||||
@ -109,7 +109,7 @@ final readonly class ImportController implements InvocableController
|
||||
|
||||
$timeoutPassed = $request->getParam('timeout_passed');
|
||||
$localImportFile = $request->getParam('local_import_file');
|
||||
$compressions = Import::getCompressions();
|
||||
$compressions = Import::getCompressions($this->config);
|
||||
|
||||
$charsets = Charsets::getCharsets($this->dbi, $this->config->selectedServer['DisableIS']);
|
||||
|
||||
@ -155,7 +155,7 @@ final readonly class ImportController implements InvocableController
|
||||
'charsets' => $charsets,
|
||||
'is_foreign_key_check' => ForeignKey::isCheckEnabled(),
|
||||
'user_upload_dir' => Util::userDir($this->config->config->UploadDir),
|
||||
'local_files' => Import::getLocalFiles($importList),
|
||||
'local_files' => Import::getLocalFiles($this->config, $importList),
|
||||
]);
|
||||
|
||||
return $this->response->response();
|
||||
|
||||
@ -59,7 +59,7 @@ use function trim;
|
||||
/**
|
||||
* Library that provides common import functions that are used by import plugins
|
||||
*/
|
||||
class Import
|
||||
final class Import
|
||||
{
|
||||
private string|null $importRunBuffer = null;
|
||||
public static bool $hasError = false;
|
||||
@ -68,9 +68,12 @@ class Import
|
||||
public static string $errorUrl = '';
|
||||
private bool $forceExecute = false;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
Config::getInstance()->selectedServer['DisableIS'] = false;
|
||||
public function __construct(
|
||||
private readonly DatabaseInterface $dbi,
|
||||
private readonly ResponseRenderer $responseRenderer,
|
||||
private readonly Config $config,
|
||||
) {
|
||||
$this->config->selectedServer['DisableIS'] = false;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -106,8 +109,7 @@ class Import
|
||||
*/
|
||||
public function executeQuery(string $sql, array &$sqlData): void
|
||||
{
|
||||
$dbi = DatabaseInterface::getInstance();
|
||||
self::$result = $dbi->tryQuery($sql);
|
||||
self::$result = $this->dbi->tryQuery($sql);
|
||||
|
||||
// USE query changes the database, son need to track
|
||||
// while running multiple queries
|
||||
@ -115,18 +117,18 @@ class Import
|
||||
|
||||
ImportSettings::$message = '# ';
|
||||
if (self::$result === false) {
|
||||
ImportSettings::$failedQueries[] = ['sql' => $sql, 'error' => $dbi->getError()];
|
||||
ImportSettings::$failedQueries[] = ['sql' => $sql, 'error' => $this->dbi->getError()];
|
||||
|
||||
ImportSettings::$message .= __('Error');
|
||||
|
||||
if (! Config::getInstance()->settings['IgnoreMultiSubmitErrors']) {
|
||||
if (! $this->config->settings['IgnoreMultiSubmitErrors']) {
|
||||
self::$hasError = true;
|
||||
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
$aNumRows = (int) self::$result->numRows();
|
||||
$aAffectedRows = (int) @$dbi->affectedRows();
|
||||
$aAffectedRows = (int) @$this->dbi->affectedRows();
|
||||
if ($aNumRows > 0) {
|
||||
ImportSettings::$message .= __('Rows') . ': ' . $aNumRows;
|
||||
} elseif ($aAffectedRows > 0) {
|
||||
@ -759,7 +761,7 @@ class Import
|
||||
if ($analyses !== null) {
|
||||
/* TODO: Do more checking here to make sure they really are matched */
|
||||
if (count($tables) !== count($analyses)) {
|
||||
ResponseRenderer::getInstance()->callExit();
|
||||
$this->responseRenderer->callExit();
|
||||
}
|
||||
|
||||
/* Create SQL code to create the tables */
|
||||
@ -809,7 +811,6 @@ class Import
|
||||
*
|
||||
* Only one insert query is formed for each table
|
||||
*/
|
||||
$dbi = DatabaseInterface::getInstance();
|
||||
foreach ($tables as $tableIndex => $table) {
|
||||
$numCols = count($table->columns);
|
||||
$lastColumnKey = array_key_last($table->columns);
|
||||
@ -856,7 +857,7 @@ class Import
|
||||
}
|
||||
|
||||
$tempSQLStr .= $isVarchar
|
||||
? $dbi->quoteString((string) $row[$columnIndex])
|
||||
? $this->dbi->quoteString((string) $row[$columnIndex])
|
||||
: (string) $row[$columnIndex];
|
||||
}
|
||||
|
||||
@ -919,7 +920,7 @@ class Import
|
||||
$tables[] = new ImportTable($regs[1]);
|
||||
}
|
||||
|
||||
$message = $this->getSuccessMessage($dbName, $tables, $dbi);
|
||||
$message = $this->getSuccessMessage($dbName, $tables);
|
||||
|
||||
ImportSettings::$importNotice = $message;
|
||||
}
|
||||
@ -928,7 +929,6 @@ class Import
|
||||
{
|
||||
$sqlDelimiter = $_POST['sql_delimiter'];
|
||||
$queries = explode($sqlDelimiter, $sqlQuery);
|
||||
$dbi = DatabaseInterface::getInstance();
|
||||
foreach ($queries as $sqlQuery) {
|
||||
if ($sqlQuery === '') {
|
||||
continue;
|
||||
@ -939,19 +939,18 @@ class Import
|
||||
continue;
|
||||
}
|
||||
|
||||
$sqlError = $dbi->getError();
|
||||
$sqlError = $this->dbi->getError();
|
||||
$error = $sqlError !== '' ? $sqlError : __(
|
||||
'Only INSERT, UPDATE, DELETE, REPLACE and SET (without options like GLOBAL) '
|
||||
. 'SQL queries containing transactional engine tables can be rolled back.',
|
||||
);
|
||||
|
||||
$response = ResponseRenderer::getInstance();
|
||||
$response->addJSON('message', Message::rawError($error));
|
||||
$response->callExit();
|
||||
$this->responseRenderer->addJSON('message', Message::rawError($error));
|
||||
$this->responseRenderer->callExit();
|
||||
}
|
||||
|
||||
// If everything fine, START a transaction.
|
||||
$dbi->query('START TRANSACTION');
|
||||
$this->dbi->query('START TRANSACTION');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1019,8 +1018,7 @@ class Import
|
||||
. '.' . Util::backquote($table) . ' '
|
||||
. 'LIMIT 1';
|
||||
|
||||
$dbi = DatabaseInterface::getInstance();
|
||||
$result = $dbi->tryQuery($checkTableQuery);
|
||||
$result = $this->dbi->tryQuery($checkTableQuery);
|
||||
|
||||
if (! $result) {
|
||||
return false;
|
||||
@ -1040,23 +1038,21 @@ class Import
|
||||
|
||||
// Query to check if table is 'Transactional'.
|
||||
$checkQuery = 'SELECT `ENGINE` FROM `information_schema`.`tables` '
|
||||
. 'WHERE `table_name` = ' . $dbi->quoteString($table) . ' '
|
||||
. 'AND `table_schema` = ' . $dbi->quoteString($db) . ' '
|
||||
. 'WHERE `table_name` = ' . $this->dbi->quoteString($table) . ' '
|
||||
. 'AND `table_schema` = ' . $this->dbi->quoteString($db) . ' '
|
||||
. 'AND UPPER(`engine`) IN ("'
|
||||
. implode('", "', $transactionalEngines)
|
||||
. '")';
|
||||
|
||||
$result = $dbi->tryQuery($checkQuery);
|
||||
$result = $this->dbi->tryQuery($checkQuery);
|
||||
|
||||
return $result && $result->numRows() === 1;
|
||||
}
|
||||
|
||||
/** @return string[] */
|
||||
public static function getCompressions(): array
|
||||
public static function getCompressions(Config $config): array
|
||||
{
|
||||
$compressions = [];
|
||||
|
||||
$config = Config::getInstance();
|
||||
if ($config->config->GZipDump && function_exists('gzopen')) {
|
||||
$compressions[] = 'gzip';
|
||||
}
|
||||
@ -1073,7 +1069,7 @@ class Import
|
||||
}
|
||||
|
||||
/** @param ImportPlugin[] $importList List of plugin instances. */
|
||||
public static function getLocalFiles(array $importList): false|string
|
||||
public static function getLocalFiles(Config $config, array $importList): false|string
|
||||
{
|
||||
$fileListing = new FileListing();
|
||||
|
||||
@ -1093,7 +1089,7 @@ class Import
|
||||
: '';
|
||||
|
||||
return $fileListing->getFileSelectOptions(
|
||||
Util::userDir(Config::getInstance()->config->UploadDir),
|
||||
Util::userDir($config->config->UploadDir),
|
||||
$matcher,
|
||||
$active,
|
||||
);
|
||||
@ -1109,7 +1105,7 @@ class Import
|
||||
$importFileName = (string) preg_replace('/[^\x{0001}-\x{FFFF}]/u', '_', $importFileName);
|
||||
|
||||
if ($databaseName !== '') {
|
||||
$existingTables = DatabaseInterface::getInstance()->getTables($databaseName);
|
||||
$existingTables = $this->dbi->getTables($databaseName);
|
||||
|
||||
// check to see if {filename} as table exist
|
||||
// if no use filename as table name
|
||||
@ -1144,7 +1140,7 @@ class Import
|
||||
}
|
||||
|
||||
/** @param ImportTable[] $tables */
|
||||
private function getHtmlListForAllTables(array $tables, string $dbName, DatabaseInterface $dbi): string
|
||||
private function getHtmlListForAllTables(array $tables, string $dbName): string
|
||||
{
|
||||
$message = '<ul>';
|
||||
|
||||
@ -1154,7 +1150,7 @@ class Import
|
||||
$tblStructUrl = Url::getFromRoute('/table/structure', $params);
|
||||
$tblOpsUrl = Url::getFromRoute('/table/operations', $params);
|
||||
|
||||
$tableObj = new Table($table->tableName, $dbName, $dbi);
|
||||
$tableObj = new Table($table->tableName, $dbName, $this->dbi);
|
||||
if (! $tableObj->isView()) {
|
||||
$message .= sprintf(
|
||||
'<li><a href="%s" title="%s">%s</a> (<a href="%s" title="%s">' . __(
|
||||
@ -1202,7 +1198,7 @@ class Import
|
||||
}
|
||||
|
||||
/** @param ImportTable[] $tables */
|
||||
private function getSuccessMessage(string $dbName, array $tables, DatabaseInterface $dbi): string
|
||||
private function getSuccessMessage(string $dbName, array $tables): string
|
||||
{
|
||||
$dbUrl = Url::getFromRoute('/database/structure', ['db' => $dbName]);
|
||||
$dbOperationsUrl = Url::getFromRoute('/database/operations', ['db' => $dbName]);
|
||||
@ -1231,7 +1227,7 @@ class Import
|
||||
),
|
||||
);
|
||||
|
||||
$message .= $this->getHtmlListForAllTables($tables, $dbName, $dbi);
|
||||
$message .= $this->getHtmlListForAllTables($tables, $dbName);
|
||||
|
||||
return $message;
|
||||
}
|
||||
|
||||
@ -9,6 +9,7 @@ namespace PhpMyAdmin\Plugins\Import;
|
||||
|
||||
use PhpMyAdmin\Config;
|
||||
use PhpMyAdmin\Current;
|
||||
use PhpMyAdmin\Dbal\DatabaseInterface;
|
||||
use PhpMyAdmin\File;
|
||||
use PhpMyAdmin\Gis\GisFactory;
|
||||
use PhpMyAdmin\Gis\GisMultiLineString;
|
||||
@ -23,6 +24,7 @@ use PhpMyAdmin\Import\ImportTable;
|
||||
use PhpMyAdmin\Message;
|
||||
use PhpMyAdmin\Plugins\ImportPlugin;
|
||||
use PhpMyAdmin\Properties\Plugins\ImportPluginProperties;
|
||||
use PhpMyAdmin\ResponseRenderer;
|
||||
use PhpMyAdmin\Sanitize;
|
||||
use PhpMyAdmin\ShapeFile\ShapeType;
|
||||
use PhpMyAdmin\ZipExtension;
|
||||
@ -315,7 +317,11 @@ class ImportShp extends ImportPlugin
|
||||
*/
|
||||
public static function readFromBuffer(int $length): string
|
||||
{
|
||||
$import = new Import();
|
||||
$import = new Import(
|
||||
DatabaseInterface::getInstance(),
|
||||
ResponseRenderer::getInstance(),
|
||||
Config::getInstance(),
|
||||
);
|
||||
|
||||
if (strlen(self::$buffer) < $length) {
|
||||
if (ImportSettings::$finished) {
|
||||
|
||||
@ -7,11 +7,14 @@ declare(strict_types=1);
|
||||
|
||||
namespace PhpMyAdmin\Plugins;
|
||||
|
||||
use PhpMyAdmin\Config;
|
||||
use PhpMyAdmin\Dbal\DatabaseInterface;
|
||||
use PhpMyAdmin\File;
|
||||
use PhpMyAdmin\Http\ServerRequest;
|
||||
use PhpMyAdmin\Import\Import;
|
||||
use PhpMyAdmin\Properties\Plugins\ImportPluginProperties;
|
||||
use PhpMyAdmin\Properties\Plugins\PluginPropertyItem;
|
||||
use PhpMyAdmin\ResponseRenderer;
|
||||
|
||||
/**
|
||||
* Provides a common interface that will have to be implemented by all of the
|
||||
@ -28,7 +31,11 @@ abstract class ImportPlugin implements Plugin
|
||||
|
||||
final public function __construct()
|
||||
{
|
||||
$this->import = new Import();
|
||||
$this->import = new Import(
|
||||
DatabaseInterface::getInstance(),
|
||||
ResponseRenderer::getInstance(),
|
||||
Config::getInstance(),
|
||||
);
|
||||
$this->init();
|
||||
$this->properties = $this->setProperties();
|
||||
}
|
||||
|
||||
@ -100,7 +100,7 @@ class ImportControllerTest extends AbstractTestCase
|
||||
|
||||
$importController = new ImportController(
|
||||
$responseRenderer,
|
||||
new Import(),
|
||||
new Import($this->dbi, $responseRenderer, $config),
|
||||
$sql,
|
||||
$this->dbi,
|
||||
$bookmarkRepository,
|
||||
|
||||
@ -4,8 +4,8 @@ declare(strict_types=1);
|
||||
|
||||
namespace PhpMyAdmin\Tests\Import;
|
||||
|
||||
use PhpMyAdmin\Config;
|
||||
use PhpMyAdmin\Current;
|
||||
use PhpMyAdmin\Dbal\DatabaseInterface;
|
||||
use PhpMyAdmin\Import\AnalysedColumn;
|
||||
use PhpMyAdmin\Import\ColumnType;
|
||||
use PhpMyAdmin\Import\DecimalSize;
|
||||
@ -13,6 +13,7 @@ use PhpMyAdmin\Import\Import;
|
||||
use PhpMyAdmin\Import\ImportSettings;
|
||||
use PhpMyAdmin\Import\ImportTable;
|
||||
use PhpMyAdmin\Tests\AbstractTestCase;
|
||||
use PhpMyAdmin\Tests\Stubs\ResponseRenderer;
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
|
||||
@ -35,14 +36,13 @@ final class ImportTest extends AbstractTestCase
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
DatabaseInterface::$instance = $this->createDatabaseInterface();
|
||||
Current::$completeQuery = null;
|
||||
Current::$displayQuery = null;
|
||||
ImportSettings::$skipQueries = 0;
|
||||
ImportSettings::$maxSqlLength = 0;
|
||||
ImportSettings::$sqlQueryDisabled = false;
|
||||
ImportSettings::$executedQueries = 0;
|
||||
$this->import = new Import();
|
||||
$this->import = new Import($this->createDatabaseInterface(), new ResponseRenderer(), new Config());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -363,7 +363,7 @@ final class ImportTest extends AbstractTestCase
|
||||
#[DataProvider('providerForTestAnalyzeTable')]
|
||||
public function testAnalyzeTable(array $columns, array $rows, array $expected): void
|
||||
{
|
||||
$import = new Import();
|
||||
$import = new Import($this->createDatabaseInterface(), new ResponseRenderer(), new Config());
|
||||
self::assertEquals(
|
||||
array_map(static fn (array $column): AnalysedColumn => new AnalysedColumn(...$column), $expected),
|
||||
$import->analyzeTable(new ImportTable('test_table', $columns, $rows)),
|
||||
|
||||
@ -19,10 +19,8 @@ use function __;
|
||||
|
||||
#[CoversClass(ImportCsv::class)]
|
||||
#[Medium]
|
||||
class ImportCsvTest extends AbstractTestCase
|
||||
final class ImportCsvTest extends AbstractTestCase
|
||||
{
|
||||
protected ImportCsv $object;
|
||||
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
@ -53,39 +51,16 @@ class ImportCsvTest extends AbstractTestCase
|
||||
ImportSettings::$importFileName = 'db_test';
|
||||
ImportSettings::$readMultiply = 10;
|
||||
ImportSettings::$sqlQueryDisabled = false;
|
||||
|
||||
$this->object = new ImportCsv();
|
||||
|
||||
$request = ServerRequestFactory::create()->createServerRequest('POST', 'http://example.com/')
|
||||
->withParsedBody([
|
||||
'csv_terminated' => "\015",
|
||||
'csv_enclosed' => '"',
|
||||
'csv_escaped' => '"',
|
||||
'csv_new_line' => 'auto',
|
||||
'csv_columns' => null,
|
||||
]);
|
||||
$this->object->setImportOptions($request);
|
||||
|
||||
Import::$importText = 'ImportCsv_Test';
|
||||
}
|
||||
|
||||
/**
|
||||
* Tears down the fixture, for example, closes a network connection.
|
||||
* This method is called after a test is executed.
|
||||
*/
|
||||
protected function tearDown(): void
|
||||
{
|
||||
parent::tearDown();
|
||||
|
||||
unset($this->object);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for getProperties
|
||||
*/
|
||||
public function testGetProperties(): void
|
||||
{
|
||||
$properties = $this->object->getProperties();
|
||||
$importCsv = new ImportCsv();
|
||||
$properties = $importCsv->getProperties();
|
||||
self::assertSame(
|
||||
__('CSV'),
|
||||
$properties->getText(),
|
||||
@ -108,8 +83,19 @@ class ImportCsvTest extends AbstractTestCase
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
//Test function called
|
||||
$this->object->doImport($importHandle);
|
||||
$importCsv = new ImportCsv();
|
||||
|
||||
$request = ServerRequestFactory::create()->createServerRequest('POST', 'http://example.com/')
|
||||
->withParsedBody([
|
||||
'csv_terminated' => "\015",
|
||||
'csv_enclosed' => '"',
|
||||
'csv_escaped' => '"',
|
||||
'csv_new_line' => 'auto',
|
||||
'csv_columns' => null,
|
||||
]);
|
||||
$importCsv->setImportOptions($request);
|
||||
|
||||
$importCsv->doImport($importHandle);
|
||||
|
||||
//asset that all sql are executed
|
||||
self::assertStringContainsString(
|
||||
@ -132,6 +118,12 @@ class ImportCsvTest extends AbstractTestCase
|
||||
$importHandle = new File(ImportSettings::$importFile);
|
||||
$importHandle->open();
|
||||
|
||||
DatabaseInterface::$instance = $this->getMockBuilder(DatabaseInterface::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$importCsv = new ImportCsv();
|
||||
|
||||
$request = ServerRequestFactory::create()->createServerRequest('POST', 'http://example.com/')
|
||||
->withParsedBody([
|
||||
'csv_terminated' => ',',
|
||||
@ -142,14 +134,10 @@ class ImportCsvTest extends AbstractTestCase
|
||||
'csv_new_tbl_name' => 'ImportTestTable',
|
||||
'csv_new_db_name' => 'ImportTestDb',
|
||||
]);
|
||||
$this->object->setImportOptions($request);
|
||||
|
||||
DatabaseInterface::$instance = $this->getMockBuilder(DatabaseInterface::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$importCsv->setImportOptions($request);
|
||||
|
||||
//Test function called
|
||||
$this->object->doImport($importHandle);
|
||||
$importCsv->doImport($importHandle);
|
||||
|
||||
//asset that all sql are executed
|
||||
self::assertStringContainsString(
|
||||
@ -169,7 +157,8 @@ class ImportCsvTest extends AbstractTestCase
|
||||
*/
|
||||
public function testGetPropertiesForTable(): void
|
||||
{
|
||||
$properties = $this->object->getProperties();
|
||||
$importCsv = new ImportCsv();
|
||||
$properties = $importCsv->getProperties();
|
||||
self::assertSame(
|
||||
__('CSV'),
|
||||
$properties->getText(),
|
||||
@ -192,8 +181,19 @@ class ImportCsvTest extends AbstractTestCase
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
//Test function called
|
||||
$this->object->doImport($importHandle);
|
||||
$importCsv = new ImportCsv();
|
||||
|
||||
$request = ServerRequestFactory::create()->createServerRequest('POST', 'http://example.com/')
|
||||
->withParsedBody([
|
||||
'csv_terminated' => "\015",
|
||||
'csv_enclosed' => '"',
|
||||
'csv_escaped' => '"',
|
||||
'csv_new_line' => 'auto',
|
||||
'csv_columns' => null,
|
||||
]);
|
||||
$importCsv->setImportOptions($request);
|
||||
|
||||
$importCsv->doImport($importHandle);
|
||||
|
||||
//asset that all sql are executed
|
||||
self::assertStringContainsString(
|
||||
@ -217,6 +217,12 @@ class ImportCsvTest extends AbstractTestCase
|
||||
ImportSettings::$importFile = 'none';
|
||||
Import::$importText = '"Row 1","Row 2"' . "\n" . '"123","456"';
|
||||
|
||||
$dummyDbi = $this->createDbiDummy();
|
||||
$dbi = $this->createDatabaseInterface($dummyDbi);
|
||||
DatabaseInterface::$instance = $dbi;
|
||||
|
||||
$importCsv = new ImportCsv();
|
||||
|
||||
$request = ServerRequestFactory::create()->createServerRequest('POST', 'http://example.com/')
|
||||
->withParsedBody([
|
||||
'csv_terminated' => ',',
|
||||
@ -225,11 +231,7 @@ class ImportCsvTest extends AbstractTestCase
|
||||
'csv_new_line' => 'auto',
|
||||
'csv_columns' => null,
|
||||
]);
|
||||
$this->object->setImportOptions($request);
|
||||
|
||||
$dummyDbi = $this->createDbiDummy();
|
||||
$dbi = $this->createDatabaseInterface($dummyDbi);
|
||||
DatabaseInterface::$instance = $dbi;
|
||||
$importCsv->setImportOptions($request);
|
||||
|
||||
$dummyDbi->addResult(
|
||||
'SHOW DATABASES',
|
||||
@ -242,7 +244,7 @@ class ImportCsvTest extends AbstractTestCase
|
||||
[],
|
||||
);
|
||||
|
||||
$this->object->doImport();
|
||||
$importCsv->doImport();
|
||||
|
||||
self::assertSame(
|
||||
'CREATE DATABASE IF NOT EXISTS `CSV_DB 1` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;'
|
||||
@ -264,6 +266,12 @@ class ImportCsvTest extends AbstractTestCase
|
||||
ImportSettings::$importFile = 'none';
|
||||
Import::$importText = '"Row 1","Row 2"' . "\n" . '"123","456"';
|
||||
|
||||
$dummyDbi = $this->createDbiDummy();
|
||||
$dbi = $this->createDatabaseInterface($dummyDbi);
|
||||
DatabaseInterface::$instance = $dbi;
|
||||
|
||||
$importCsv = new ImportCsv();
|
||||
|
||||
$request = ServerRequestFactory::create()->createServerRequest('POST', 'http://example.com/')
|
||||
->withParsedBody([
|
||||
'csv_terminated' => ',',
|
||||
@ -273,11 +281,7 @@ class ImportCsvTest extends AbstractTestCase
|
||||
'csv_columns' => null,
|
||||
'csv_col_names' => 'yes',
|
||||
]);
|
||||
$this->object->setImportOptions($request);
|
||||
|
||||
$dummyDbi = $this->createDbiDummy();
|
||||
$dbi = $this->createDatabaseInterface($dummyDbi);
|
||||
DatabaseInterface::$instance = $dbi;
|
||||
$importCsv->setImportOptions($request);
|
||||
|
||||
$dummyDbi->addResult(
|
||||
'SHOW DATABASES',
|
||||
@ -290,7 +294,7 @@ class ImportCsvTest extends AbstractTestCase
|
||||
[],
|
||||
);
|
||||
|
||||
$this->object->doImport();
|
||||
$importCsv->doImport();
|
||||
|
||||
self::assertSame(
|
||||
'CREATE DATABASE IF NOT EXISTS `CSV_DB 1` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;'
|
||||
@ -314,6 +318,12 @@ class ImportCsvTest extends AbstractTestCase
|
||||
ImportSettings::$importFile = 'none';
|
||||
Import::$importText = '"Row 1","Row 2"' . "\n" . '"123","456"';
|
||||
|
||||
$dummyDbi = $this->createDbiDummy();
|
||||
$dbi = $this->createDatabaseInterface($dummyDbi);
|
||||
DatabaseInterface::$instance = $dbi;
|
||||
|
||||
$importCsv = new ImportCsv();
|
||||
|
||||
$request = ServerRequestFactory::create()->createServerRequest('POST', 'http://example.com/')
|
||||
->withParsedBody([
|
||||
'csv_terminated' => ',',
|
||||
@ -325,11 +335,7 @@ class ImportCsvTest extends AbstractTestCase
|
||||
'csv_col_names' => 'yes',
|
||||
'csv_new_tbl_name' => 'already_uploaded_file',
|
||||
]);
|
||||
$this->object->setImportOptions($request);
|
||||
|
||||
$dummyDbi = $this->createDbiDummy();
|
||||
$dbi = $this->createDatabaseInterface($dummyDbi);
|
||||
DatabaseInterface::$instance = $dbi;
|
||||
$importCsv->setImportOptions($request);
|
||||
|
||||
$dummyDbi->addResult(
|
||||
'SHOW DATABASES',
|
||||
@ -342,7 +348,7 @@ class ImportCsvTest extends AbstractTestCase
|
||||
[],
|
||||
);
|
||||
|
||||
$this->object->doImport();
|
||||
$importCsv->doImport();
|
||||
|
||||
self::assertSame(
|
||||
'CREATE TABLE IF NOT EXISTS `public`.`already_uploaded_file` (`Row 1` int(3), `Row 2` int(3));'
|
||||
|
||||
@ -18,10 +18,8 @@ use function __;
|
||||
|
||||
#[CoversClass(ImportMediawiki::class)]
|
||||
#[Medium]
|
||||
class ImportMediawikiTest extends AbstractTestCase
|
||||
final class ImportMediawikiTest extends AbstractTestCase
|
||||
{
|
||||
protected ImportMediawiki $object;
|
||||
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
@ -49,19 +47,6 @@ class ImportMediawikiTest extends AbstractTestCase
|
||||
ImportSettings::$importFile = 'tests/test_data/phpmyadmin.mediawiki';
|
||||
Import::$importText = 'ImportMediawiki_Test';
|
||||
ImportSettings::$readMultiply = 10;
|
||||
|
||||
$this->object = new ImportMediawiki();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tears down the fixture, for example, closes a network connection.
|
||||
* This method is called after a test is executed.
|
||||
*/
|
||||
protected function tearDown(): void
|
||||
{
|
||||
parent::tearDown();
|
||||
|
||||
unset($this->object);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -69,7 +54,8 @@ class ImportMediawikiTest extends AbstractTestCase
|
||||
*/
|
||||
public function testGetProperties(): void
|
||||
{
|
||||
$properties = $this->object->getProperties();
|
||||
$importMediawiki = new ImportMediawiki();
|
||||
$properties = $importMediawiki->getProperties();
|
||||
self::assertSame(
|
||||
__('MediaWiki Table'),
|
||||
$properties->getText(),
|
||||
@ -102,8 +88,10 @@ class ImportMediawikiTest extends AbstractTestCase
|
||||
$importHandle = new File(ImportSettings::$importFile);
|
||||
$importHandle->open();
|
||||
|
||||
$importMediawiki = new ImportMediawiki();
|
||||
|
||||
//Test function called
|
||||
$this->object->doImport($importHandle);
|
||||
$importMediawiki->doImport($importHandle);
|
||||
|
||||
// If import successfully, PMA will show all databases and
|
||||
// tables imported as following HTML Page
|
||||
@ -140,8 +128,10 @@ class ImportMediawikiTest extends AbstractTestCase
|
||||
$importHandle = new File('tests/test_data/__slashes.mediawiki');
|
||||
$importHandle->open();
|
||||
|
||||
$importMediawiki = new ImportMediawiki();
|
||||
|
||||
//Test function called
|
||||
$this->object->doImport($importHandle);
|
||||
$importMediawiki->doImport($importHandle);
|
||||
|
||||
// If import successfully, PMA will show all databases and
|
||||
// tables imported as following HTML Page
|
||||
|
||||
@ -24,10 +24,8 @@ use function str_repeat;
|
||||
#[CoversClass(ImportOds::class)]
|
||||
#[RequiresPhpExtension('zip')]
|
||||
#[Medium]
|
||||
class ImportOdsTest extends AbstractTestCase
|
||||
final class ImportOdsTest extends AbstractTestCase
|
||||
{
|
||||
protected ImportOds $object;
|
||||
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
@ -52,27 +50,6 @@ class ImportOdsTest extends AbstractTestCase
|
||||
ImportSettings::$offset = 0;
|
||||
Config::getInstance()->selectedServer['DisableIS'] = false;
|
||||
ImportSettings::$readMultiply = 10;
|
||||
|
||||
$this->object = new ImportOds();
|
||||
|
||||
//variable for Ods
|
||||
$request = ServerRequestFactory::create()->createServerRequest('POST', 'http://example.com/')
|
||||
->withParsedBody([
|
||||
'ods_recognize_percentages' => 'yes',
|
||||
'ods_recognize_currency' => 'yes',
|
||||
]);
|
||||
$this->object->setImportOptions($request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tears down the fixture, for example, closes a network connection.
|
||||
* This method is called after a test is executed.
|
||||
*/
|
||||
protected function tearDown(): void
|
||||
{
|
||||
parent::tearDown();
|
||||
|
||||
unset($this->object);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -80,7 +57,8 @@ class ImportOdsTest extends AbstractTestCase
|
||||
*/
|
||||
public function testGetProperties(): void
|
||||
{
|
||||
$properties = $this->object->getProperties();
|
||||
$importOds = new ImportOds();
|
||||
$properties = $importOds->getProperties();
|
||||
self::assertSame(
|
||||
__('OpenDocument Spreadsheet'),
|
||||
$properties->getText(),
|
||||
@ -104,21 +82,23 @@ class ImportOdsTest extends AbstractTestCase
|
||||
|
||||
ImportSettings::$importFile = 'tests/test_data/db_test.ods';
|
||||
|
||||
DatabaseInterface::$instance = $this->createDatabaseInterface();
|
||||
|
||||
$importOds = new ImportOds();
|
||||
|
||||
$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();
|
||||
$importOds->setImportOptions($request);
|
||||
|
||||
$importHandle = new File(ImportSettings::$importFile);
|
||||
$importHandle->setDecompressContent(true);
|
||||
$importHandle->open();
|
||||
|
||||
$this->object->doImport($importHandle);
|
||||
$importOds->doImport($importHandle);
|
||||
|
||||
self::assertStringContainsString(
|
||||
'CREATE DATABASE IF NOT EXISTS `ODS_DB` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci',
|
||||
@ -163,6 +143,11 @@ class ImportOdsTest extends AbstractTestCase
|
||||
ImportSettings::$sqlQueryDisabled = false; //will show the import SQL detail
|
||||
|
||||
ImportSettings::$importFile = 'tests/test_data/import-slim.ods.xml';
|
||||
|
||||
DatabaseInterface::$instance = $this->createDatabaseInterface();
|
||||
|
||||
$importOds = new ImportOds();
|
||||
|
||||
$request = ServerRequestFactory::create()->createServerRequest('POST', 'http://example.com/')
|
||||
->withParsedBody([
|
||||
'ods_recognize_percentages' => 'yes',
|
||||
@ -170,9 +155,7 @@ class ImportOdsTest extends AbstractTestCase
|
||||
'ods_col_names' => 'yes',
|
||||
'ods_empty_rows' => $odsEmptyRowsMode,
|
||||
]);
|
||||
$this->object->setImportOptions($request);
|
||||
|
||||
DatabaseInterface::$instance = $this->createDatabaseInterface();
|
||||
$importOds->setImportOptions($request);
|
||||
|
||||
$importHandle = new File(ImportSettings::$importFile);
|
||||
$importHandle->setDecompressContent(false);// Not compressed
|
||||
@ -188,7 +171,7 @@ class ImportOdsTest extends AbstractTestCase
|
||||
$endOfSql = '),' . "\n" . ' (' . $fullCols . '),' . "\n" . ' (' . $fullCols . ');';
|
||||
}
|
||||
|
||||
$this->object->doImport($importHandle);
|
||||
$importOds->doImport($importHandle);
|
||||
|
||||
self::assertSame(
|
||||
'CREATE DATABASE IF NOT EXISTS `ODS_DB` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;'
|
||||
|
||||
@ -21,10 +21,8 @@ use function __;
|
||||
#[RequiresPhpExtension('xml')]
|
||||
#[RequiresPhpExtension('xmlwriter')]
|
||||
#[Medium]
|
||||
class ImportXmlTest extends AbstractTestCase
|
||||
final class ImportXmlTest extends AbstractTestCase
|
||||
{
|
||||
protected ImportXml $object;
|
||||
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
@ -51,19 +49,6 @@ class ImportXmlTest extends AbstractTestCase
|
||||
ImportSettings::$importFile = 'tests/test_data/phpmyadmin_importXML_For_Testing.xml';
|
||||
Import::$importText = 'ImportXml_Test';
|
||||
ImportSettings::$readMultiply = 10;
|
||||
|
||||
$this->object = new ImportXml();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tears down the fixture, for example, closes a network connection.
|
||||
* This method is called after a test is executed.
|
||||
*/
|
||||
protected function tearDown(): void
|
||||
{
|
||||
parent::tearDown();
|
||||
|
||||
unset($this->object);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -71,7 +56,8 @@ class ImportXmlTest extends AbstractTestCase
|
||||
*/
|
||||
public function testGetProperties(): void
|
||||
{
|
||||
$properties = $this->object->getProperties();
|
||||
$importXml = new ImportXml();
|
||||
$properties = $importXml->getProperties();
|
||||
self::assertSame(
|
||||
__('XML'),
|
||||
$properties->getText(),
|
||||
@ -105,7 +91,8 @@ class ImportXmlTest extends AbstractTestCase
|
||||
$importHandle = new File(ImportSettings::$importFile);
|
||||
$importHandle->open();
|
||||
|
||||
$this->object->doImport($importHandle);
|
||||
$importXml = new ImportXml();
|
||||
$importXml->doImport($importHandle);
|
||||
|
||||
// If import successfully, PMA will show all databases and tables
|
||||
// imported as following HTML Page
|
||||
|
||||
Loading…
Reference in New Issue
Block a user