Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/phpmyadmin/phpmyadmin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/classes/ExportTest.php181
1 files changed, 158 insertions, 23 deletions
diff --git a/test/classes/ExportTest.php b/test/classes/ExportTest.php
index 45ad69ef5b..5f2f714302 100644
--- a/test/classes/ExportTest.php
+++ b/test/classes/ExportTest.php
@@ -7,7 +7,11 @@ namespace PhpMyAdmin\Tests;
use PhpMyAdmin\ConfigStorage\Relation;
use PhpMyAdmin\Export;
use PhpMyAdmin\Plugins\Export\ExportPhparray;
+use PhpMyAdmin\Plugins\Export\ExportSql;
use PhpMyAdmin\Transformations;
+use stdClass;
+
+use function htmlspecialchars;
/**
* @covers \PhpMyAdmin\Export
@@ -15,24 +19,10 @@ use PhpMyAdmin\Transformations;
*/
class ExportTest extends AbstractTestCase
{
- /** @var Export */
- private $export;
-
- /**
- * Sets up the fixture
- */
- protected function setUp(): void
- {
- parent::setUp();
- $GLOBALS['dbi'] = $this->createDatabaseInterface();
- $this->export = new Export($GLOBALS['dbi']);
- }
-
- /**
- * Test for mergeAliases
- */
public function testMergeAliases(): void
{
+ $GLOBALS['dbi'] = $this->createDatabaseInterface();
+ $export = new Export($GLOBALS['dbi']);
$aliases1 = [
'test_db' => [
'alias' => 'aliastest',
@@ -91,31 +81,30 @@ class ExportTest extends AbstractTestCase
],
],
];
- $actual = $this->export->mergeAliases($aliases1, $aliases2);
+ $actual = $export->mergeAliases($aliases1, $aliases2);
$this->assertEquals($expected, $actual);
}
- /**
- * Test for getFinalFilenameAndMimetypeForFilename
- */
public function testGetFinalFilenameAndMimetypeForFilename(): void
{
+ $GLOBALS['dbi'] = $this->createDatabaseInterface();
+ $export = new Export($GLOBALS['dbi']);
$exportPlugin = new ExportPhparray(
new Relation($GLOBALS['dbi']),
new Export($GLOBALS['dbi']),
new Transformations()
);
- $finalFileName = $this->export->getFinalFilenameAndMimetypeForFilename($exportPlugin, 'zip', 'myfilename');
+ $finalFileName = $export->getFinalFilenameAndMimetypeForFilename($exportPlugin, 'zip', 'myfilename');
$this->assertSame([
'myfilename.php.zip',
'application/zip',
], $finalFileName);
- $finalFileName = $this->export->getFinalFilenameAndMimetypeForFilename($exportPlugin, 'gzip', 'myfilename');
+ $finalFileName = $export->getFinalFilenameAndMimetypeForFilename($exportPlugin, 'gzip', 'myfilename');
$this->assertSame([
'myfilename.php.gz',
'application/x-gzip',
], $finalFileName);
- $finalFileName = $this->export->getFinalFilenameAndMimetypeForFilename(
+ $finalFileName = $export->getFinalFilenameAndMimetypeForFilename(
$exportPlugin,
'gzip',
'export.db1.table1.file'
@@ -125,4 +114,150 @@ class ExportTest extends AbstractTestCase
'application/x-gzip',
], $finalFileName);
}
+
+ public function testExportDatabase(): void
+ {
+ $GLOBALS['plugin_param'] = ['export_type' => 'database', 'single_table' => false];
+ $GLOBALS['sql_create_view'] = 'something';
+ $GLOBALS['output_kanji_conversion'] = false;
+ $GLOBALS['buffer_needed'] = false;
+ $GLOBALS['asfile'] = false;
+ $GLOBALS['sql_structure_or_data'] = 'structure_and_data';
+ $GLOBALS['cfg']['Server']['DisableIS'] = false;
+ $GLOBALS['sql_insert_syntax'] = 'both';
+ $GLOBALS['sql_max_query_size'] = '50000';
+
+ // phpcs:disable Generic.Files.LineLength.TooLong
+ $dbiDummy = $this->createDbiDummy();
+ $dbiDummy->addResult(
+ 'SELECT TABLE_NAME FROM information_schema.VIEWS WHERE TABLE_SCHEMA = \'test_db\' AND TABLE_NAME = \'test_table\'',
+ [],
+ ['TABLE_NAME']
+ );
+ $dbiDummy->addResult(
+ 'SELECT *, `TABLE_SCHEMA` AS `Db`, `TABLE_NAME` AS `Name`, `TABLE_TYPE` AS `TABLE_TYPE`, `ENGINE` AS `Engine`, `ENGINE` AS `Type`, `VERSION` AS `Version`, `ROW_FORMAT` AS `Row_format`, `TABLE_ROWS` AS `Rows`, `AVG_ROW_LENGTH` AS `Avg_row_length`, `DATA_LENGTH` AS `Data_length`, `MAX_DATA_LENGTH` AS `Max_data_length`, `INDEX_LENGTH` AS `Index_length`, `DATA_FREE` AS `Data_free`, `AUTO_INCREMENT` AS `Auto_increment`, `CREATE_TIME` AS `Create_time`, `UPDATE_TIME` AS `Update_time`, `CHECK_TIME` AS `Check_time`, `TABLE_COLLATION` AS `Collation`, `CHECKSUM` AS `Checksum`, `CREATE_OPTIONS` AS `Create_options`, `TABLE_COMMENT` AS `Comment` FROM `information_schema`.`TABLES` t WHERE `TABLE_SCHEMA` IN (\'test_db\') AND t.`TABLE_NAME` = \'test_table\' ORDER BY Name ASC',
+ [['def', 'test_db', 'test_table', 'BASE TABLE', 'InnoDB', '10', 'Dynamic', '3', '5461', '16384', '0', '0', '0', '4', '2011-12-13 14:15:16', null, null, 'utf8mb4_general_ci', null, '', '', '0', 'N', 'test_db', 'test_table', 'BASE TABLE', 'InnoDB', 'InnoDB', '10', 'Dynamic', '3', '5461', '16384', '0', '0', '0', '4', '2011-12-13 14:15:16', null, null, 'utf8mb4_general_ci', null, '', '']],
+ ['TABLE_CATALOG', 'TABLE_SCHEMA', 'TABLE_NAME', 'TABLE_TYPE', 'ENGINE', 'VERSION', 'ROW_FORMAT', 'TABLE_ROWS', 'AVG_ROW_LENGTH', 'DATA_LENGTH', 'MAX_DATA_LENGTH', 'INDEX_LENGTH', 'DATA_FREE', 'AUTO_INCREMENT', 'CREATE_TIME', 'UPDATE_TIME', 'CHECK_TIME', 'TABLE_COLLATION', 'CHECKSUM', 'CREATE_OPTIONS', 'TABLE_COMMENT', 'MAX_INDEX_LENGTH', 'TEMPORARY', 'Db', 'Name', 'TABLE_TYPE', 'Engine', 'Type', 'Version', 'Row_format', 'Rows', 'Avg_row_length', 'Data_length', 'Max_data_length', 'Index_length', 'Data_free', 'Auto_increment', 'Create_time', 'Update_time', 'Check_time', 'Collation', 'Checksum', 'Create_options', 'Comment']
+ );
+ $dbiDummy->addResult(
+ 'SELECT `id`, `name`, `datetimefield` FROM `test_db`.`test_table`',
+ [
+ ['1', 'abcd', '2011-01-20 02:00:02'],
+ ['2', 'foo', '2010-01-20 02:00:02'],
+ ['3', 'Abcd', '2012-01-20 02:00:02'],
+ ],
+ ['id', 'name', 'datetimefield']
+ );
+ // phpcs:enable
+
+ $dbi = $this->createDatabaseInterface($dbiDummy);
+ $GLOBALS['dbi'] = $dbi;
+ $export = new Export($dbi);
+
+ $export->exportDatabase(
+ 'test_db',
+ ['test_table'],
+ 'structure_and_data',
+ ['test_table'],
+ ['test_table'],
+ new ExportSql(new Relation($dbi), $export, new Transformations()),
+ "\n",
+ 'index.php?route=/database/export&db=test_db',
+ 'database',
+ false,
+ true,
+ false,
+ false,
+ [],
+ ''
+ );
+
+ $expected = <<<SQL
+
+INSERT INTO test_table (id, name, datetimefield) VALUES
+('1', 'abcd', '2011-01-20 02:00:02'),
+('2', 'foo', '2010-01-20 02:00:02'),
+('3', 'Abcd', '2012-01-20 02:00:02');
+
+SQL;
+
+ $this->assertSame(htmlspecialchars($expected), $this->getActualOutputForAssertion());
+ }
+
+ public function testExportServer(): void
+ {
+ $GLOBALS['plugin_param'] = ['export_type' => 'server', 'single_table' => false];
+ $GLOBALS['dblist'] = new stdClass();
+ $GLOBALS['dblist']->databases = ['test_db'];
+ $GLOBALS['output_kanji_conversion'] = false;
+ $GLOBALS['buffer_needed'] = false;
+ $GLOBALS['asfile'] = false;
+ $GLOBALS['cfg']['Server']['DisableIS'] = false;
+ $GLOBALS['sql_structure_or_data'] = 'structure_and_data';
+ $GLOBALS['sql_insert_syntax'] = 'both';
+ $GLOBALS['sql_max_query_size'] = '50000';
+
+ // phpcs:disable Generic.Files.LineLength.TooLong
+ $dbiDummy = $this->createDbiDummy();
+ $dbiDummy->addResult(
+ 'SHOW TABLES FROM `test_db`;',
+ [['test_table']],
+ ['Tables_in_test_db']
+ );
+ $dbiDummy->addResult(
+ 'SELECT DEFAULT_COLLATION_NAME FROM information_schema.SCHEMATA WHERE SCHEMA_NAME = \'test_db\' LIMIT 1',
+ [['utf8mb4_general_ci']],
+ ['DEFAULT_COLLATION_NAME']
+ );
+ $dbiDummy->addResult(
+ 'SELECT TABLE_NAME FROM information_schema.VIEWS WHERE TABLE_SCHEMA = \'test_db\' AND TABLE_NAME = \'test_table\'',
+ [],
+ ['TABLE_NAME']
+ );
+ $dbiDummy->addResult(
+ 'SELECT *, `TABLE_SCHEMA` AS `Db`, `TABLE_NAME` AS `Name`, `TABLE_TYPE` AS `TABLE_TYPE`, `ENGINE` AS `Engine`, `ENGINE` AS `Type`, `VERSION` AS `Version`, `ROW_FORMAT` AS `Row_format`, `TABLE_ROWS` AS `Rows`, `AVG_ROW_LENGTH` AS `Avg_row_length`, `DATA_LENGTH` AS `Data_length`, `MAX_DATA_LENGTH` AS `Max_data_length`, `INDEX_LENGTH` AS `Index_length`, `DATA_FREE` AS `Data_free`, `AUTO_INCREMENT` AS `Auto_increment`, `CREATE_TIME` AS `Create_time`, `UPDATE_TIME` AS `Update_time`, `CHECK_TIME` AS `Check_time`, `TABLE_COLLATION` AS `Collation`, `CHECKSUM` AS `Checksum`, `CREATE_OPTIONS` AS `Create_options`, `TABLE_COMMENT` AS `Comment` FROM `information_schema`.`TABLES` t WHERE `TABLE_SCHEMA` IN (\'test_db\') AND t.`TABLE_NAME` = \'test_table\' ORDER BY Name ASC',
+ [['def', 'test_db', 'test_table', 'BASE TABLE', 'InnoDB', '10', 'Dynamic', '3', '5461', '16384', '0', '0', '0', '4', '2011-12-13 14:15:16', null, null, 'utf8mb4_general_ci', null, '', '', '0', 'N', 'test_db', 'test_table', 'BASE TABLE', 'InnoDB', 'InnoDB', '10', 'Dynamic', '3', '5461', '16384', '0', '0', '0', '4', '2011-12-13 14:15:16', null, null, 'utf8mb4_general_ci', null, '', '']],
+ ['TABLE_CATALOG', 'TABLE_SCHEMA', 'TABLE_NAME', 'TABLE_TYPE', 'ENGINE', 'VERSION', 'ROW_FORMAT', 'TABLE_ROWS', 'AVG_ROW_LENGTH', 'DATA_LENGTH', 'MAX_DATA_LENGTH', 'INDEX_LENGTH', 'DATA_FREE', 'AUTO_INCREMENT', 'CREATE_TIME', 'UPDATE_TIME', 'CHECK_TIME', 'TABLE_COLLATION', 'CHECKSUM', 'CREATE_OPTIONS', 'TABLE_COMMENT', 'MAX_INDEX_LENGTH', 'TEMPORARY', 'Db', 'Name', 'TABLE_TYPE', 'Engine', 'Type', 'Version', 'Row_format', 'Rows', 'Avg_row_length', 'Data_length', 'Max_data_length', 'Index_length', 'Data_free', 'Auto_increment', 'Create_time', 'Update_time', 'Check_time', 'Collation', 'Checksum', 'Create_options', 'Comment']
+ );
+ $dbiDummy->addResult(
+ 'SELECT `id`, `name`, `datetimefield` FROM `test_db`.`test_table`',
+ [
+ ['1', 'abcd', '2011-01-20 02:00:02'],
+ ['2', 'foo', '2010-01-20 02:00:02'],
+ ['3', 'Abcd', '2012-01-20 02:00:02'],
+ ],
+ ['id', 'name', 'datetimefield']
+ );
+ // phpcs:enable
+
+ $dbi = $this->createDatabaseInterface($dbiDummy);
+ $GLOBALS['dbi'] = $dbi;
+ $export = new Export($dbi);
+
+ $export->exportServer(
+ ['test_db'],
+ 'structure_and_data',
+ new ExportSql(new Relation($dbi), $export, new Transformations()),
+ "\n",
+ 'index.php?route=/server/export',
+ 'server',
+ false,
+ true,
+ false,
+ false,
+ [],
+ ''
+ );
+
+ $expected = <<<SQL
+CREATE DATABASE IF NOT EXISTS test_db DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;USE test_db;
+INSERT INTO test_table (id, name, datetimefield) VALUES
+('1', 'abcd', '2011-01-20 02:00:02'),
+('2', 'foo', '2010-01-20 02:00:02'),
+('3', 'Abcd', '2012-01-20 02:00:02');
+
+SQL;
+
+ $this->assertSame(htmlspecialchars($expected), $this->getActualOutputForAssertion());
+ }
}