From 269b38f7a81c3a00bbe013bc09473bd152efe863 Mon Sep 17 00:00:00 2001 From: ayushchd Date: Mon, 26 Aug 2013 21:40:51 +0530 Subject: [PATCH] Tests for server, db and table imports --- test/selenium/PmaSeleniumImportTest.php | 161 ++++++++++++++++++++++++ test/test_data/db_import.sql | 8 ++ test/test_data/server_import.sql | 9 ++ test/test_data/table_import.sql | 9 ++ 4 files changed, 187 insertions(+) create mode 100644 test/selenium/PmaSeleniumImportTest.php create mode 100644 test/test_data/db_import.sql create mode 100644 test/test_data/server_import.sql create mode 100644 test/test_data/table_import.sql diff --git a/test/selenium/PmaSeleniumImportTest.php b/test/selenium/PmaSeleniumImportTest.php new file mode 100644 index 0000000000..17fda3e6a4 --- /dev/null +++ b/test/selenium/PmaSeleniumImportTest.php @@ -0,0 +1,161 @@ +_helper = new Helper($this); + $this->setBrowser($this->_helper->getBrowserString()); + $this->setBrowserUrl(TESTSUITE_PHPMYADMIN_HOST . TESTSUITE_PHPMYADMIN_URL); + $this->_helper->dbConnect(); + $this->_dbname = 'pma_db_' . time(); + } + + /** + * setUp function that can use the selenium session (called before each test) + * + * @return void + */ + public function setUpPage() + { + $this->_helper->login(TESTSUITE_USER, TESTSUITE_PASSWORD); + } + + /** + * Test for server level import + * + * @return void + */ + public function testServerImport() + { + $this->_doImport('server'); + $result = $this->_helper->dbQuery("SHOW DATABASES LIKE 'test_import%'"); + $this->assertGreaterThanOrEqual(2, $result->num_rows); + + // clear db + $this->_helper->dbQuery("DROP DATABASE test_import1"); + $this->_helper->dbQuery("DROP DATABASE test_import2"); + } + + /** + * Test for db level import + * + * @return void + */ + public function testDbImport() + { + $this->_helper->dbQuery("CREATE DATABASE " . $this->_dbname); + $this->byLinkText("Databases")->click(); + $this->_helper->waitForElement("byLinkText", $this->_dbname)->click(); + $this->_helper->waitForElement( + "byXPath", + "//a[@class='item' and contains(., 'Database: ". $this->_dbname ."')]" + ); + + $this->_doImport("db"); + + $this->_helper->dbQuery("USE " . $this->_dbname); + $result = $this->_helper->dbQuery("SHOW TABLES"); + $this->assertEquals(1, $result->num_rows); + } + + /** + * Test for table level import + * + * @return void + */ + public function testTableImport() + { + // setup the db + $this->_helper->dbQuery("CREATE DATABASE " . $this->_dbname); + $this->_helper->dbQuery("USE " . $this->_dbname); + $this->_helper->dbQuery( + "CREATE TABLE IF NOT EXISTS `test_table` (`val` int(11) NOT NULL)" + ); + + // go to database page + $this->byLinkText("Databases")->click(); + $this->_helper->waitForElement("byLinkText", $this->_dbname)->click(); + $this->_helper->waitForElement( + "byXPath", + "//a[@class='item' and contains(., 'Database: ". $this->_dbname ."')]" + ); + + // got to table page + $this->_helper->waitForElement("byLinkText", "test_table")->click(); + $this->_helper->waitForElement( + "byXPath", + "//a[@class='tabactive' and contains(., 'Browse')]" + ); + + $this->_doImport("table"); + + $result = $this->_helper->dbQuery("SELECT * FROM test_table"); + $this->assertEquals(2, $result->num_rows); + } + + /** + * Function that goes to the import page, uploads a file and submit form + * + * @param string $type level: server, db or import + * + * @return void + */ + private function _doImport($type) + { + $this->byLinkText("Import")->click(); + $ele = $this->_helper->waitForElement("byId", "input_import_file"); + $ele->value( + dirname(__FILE__) . "/../test_data/" . $type . "_import.sql" + ); + $this->byId("buttonGo")->click(); + $this->_helper->waitForElement( + "byXPath", + "//div[@class='success' and contains(., 'Import has been successfully')]" + ); + } + + /** + * Tear Down function for test cases + * + * @return void + */ + public function tearDown() + { + $this->_helper->dbQuery('DROP DATABASE IF EXISTS ' . $this->_dbname); + } + +} diff --git a/test/test_data/db_import.sql b/test/test_data/db_import.sql new file mode 100644 index 0000000000..105817a68b --- /dev/null +++ b/test/test_data/db_import.sql @@ -0,0 +1,8 @@ + +-- +-- Table structure for table `test_table` +-- + +CREATE TABLE IF NOT EXISTS `test_table` ( + `val` int(11) NOT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1; diff --git a/test/test_data/server_import.sql b/test/test_data/server_import.sql new file mode 100644 index 0000000000..86f84a921e --- /dev/null +++ b/test/test_data/server_import.sql @@ -0,0 +1,9 @@ +-- +-- Database: `test_import1` +-- +CREATE DATABASE IF NOT EXISTS `test_import1` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci; +-- +-- Database: `test_import1` +-- +CREATE DATABASE IF NOT EXISTS `test_import2` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci; + diff --git a/test/test_data/table_import.sql b/test/test_data/table_import.sql new file mode 100644 index 0000000000..6891eb2ea6 --- /dev/null +++ b/test/test_data/table_import.sql @@ -0,0 +1,9 @@ + +-- +-- Dumping data for table `test_table` +-- + +INSERT INTO `test_table` (`val`) VALUES +(8), +(9); +