Initial commit
This commit is contained in:
202
#pma/test/classes/plugin/import/ImportCsvTest.php
Normal file
202
#pma/test/classes/plugin/import/ImportCsvTest.php
Normal file
@ -0,0 +1,202 @@
|
||||
<?php
|
||||
/**
|
||||
* Tests for PMA\libraries\plugins\import\ImportCsv class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
|
||||
/*
|
||||
* we must set $GLOBALS['server'] here
|
||||
* since 'check_user_privileges.lib.php' will use it globally
|
||||
*/
|
||||
use PMA\libraries\plugins\import\ImportCsv;
|
||||
use PMA\libraries\Theme;
|
||||
|
||||
$GLOBALS['server'] = 0;
|
||||
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
require_once 'libraries/url_generating.lib.php';
|
||||
require_once 'libraries/database_interface.inc.php';
|
||||
require_once 'libraries/import.lib.php';
|
||||
require_once 'libraries/sanitizing.lib.php';
|
||||
require_once 'test/PMATestCase.php';
|
||||
|
||||
/**
|
||||
* Tests for PMA\libraries\plugins\import\ImportCsv class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class ImportCsvTest extends PMATestCase
|
||||
{
|
||||
/**
|
||||
* @var ImportCsv
|
||||
* @access protected
|
||||
*/
|
||||
protected $object;
|
||||
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*
|
||||
* @access protected
|
||||
* @return void
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
$GLOBALS['plugin_param'] = "csv";
|
||||
$this->object = new ImportCsv();
|
||||
|
||||
unset($GLOBALS['db']);
|
||||
|
||||
//setting
|
||||
$GLOBALS['finished'] = false;
|
||||
$GLOBALS['read_limit'] = 100000000;
|
||||
$GLOBALS['offset'] = 0;
|
||||
$GLOBALS['cfg']['Server']['DisableIS'] = false;
|
||||
|
||||
$GLOBALS['import_file'] = 'test/test_data/db_test.csv';
|
||||
$GLOBALS['import_text'] = 'ImportCsv_Test';
|
||||
$GLOBALS['compression'] = 'none';
|
||||
$GLOBALS['read_multiply'] = 10;
|
||||
$GLOBALS['import_type'] = 'Xml';
|
||||
$GLOBALS['pmaThemeImage'] = 'image';
|
||||
$GLOBALS['import_handle'] = @fopen($GLOBALS['import_file'], 'r');
|
||||
|
||||
//separator for csv
|
||||
$GLOBALS['csv_terminated'] = "\015";
|
||||
$GLOBALS['csv_enclosed'] = '"';
|
||||
$GLOBALS['csv_escaped'] = '"';
|
||||
$GLOBALS['csv_new_line'] = 'auto';
|
||||
|
||||
//$_SESSION
|
||||
$_SESSION['PMA_Theme'] = Theme::load('./themes/pmahomme');
|
||||
$_SESSION['PMA_Theme'] = new Theme();
|
||||
|
||||
//Mock DBI
|
||||
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$GLOBALS['dbi'] = $dbi;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tears down the fixture, for example, closes a network connection.
|
||||
* This method is called after a test is executed.
|
||||
*
|
||||
* @access protected
|
||||
* @return void
|
||||
*/
|
||||
protected function tearDown()
|
||||
{
|
||||
unset($this->object);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for getProperties
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @group medium
|
||||
*/
|
||||
public function testGetProperties()
|
||||
{
|
||||
$properties = $this->object->getProperties();
|
||||
$this->assertEquals(
|
||||
__('CSV'),
|
||||
$properties->getText()
|
||||
);
|
||||
$this->assertEquals(
|
||||
'csv',
|
||||
$properties->getExtension()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for doImport
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @group medium
|
||||
*/
|
||||
public function testDoImport()
|
||||
{
|
||||
//$sql_query_disabled will show the import SQL detail
|
||||
global $sql_query, $sql_query_disabled;
|
||||
$sql_query_disabled = false;
|
||||
|
||||
//Test function called
|
||||
$this->object->doImport();
|
||||
|
||||
//asset that all sql are executed
|
||||
$this->assertContains(
|
||||
'CREATE DATABASE IF NOT EXISTS `CSV_DB` DEFAULT CHARACTER',
|
||||
$sql_query
|
||||
);
|
||||
$this->assertContains(
|
||||
'CREATE TABLE IF NOT EXISTS `CSV_DB`.`TBL_NAME`',
|
||||
$sql_query
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
true,
|
||||
$GLOBALS['finished']
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for getProperties for Table param
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @group medium
|
||||
*/
|
||||
public function testGetPropertiesForTable()
|
||||
{
|
||||
$GLOBALS['plugin_param'] = 'table';
|
||||
$this->object = new ImportCsv();
|
||||
$properties = $this->object->getProperties();
|
||||
$this->assertEquals(
|
||||
__('CSV'),
|
||||
$properties->getText()
|
||||
);
|
||||
$this->assertEquals(
|
||||
'csv',
|
||||
$properties->getExtension()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for doImport for _getAnalyze = false, should be OK as well
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @group medium
|
||||
*/
|
||||
public function testDoImportNotAnalysis()
|
||||
{
|
||||
//$sql_query_disabled will show the import SQL detail
|
||||
global $sql_query, $sql_query_disabled;
|
||||
$sql_query_disabled = false;
|
||||
|
||||
//Test function called
|
||||
$this->object->doImport();
|
||||
|
||||
//asset that all sql are executed
|
||||
$this->assertContains(
|
||||
'CREATE DATABASE IF NOT EXISTS `CSV_DB` DEFAULT CHARACTER',
|
||||
$sql_query
|
||||
);
|
||||
|
||||
$this->assertContains(
|
||||
'CREATE TABLE IF NOT EXISTS `CSV_DB`.`TBL_NAME`',
|
||||
$sql_query
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
true,
|
||||
$GLOBALS['finished']
|
||||
);
|
||||
}
|
||||
}
|
266
#pma/test/classes/plugin/import/ImportLdiTest.php
Normal file
266
#pma/test/classes/plugin/import/ImportLdiTest.php
Normal file
@ -0,0 +1,266 @@
|
||||
<?php
|
||||
/**
|
||||
* Tests for PMA\libraries\plugins\import\ImportLdi class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
|
||||
/*
|
||||
* we must set $GLOBALS['server'] here
|
||||
* since 'check_user_privileges.lib.php' will use it globally
|
||||
*/
|
||||
use PMA\libraries\plugins\import\ImportLdi;
|
||||
|
||||
$GLOBALS['server'] = 0;
|
||||
$GLOBALS['plugin_param'] = "table";
|
||||
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
require_once 'libraries/sanitizing.lib.php';
|
||||
require_once 'libraries/url_generating.lib.php';
|
||||
require_once 'libraries/database_interface.inc.php';
|
||||
require_once 'libraries/import.lib.php';
|
||||
require_once 'test/PMATestCase.php';
|
||||
|
||||
/**
|
||||
* Tests for PMA\libraries\plugins\import\ImportLdi class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class ImportLdiTest extends PMATestCase
|
||||
{
|
||||
/**
|
||||
* @access protected
|
||||
*/
|
||||
protected $object;
|
||||
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*
|
||||
* @access protected
|
||||
* @return void
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
//setting
|
||||
$GLOBALS['finished'] = false;
|
||||
$GLOBALS['read_limit'] = 100000000;
|
||||
$GLOBALS['offset'] = 0;
|
||||
$GLOBALS['cfg']['Server']['DisableIS'] = false;
|
||||
|
||||
$GLOBALS['import_file'] = 'test/test_data/db_test_ldi.csv';
|
||||
$GLOBALS['import_text'] = 'ImportLdi_Test';
|
||||
$GLOBALS['compression'] = 'none';
|
||||
$GLOBALS['read_multiply'] = 10;
|
||||
$GLOBALS['import_type'] = 'csv';
|
||||
$GLOBALS['import_handle'] = @fopen($GLOBALS['import_file'], 'r');
|
||||
|
||||
//setting for Ldi
|
||||
$GLOBALS['cfg']['Import']['ldi_replace'] = false;
|
||||
$GLOBALS['cfg']['Import']['ldi_ignore'] = false;
|
||||
$GLOBALS['cfg']['Import']['ldi_terminated'] = ';';
|
||||
$GLOBALS['cfg']['Import']['ldi_enclosed'] = '"';
|
||||
$GLOBALS['cfg']['Import']['ldi_escaped'] = '\\';
|
||||
$GLOBALS['cfg']['Import']['ldi_new_line'] = 'auto';
|
||||
$GLOBALS['cfg']['Import']['ldi_columns'] = '';
|
||||
$GLOBALS['cfg']['Import']['ldi_local_option'] = false;
|
||||
$GLOBALS['table'] = "phpmyadmintest";
|
||||
|
||||
//Mock DBI
|
||||
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$dbi->expects($this->any())->method('tryQuery')
|
||||
->will($this->returnValue(true));
|
||||
|
||||
$dbi->expects($this->any())->method('numRows')
|
||||
->will($this->returnValue(10));
|
||||
|
||||
$fetchRowResult = array("ON");
|
||||
$dbi->expects($this->any())->method('fetchRow')
|
||||
->will($this->returnValue($fetchRowResult));
|
||||
|
||||
$dbi->expects($this->any())->method('escapeString')
|
||||
->will($this->returnArgument(0));
|
||||
|
||||
$GLOBALS['dbi'] = $dbi;
|
||||
|
||||
$this->object = new ImportLdi();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tears down the fixture, for example, closes a network connection.
|
||||
* This method is called after a test is executed.
|
||||
*
|
||||
* @access protected
|
||||
* @return void
|
||||
*/
|
||||
protected function tearDown()
|
||||
{
|
||||
unset($this->object);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for getProperties
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @group medium
|
||||
*/
|
||||
public function testGetProperties()
|
||||
{
|
||||
$properties = $this->object->getProperties();
|
||||
$this->assertEquals(
|
||||
__('CSV using LOAD DATA'),
|
||||
$properties->getText()
|
||||
);
|
||||
$this->assertEquals(
|
||||
'ldi',
|
||||
$properties->getExtension()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for getProperties for ldi_local_option = auto
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @group medium
|
||||
*/
|
||||
public function testGetPropertiesAutoLdi()
|
||||
{
|
||||
$GLOBALS['cfg']['Import']['ldi_local_option'] = 'auto';
|
||||
$this->object = new ImportLdi();
|
||||
$properties = $this->object->getProperties();
|
||||
$this->assertEquals(
|
||||
true,
|
||||
$GLOBALS['cfg']['Import']['ldi_local_option']
|
||||
);
|
||||
$this->assertEquals(
|
||||
__('CSV using LOAD DATA'),
|
||||
$properties->getText()
|
||||
);
|
||||
$this->assertEquals(
|
||||
'ldi',
|
||||
$properties->getExtension()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for doImport
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @group medium
|
||||
*/
|
||||
public function testDoImport()
|
||||
{
|
||||
//$sql_query_disabled will show the import SQL detail
|
||||
global $sql_query, $sql_query_disabled;
|
||||
$sql_query_disabled = false;
|
||||
|
||||
//Test function called
|
||||
$this->object->doImport();
|
||||
|
||||
//asset that all sql are executed
|
||||
$this->assertContains(
|
||||
"LOAD DATA INFILE 'test/test_data/db_test_ldi.csv' INTO TABLE "
|
||||
. "`phpmyadmintest`",
|
||||
$sql_query
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
true,
|
||||
$GLOBALS['finished']
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for doImport : invalid import file
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @group medium
|
||||
*/
|
||||
public function testDoImportInvalidFile()
|
||||
{
|
||||
global $import_file;
|
||||
$import_file = 'none';
|
||||
|
||||
//Test function called
|
||||
$this->object->doImport();
|
||||
|
||||
// We handle only some kind of data!
|
||||
$this->assertContains(
|
||||
__('This plugin does not support compressed imports!'),
|
||||
$GLOBALS['message']->__toString()
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
true,
|
||||
$GLOBALS['error']
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for doImport with LDI setting
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @group medium
|
||||
*/
|
||||
public function testDoImportLDISetting()
|
||||
{
|
||||
global $ldi_local_option, $ldi_replace, $ldi_ignore, $ldi_terminated,
|
||||
$ldi_enclosed, $ldi_new_line, $skip_queries;
|
||||
|
||||
//$sql_query_disabled will show the import SQL detail
|
||||
global $sql_query, $sql_query_disabled;
|
||||
$sql_query_disabled = false;
|
||||
|
||||
$ldi_local_option = true;
|
||||
$ldi_replace = true;
|
||||
$ldi_ignore = true;
|
||||
$ldi_terminated = ',';
|
||||
$ldi_enclosed = ')';
|
||||
$ldi_new_line = 'newline_mark';
|
||||
$skip_queries = true;
|
||||
|
||||
//Test function called
|
||||
$this->object->doImport();
|
||||
|
||||
//asset that all sql are executed
|
||||
//replace
|
||||
$this->assertContains(
|
||||
"LOAD DATA LOCAL INFILE 'test/test_data/db_test_ldi.csv' REPLACE INTO "
|
||||
. "TABLE `phpmyadmintest`",
|
||||
$sql_query
|
||||
);
|
||||
|
||||
//FIELDS TERMINATED
|
||||
$this->assertContains(
|
||||
"FIELDS TERMINATED BY ','",
|
||||
$sql_query
|
||||
);
|
||||
|
||||
//LINES TERMINATED
|
||||
$this->assertContains(
|
||||
"LINES TERMINATED BY 'newline_mark'",
|
||||
$sql_query
|
||||
);
|
||||
|
||||
//IGNORE
|
||||
$this->assertContains(
|
||||
"IGNORE 1 LINES",
|
||||
$sql_query
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
true,
|
||||
$GLOBALS['finished']
|
||||
);
|
||||
}
|
||||
}
|
167
#pma/test/classes/plugin/import/ImportMediawikiTest.php
Normal file
167
#pma/test/classes/plugin/import/ImportMediawikiTest.php
Normal file
@ -0,0 +1,167 @@
|
||||
<?php
|
||||
/**
|
||||
* Tests for PMA\libraries\plugins\import\ImportMediawiki class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
/*
|
||||
* we must set $GLOBALS['server'] here
|
||||
* since 'check_user_privileges.lib.php' will use it globally
|
||||
*/
|
||||
use PMA\libraries\plugins\import\ImportMediawiki;
|
||||
|
||||
$GLOBALS['server'] = 0;
|
||||
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
require_once 'libraries/url_generating.lib.php';
|
||||
require_once 'libraries/database_interface.inc.php';
|
||||
require_once 'libraries/import.lib.php';
|
||||
require_once 'test/PMATestCase.php';
|
||||
|
||||
/**
|
||||
* Tests for PMA\libraries\plugins\import\ImportMediawiki class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class ImportMediawikiTest extends PMATestCase
|
||||
{
|
||||
/**
|
||||
* @access protected
|
||||
*/
|
||||
protected $object;
|
||||
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*
|
||||
* @access protected
|
||||
* @return void
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
$GLOBALS['plugin_param'] = 'database';
|
||||
$this->object = new ImportMediawiki();
|
||||
|
||||
//setting
|
||||
$GLOBALS['finished'] = false;
|
||||
$GLOBALS['read_limit'] = 100000000;
|
||||
$GLOBALS['offset'] = 0;
|
||||
$GLOBALS['cfg']['Server']['DisableIS'] = false;
|
||||
|
||||
$GLOBALS['import_file'] = 'test/test_data/phpmyadmin.mediawiki';
|
||||
$GLOBALS['import_text'] = 'ImportMediawiki_Test';
|
||||
$GLOBALS['compression'] = 'none';
|
||||
$GLOBALS['read_multiply'] = 10;
|
||||
$GLOBALS['import_type'] = 'Mediawiki';
|
||||
$GLOBALS['import_handle'] = @fopen($GLOBALS['import_file'], 'r');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tears down the fixture, for example, closes a network connection.
|
||||
* This method is called after a test is executed.
|
||||
*
|
||||
* @access protected
|
||||
* @return void
|
||||
*/
|
||||
protected function tearDown()
|
||||
{
|
||||
unset($this->object);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for getProperties
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @group medium
|
||||
*/
|
||||
public function testGetProperties()
|
||||
{
|
||||
$properties = $this->object->getProperties();
|
||||
$this->assertEquals(
|
||||
__('MediaWiki Table'),
|
||||
$properties->getText()
|
||||
);
|
||||
$this->assertEquals(
|
||||
'txt',
|
||||
$properties->getExtension()
|
||||
);
|
||||
$this->assertEquals(
|
||||
'text/plain',
|
||||
$properties->getMimeType()
|
||||
);
|
||||
$this->assertEquals(
|
||||
array(),
|
||||
$properties->getOptions()
|
||||
);
|
||||
$this->assertEquals(
|
||||
__('Options'),
|
||||
$properties->getOptionsText()
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for doImport
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @group medium
|
||||
*/
|
||||
public function testDoImport()
|
||||
{
|
||||
//$import_notice will show the import detail result
|
||||
global $import_notice;
|
||||
|
||||
//Mock DBI
|
||||
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$GLOBALS['dbi'] = $dbi;
|
||||
|
||||
//Test function called
|
||||
$this->object->doImport();
|
||||
|
||||
// If import successfully, PMA will show all databases and
|
||||
// tables imported as following HTML Page
|
||||
/*
|
||||
The following structures have either been created or altered. Here you
|
||||
can:
|
||||
View a structure's contents by clicking on its name
|
||||
Change any of its settings by clicking the corresponding "Options" link
|
||||
Edit structure by following the "Structure" link
|
||||
|
||||
mediawiki_DB (Options)
|
||||
pma_bookmarktest (Structure) (Options)
|
||||
*/
|
||||
|
||||
//asset that all databases and tables are imported
|
||||
$this->assertContains(
|
||||
'The following structures have either been created or altered.',
|
||||
$import_notice
|
||||
);
|
||||
$this->assertContains(
|
||||
'Go to database: `mediawiki_DB`',
|
||||
$import_notice
|
||||
);
|
||||
$this->assertContains(
|
||||
'Edit settings for `mediawiki_DB`',
|
||||
$import_notice
|
||||
);
|
||||
$this->assertContains(
|
||||
'Go to table: `pma_bookmarktest`',
|
||||
$import_notice
|
||||
);
|
||||
$this->assertContains(
|
||||
'Edit settings for `pma_bookmarktest`',
|
||||
$import_notice
|
||||
);
|
||||
$this->assertEquals(
|
||||
true,
|
||||
$GLOBALS['finished']
|
||||
);
|
||||
|
||||
}
|
||||
}
|
179
#pma/test/classes/plugin/import/ImportOdsTest.php
Normal file
179
#pma/test/classes/plugin/import/ImportOdsTest.php
Normal file
@ -0,0 +1,179 @@
|
||||
<?php
|
||||
/**
|
||||
* Tests for PMA\libraries\plugins\import\ImportOds class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
|
||||
/*
|
||||
* we must set $GLOBALS['server'] here
|
||||
* since 'check_user_privileges.lib.php' will use it globally
|
||||
*/
|
||||
use PMA\libraries\plugins\import\ImportOds;
|
||||
|
||||
$GLOBALS['server'] = 0;
|
||||
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
require_once 'libraries/url_generating.lib.php';
|
||||
require_once 'libraries/database_interface.inc.php';
|
||||
require_once 'libraries/import.lib.php';
|
||||
require_once 'libraries/sanitizing.lib.php';
|
||||
require_once 'libraries/plugins/import/ImportOds.php';
|
||||
require_once 'test/PMATestCase.php';
|
||||
|
||||
/**
|
||||
* Tests for PMA\libraries\plugins\import\ImportOds class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class ImportOdsTest extends PMATestCase
|
||||
{
|
||||
/**
|
||||
* @access protected
|
||||
*/
|
||||
protected $object;
|
||||
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*
|
||||
* @access protected
|
||||
* @return void
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
$GLOBALS['plugin_param'] = "csv";
|
||||
$this->object = new ImportOds();
|
||||
|
||||
//setting
|
||||
$GLOBALS['finished'] = false;
|
||||
$GLOBALS['read_limit'] = 100000000;
|
||||
$GLOBALS['offset'] = 0;
|
||||
$GLOBALS['cfg']['Server']['DisableIS'] = false;
|
||||
|
||||
$GLOBALS['import_file'] = 'test/test_data/db_test.ods';
|
||||
|
||||
/**
|
||||
* Load interface for zip extension.
|
||||
*/
|
||||
include_once 'libraries/zip_extension.lib.php';
|
||||
$result = PMA_getZipContents($GLOBALS['import_file']);
|
||||
$GLOBALS['import_text'] = $result["data"];
|
||||
$GLOBALS['compression'] = 'application/zip';
|
||||
$GLOBALS['read_multiply'] = 10;
|
||||
$GLOBALS['import_type'] = 'ods';
|
||||
$GLOBALS['import_handle'] = @fopen($GLOBALS['import_file'], 'r');
|
||||
|
||||
//variable for Ods
|
||||
$_REQUEST['ods_recognize_percentages'] = true;
|
||||
$_REQUEST['ods_recognize_currency'] = true;
|
||||
$_REQUEST['ods_empty_rows'] = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tears down the fixture, for example, closes a network connection.
|
||||
* This method is called after a test is executed.
|
||||
*
|
||||
* @access protected
|
||||
* @return void
|
||||
*/
|
||||
protected function tearDown()
|
||||
{
|
||||
unset($this->object);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for getProperties
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @group medium
|
||||
*/
|
||||
public function testGetProperties()
|
||||
{
|
||||
$properties = $this->object->getProperties();
|
||||
$this->assertEquals(
|
||||
__('OpenDocument Spreadsheet'),
|
||||
$properties->getText()
|
||||
);
|
||||
$this->assertEquals(
|
||||
'ods',
|
||||
$properties->getExtension()
|
||||
);
|
||||
$this->assertEquals(
|
||||
__('Options'),
|
||||
$properties->getOptionsText()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for doImport
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @group medium
|
||||
*/
|
||||
public function testDoImport()
|
||||
{
|
||||
//$sql_query_disabled will show the import SQL detail
|
||||
//$import_notice will show the import detail result
|
||||
global $import_notice, $sql_query, $sql_query_disabled;
|
||||
$sql_query_disabled = false;
|
||||
|
||||
//Mock DBI
|
||||
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$dbi->expects($this->any())->method('escapeString')
|
||||
->will($this->returnArgument(0));
|
||||
$GLOBALS['dbi'] = $dbi;
|
||||
|
||||
//Test function called
|
||||
$this->object->doImport();
|
||||
|
||||
$this->assertContains(
|
||||
'CREATE DATABASE IF NOT EXISTS `ODS_DB` DEFAULT CHARACTER SET '
|
||||
. 'utf8 COLLATE utf8_general_ci',
|
||||
$sql_query
|
||||
);
|
||||
$this->assertContains(
|
||||
'CREATE TABLE IF NOT EXISTS `ODS_DB`.`pma_bookmark`',
|
||||
$sql_query
|
||||
);
|
||||
$this->assertContains(
|
||||
"INSERT INTO `ODS_DB`.`pma_bookmark` (`A`, `B`, `C`, `D`) VALUES "
|
||||
. "(1, 'dbbase', NULL, 'ddd');",
|
||||
$sql_query
|
||||
);
|
||||
|
||||
//asset that all databases and tables are imported
|
||||
$this->assertContains(
|
||||
'The following structures have either been created or altered.',
|
||||
$import_notice
|
||||
);
|
||||
$this->assertContains(
|
||||
'Go to database: `ODS_DB`',
|
||||
$import_notice
|
||||
);
|
||||
$this->assertContains(
|
||||
'Edit settings for `ODS_DB`',
|
||||
$import_notice
|
||||
);
|
||||
$this->assertContains(
|
||||
'Go to table: `pma_bookmark`',
|
||||
$import_notice
|
||||
);
|
||||
$this->assertContains(
|
||||
'Edit settings for `pma_bookmark`',
|
||||
$import_notice
|
||||
);
|
||||
|
||||
//asset that the import process is finished
|
||||
$this->assertEquals(
|
||||
true,
|
||||
$GLOBALS['finished']
|
||||
);
|
||||
}
|
||||
}
|
227
#pma/test/classes/plugin/import/ImportShpTest.php
Normal file
227
#pma/test/classes/plugin/import/ImportShpTest.php
Normal file
@ -0,0 +1,227 @@
|
||||
<?php
|
||||
/**
|
||||
* Tests for PMA\libraries\plugins\import\ImportShp class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
|
||||
/*
|
||||
* we must set $GLOBALS['server'] here
|
||||
* since 'check_user_privileges.lib.php' will use it globally
|
||||
*/
|
||||
use PMA\libraries\plugins\import\ImportShp;
|
||||
|
||||
$GLOBALS['server'] = 0;
|
||||
|
||||
require_once 'libraries/url_generating.lib.php';
|
||||
require_once 'libraries/database_interface.inc.php';
|
||||
require_once 'libraries/import.lib.php';
|
||||
require_once 'test/PMATestCase.php';
|
||||
|
||||
/**
|
||||
* Tests for PMA\libraries\plugins\import\ImportShp class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class ImportShpTest extends PMATestCase
|
||||
{
|
||||
/**
|
||||
* @var ImportShp
|
||||
* @access protected
|
||||
*/
|
||||
protected $object;
|
||||
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*
|
||||
* @access protected
|
||||
* @return void
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
//setting
|
||||
$GLOBALS['plugin_param'] = 'table';
|
||||
$GLOBALS['finished'] = false;
|
||||
$GLOBALS['read_limit'] = 100000000;
|
||||
$GLOBALS['offset'] = 0;
|
||||
$GLOBALS['cfg']['Server']['DisableIS'] = false;
|
||||
|
||||
//Mock DBI
|
||||
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$GLOBALS['dbi'] = $dbi;
|
||||
|
||||
$this->object = new ImportShp();
|
||||
|
||||
$GLOBALS['compression'] = 'application/zip';
|
||||
$GLOBALS['read_multiply'] = 10;
|
||||
$GLOBALS['import_type'] = 'ods';
|
||||
unset($GLOBALS['db'], $GLOBALS['table']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes import of given file
|
||||
*
|
||||
* @param string $filename Name of test file
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function runImport($filename)
|
||||
{
|
||||
$GLOBALS['import_file'] = $filename;
|
||||
$GLOBALS['import_handle'] = @fopen($filename, 'r');
|
||||
|
||||
$this->object->doImport();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tears down the fixture, for example, closes a network connection.
|
||||
* This method is called after a test is executed.
|
||||
*
|
||||
* @access protected
|
||||
* @return void
|
||||
*/
|
||||
protected function tearDown()
|
||||
{
|
||||
unset($this->object);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for getProperties
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @group medium
|
||||
*/
|
||||
public function testGetProperties()
|
||||
{
|
||||
$properties = $this->object->getProperties();
|
||||
$this->assertEquals(
|
||||
__('ESRI Shape File'),
|
||||
$properties->getText()
|
||||
);
|
||||
$this->assertEquals(
|
||||
'shp',
|
||||
$properties->getExtension()
|
||||
);
|
||||
$this->assertEquals(
|
||||
array(),
|
||||
$properties->getOptions()
|
||||
);
|
||||
$this->assertEquals(
|
||||
__('Options'),
|
||||
$properties->getOptionsText()
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for doImport with complex data
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @group medium
|
||||
*/
|
||||
public function testImportOsm()
|
||||
{
|
||||
//$sql_query_disabled will show the import SQL detail
|
||||
//$import_notice will show the import detail result
|
||||
global $import_notice, $sql_query, $sql_query_disabled;
|
||||
$sql_query_disabled = false;
|
||||
|
||||
//Test function called
|
||||
$this->runImport('test/test_data/dresden_osm.shp.zip');
|
||||
|
||||
$this->assertMessages($import_notice);
|
||||
$this->assertContains(
|
||||
"(GeomFromText('MULTIPOLYGON((("
|
||||
. "13.737122 51.0542065,"
|
||||
. "13.7373039 51.0541298,"
|
||||
. "13.7372661 51.0540944,"
|
||||
. "13.7370842 51.0541711,"
|
||||
. "13.737122 51.0542065)))'))",
|
||||
$sql_query
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for doImport
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @group medium
|
||||
*/
|
||||
public function testDoImport()
|
||||
{
|
||||
//$sql_query_disabled will show the import SQL detail
|
||||
//$import_notice will show the import detail result
|
||||
global $import_notice, $sql_query, $sql_query_disabled;
|
||||
$sql_query_disabled = false;
|
||||
|
||||
//Test function called
|
||||
$this->runImport('test/test_data/timezone.shp.zip');
|
||||
|
||||
//asset that all sql are executed
|
||||
$this->assertContains(
|
||||
'CREATE DATABASE IF NOT EXISTS `SHP_DB` DEFAULT CHARACTER '
|
||||
. 'SET utf8 COLLATE utf8_general_ci',
|
||||
$sql_query
|
||||
);
|
||||
$this->assertContains(
|
||||
'CREATE TABLE IF NOT EXISTS `SHP_DB`.`TBL_NAME` '
|
||||
. '(`SPATIAL` geometry) DEFAULT CHARACTER '
|
||||
. 'SET utf8 COLLATE utf8_general_ci;',
|
||||
$sql_query
|
||||
);
|
||||
$this->assertContains(
|
||||
"INSERT INTO `SHP_DB`.`TBL_NAME` (`SPATIAL`) VALUES",
|
||||
$sql_query
|
||||
);
|
||||
$this->assertContains(
|
||||
"GeomFromText('POINT(1294523.1759236",
|
||||
$sql_query
|
||||
);
|
||||
|
||||
//asset that all databases and tables are imported
|
||||
$this->assertMessages($import_notice);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates import messages
|
||||
*
|
||||
* @param string $import_notice Messages to check
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function assertMessages($import_notice)
|
||||
{
|
||||
$this->assertContains(
|
||||
'The following structures have either been created or altered.',
|
||||
$import_notice
|
||||
);
|
||||
$this->assertContains(
|
||||
'Go to database: `SHP_DB`',
|
||||
$import_notice
|
||||
);
|
||||
$this->assertContains(
|
||||
'Edit settings for `SHP_DB`',
|
||||
$import_notice
|
||||
);
|
||||
$this->assertContains(
|
||||
'Go to table: `TBL_NAME`',
|
||||
$import_notice
|
||||
);
|
||||
$this->assertContains(
|
||||
'Edit settings for `TBL_NAME`',
|
||||
$import_notice
|
||||
);
|
||||
|
||||
//asset that the import process is finished
|
||||
$this->assertEquals(
|
||||
true,
|
||||
$GLOBALS['finished']
|
||||
);
|
||||
}
|
||||
}
|
116
#pma/test/classes/plugin/import/ImportSqlTest.php
Normal file
116
#pma/test/classes/plugin/import/ImportSqlTest.php
Normal file
@ -0,0 +1,116 @@
|
||||
<?php
|
||||
/**
|
||||
* Tests for PMA\libraries\plugins\import\ImportSql class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
|
||||
/*
|
||||
* we must set $GLOBALS['server'] here
|
||||
* since 'check_user_privileges.lib.php' will use it globally
|
||||
*/
|
||||
use PMA\libraries\plugins\import\ImportSql;
|
||||
|
||||
$GLOBALS['server'] = 0;
|
||||
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
require_once 'libraries/url_generating.lib.php';
|
||||
require_once 'libraries/database_interface.inc.php';
|
||||
require_once 'libraries/import.lib.php';
|
||||
require_once 'test/PMATestCase.php';
|
||||
|
||||
/**
|
||||
* Tests for PMA\libraries\plugins\import\ImportSql class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class ImportSqlTest extends PMATestCase
|
||||
{
|
||||
/**
|
||||
* @access protected
|
||||
*/
|
||||
protected $object;
|
||||
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*
|
||||
* @access protected
|
||||
* @return void
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
$this->object = new ImportSql();
|
||||
|
||||
//setting
|
||||
$GLOBALS['finished'] = false;
|
||||
$GLOBALS['read_limit'] = 100000000;
|
||||
$GLOBALS['offset'] = 0;
|
||||
$GLOBALS['cfg']['Server']['DisableIS'] = false;
|
||||
|
||||
$GLOBALS['import_file'] = 'test/test_data/pma_bookmark.sql';
|
||||
$GLOBALS['import_text'] = 'ImportSql_Test';
|
||||
$GLOBALS['compression'] = 'none';
|
||||
$GLOBALS['read_multiply'] = 10;
|
||||
$GLOBALS['import_type'] = 'Xml';
|
||||
$GLOBALS['import_handle'] = @fopen($GLOBALS['import_file'], 'r');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tears down the fixture, for example, closes a network connection.
|
||||
* This method is called after a test is executed.
|
||||
*
|
||||
* @access protected
|
||||
* @return void
|
||||
*/
|
||||
protected function tearDown()
|
||||
{
|
||||
unset($this->object);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for doImport
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @group medium
|
||||
*/
|
||||
public function testDoImport()
|
||||
{
|
||||
//$sql_query_disabled will show the import SQL detail
|
||||
global $sql_query, $sql_query_disabled;
|
||||
$sql_query_disabled = false;
|
||||
|
||||
//Mock DBI
|
||||
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$GLOBALS['dbi'] = $dbi;
|
||||
|
||||
//Test function called
|
||||
$this->object->doImport();
|
||||
|
||||
//asset that all sql are executed
|
||||
$this->assertContains(
|
||||
'SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"',
|
||||
$sql_query
|
||||
);
|
||||
$this->assertContains(
|
||||
'CREATE TABLE IF NOT EXISTS `pma_bookmark`',
|
||||
$sql_query
|
||||
);
|
||||
$this->assertContains(
|
||||
'INSERT INTO `pma_bookmark` (`id`, `dbase`, `user`, `label`, `query`) '
|
||||
. 'VALUES',
|
||||
$sql_query
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
true,
|
||||
$GLOBALS['finished']
|
||||
);
|
||||
|
||||
}
|
||||
}
|
168
#pma/test/classes/plugin/import/ImportXmlTest.php
Normal file
168
#pma/test/classes/plugin/import/ImportXmlTest.php
Normal file
@ -0,0 +1,168 @@
|
||||
<?php
|
||||
/**
|
||||
* Tests for PMA\libraries\plugins\import\ImportXml class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
|
||||
/*
|
||||
* we must set $GLOBALS['server'] here
|
||||
* since 'check_user_privileges.lib.php' will use it globally
|
||||
*/
|
||||
use PMA\libraries\plugins\import\ImportXml;
|
||||
|
||||
$GLOBALS['server'] = 0;
|
||||
|
||||
/*
|
||||
* Include to test.
|
||||
*/
|
||||
require_once 'libraries/url_generating.lib.php';
|
||||
require_once 'libraries/database_interface.inc.php';
|
||||
require_once 'libraries/import.lib.php';
|
||||
require_once 'test/PMATestCase.php';
|
||||
|
||||
/**
|
||||
* Tests for PMA\libraries\plugins\import\ImportXml class
|
||||
*
|
||||
* @package PhpMyAdmin-test
|
||||
*/
|
||||
class ImportXmlTest extends PMATestCase
|
||||
{
|
||||
/**
|
||||
* @access protected
|
||||
*/
|
||||
protected $object;
|
||||
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*
|
||||
* @access protected
|
||||
* @return void
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
$this->object = new ImportXml();
|
||||
|
||||
//setting
|
||||
$GLOBALS['finished'] = false;
|
||||
$GLOBALS['read_limit'] = 100000000;
|
||||
$GLOBALS['offset'] = 0;
|
||||
$GLOBALS['cfg']['Server']['DisableIS'] = false;
|
||||
|
||||
$GLOBALS['import_file'] = 'test/test_data/phpmyadmin_importXML_'
|
||||
. 'For_Testing.xml';
|
||||
$GLOBALS['import_text'] = 'ImportXml_Test';
|
||||
$GLOBALS['compression'] = 'none';
|
||||
$GLOBALS['read_multiply'] = 10;
|
||||
$GLOBALS['import_type'] = 'Xml';
|
||||
$GLOBALS['import_handle'] = @fopen($GLOBALS['import_file'], 'r');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tears down the fixture, for example, closes a network connection.
|
||||
* This method is called after a test is executed.
|
||||
*
|
||||
* @access protected
|
||||
* @return void
|
||||
*/
|
||||
protected function tearDown()
|
||||
{
|
||||
unset($this->object);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for getProperties
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @group medium
|
||||
*/
|
||||
public function testGetProperties()
|
||||
{
|
||||
$properties = $this->object->getProperties();
|
||||
$this->assertEquals(
|
||||
__('XML'),
|
||||
$properties->getText()
|
||||
);
|
||||
$this->assertEquals(
|
||||
'xml',
|
||||
$properties->getExtension()
|
||||
);
|
||||
$this->assertEquals(
|
||||
'text/xml',
|
||||
$properties->getMimeType()
|
||||
);
|
||||
$this->assertEquals(
|
||||
array(),
|
||||
$properties->getOptions()
|
||||
);
|
||||
$this->assertEquals(
|
||||
__('Options'),
|
||||
$properties->getOptionsText()
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for doImport
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @group medium
|
||||
*/
|
||||
public function testDoImport()
|
||||
{
|
||||
//$import_notice will show the import detail result
|
||||
global $import_notice;
|
||||
|
||||
//Mock DBI
|
||||
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$GLOBALS['dbi'] = $dbi;
|
||||
|
||||
//Test function called
|
||||
$this->object->doImport();
|
||||
|
||||
// If import successfully, PMA will show all databases and tables
|
||||
// imported as following HTML Page
|
||||
/*
|
||||
The following structures have either been created or altered. Here you
|
||||
can:
|
||||
View a structure's contents by clicking on its name
|
||||
Change any of its settings by clicking the corresponding "Options" link
|
||||
Edit structure by following the "Structure" link
|
||||
|
||||
phpmyadmintest (Options)
|
||||
pma_bookmarktest (Structure) (Options)
|
||||
*/
|
||||
|
||||
//asset that all databases and tables are imported
|
||||
$this->assertContains(
|
||||
'The following structures have either been created or altered.',
|
||||
$import_notice
|
||||
);
|
||||
$this->assertContains(
|
||||
'Go to database: `phpmyadmintest`',
|
||||
$import_notice
|
||||
);
|
||||
$this->assertContains(
|
||||
'Edit settings for `phpmyadmintest`',
|
||||
$import_notice
|
||||
);
|
||||
$this->assertContains(
|
||||
'Go to table: `pma_bookmarktest`',
|
||||
$import_notice
|
||||
);
|
||||
$this->assertContains(
|
||||
'Edit settings for `pma_bookmarktest`',
|
||||
$import_notice
|
||||
);
|
||||
$this->assertEquals(
|
||||
true,
|
||||
$GLOBALS['finished']
|
||||
);
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user