diff --git a/test/selenium/PmaSeleniumDbStoredProceduresTest.php b/test/selenium/PmaSeleniumDbProceduresTest.php similarity index 98% rename from test/selenium/PmaSeleniumDbStoredProceduresTest.php rename to test/selenium/PmaSeleniumDbProceduresTest.php index 13363222a7..a7169584c5 100644 --- a/test/selenium/PmaSeleniumDbStoredProceduresTest.php +++ b/test/selenium/PmaSeleniumDbProceduresTest.php @@ -9,12 +9,12 @@ require_once 'Helper.php'; /** - * PmaSeleniumDbStoredProceduresTest class + * PmaSeleniumDbProceduresTest class * * @package PhpMyAdmin-test * @subpackage Selenium */ -class PmaSeleniumDbStoredProceduresTest extends PHPUnit_Extensions_Selenium2TestCase +class PmaSeleniumDbProceduresTest extends PHPUnit_Extensions_Selenium2TestCase { /** * Name of database for the test diff --git a/test/selenium/PmaSeleniumTablesBrowseDataTest.php b/test/selenium/PmaSeleniumTableBrowseTest.php similarity index 98% rename from test/selenium/PmaSeleniumTablesBrowseDataTest.php rename to test/selenium/PmaSeleniumTableBrowseTest.php index ad6c366580..fb89ee2504 100644 --- a/test/selenium/PmaSeleniumTablesBrowseDataTest.php +++ b/test/selenium/PmaSeleniumTableBrowseTest.php @@ -9,12 +9,12 @@ require_once 'Helper.php'; /** - * PmaSeleniumTablesBrowseDataTest class + * PmaSeleniumTableBrowseTest class * * @package PhpMyAdmin-test * @subpackage Selenium */ -class PmaSeleniumTablesBrowseDataTest extends PHPUnit_Extensions_Selenium2TestCase +class PmaSeleniumTableBrowseTest extends PHPUnit_Extensions_Selenium2TestCase { /** * Name of database for the test diff --git a/test/selenium/PmaSeleniumTablesTest.php b/test/selenium/PmaSeleniumTableCreateTest.php similarity index 97% rename from test/selenium/PmaSeleniumTablesTest.php rename to test/selenium/PmaSeleniumTableCreateTest.php index 987c18cb10..d63f487478 100644 --- a/test/selenium/PmaSeleniumTablesTest.php +++ b/test/selenium/PmaSeleniumTableCreateTest.php @@ -9,12 +9,12 @@ require_once 'Helper.php'; /** - * PmaSeleniumTablesTest class + * PmaSeleniumTableCreateTest class * * @package PhpMyAdmin-test * @subpackage Selenium */ -class PmaSeleniumTablesTest extends PHPUnit_Extensions_Selenium2TestCase +class PmaSeleniumTableCreateTest extends PHPUnit_Extensions_Selenium2TestCase { /** * Name of database for the test diff --git a/test/selenium/PmaSeleniumTablesInsertDataTest.php b/test/selenium/PmaSeleniumTableInsertTest.php similarity index 95% rename from test/selenium/PmaSeleniumTablesInsertDataTest.php rename to test/selenium/PmaSeleniumTableInsertTest.php index 079071b3e7..8d3cfd61ea 100644 --- a/test/selenium/PmaSeleniumTablesInsertDataTest.php +++ b/test/selenium/PmaSeleniumTableInsertTest.php @@ -9,12 +9,12 @@ require_once 'Helper.php'; /** - * PmaSeleniumTablesInsertDataTest class + * PmaSeleniumTableInsertTest class * * @package PhpMyAdmin-test * @subpackage Selenium */ -class PmaSeleniumTablesInsertDataTest extends PHPUnit_Extensions_Selenium2TestCase +class PmaSeleniumTableInsertTest extends PHPUnit_Extensions_Selenium2TestCase { /** * Name of database for the test @@ -31,7 +31,8 @@ class PmaSeleniumTablesInsertDataTest extends PHPUnit_Extensions_Selenium2TestCa private $_helper; /** - * Setup the browser environment to run the selenium test case + * Setup the browser environment to run the selenium t + * est case * * @return void */ diff --git a/test/selenium/PmaSeleniumTableOperationsTest.php b/test/selenium/PmaSeleniumTableOperationsTest.php new file mode 100644 index 0000000000..c4753a37e5 --- /dev/null +++ b/test/selenium/PmaSeleniumTableOperationsTest.php @@ -0,0 +1,260 @@ +_helper = new Helper($this); + $this->setBrowser($this->_helper->getBrowserString()); + $this->setBrowserUrl(TESTSUITE_PHPMYADMIN_HOST . TESTSUITE_PHPMYADMIN_URL); + $this->_helper->dbConnect(); + $this->_dbname = 'pma_db_test'; + $this->_helper->dbQuery('CREATE DATABASE ' . $this->_dbname); + $this->_helper->dbQuery('USE ' . $this->_dbname); + $this->_helper->dbQuery( + "CREATE TABLE `test_table` (" + . " `id` int(11) NOT NULL AUTO_INCREMENT," + . " `val` int(11) NOT NULL," + . " `val2` int(11) NOT NULL," + . " PRIMARY KEY (`id`)" + . ")" + ); + $this->_helper->dbQuery("INSERT INTO test_table (val) VALUES (22)"); + $this->_helper->dbQuery("INSERT INTO test_table (val) VALUES (33)"); + } + + /** + * setUp function that can use the selenium session (called before each test) + * + * @return void + */ + public function setUpPage() + { + $this->_helper->login(TESTSUITE_USER, TESTSUITE_PASSWORD); + $this->byLinkText($this->_dbname)->click(); + + $this->_helper->waitForElement( + "byXPath", + "//a[contains(., 'test_table')]" + )->click(); + + $this->_helper->waitForElement("byId", "table_results"); + $more = $this->_helper->waitForElement("byLinkText", "More"); + $this->moveto($more); + $this->byXPath("//a[contains(., 'Operations')]")->click(); + $this->_helper->waitForElement( + "byXPath", + "//legend[contains(., 'Alter table order by')]" + ); + } + + /** + * Test for changing a table order + * + * @return void + */ + public function testChangeTableOrder() + { + $this->select($this->byName("order_field")) + ->selectOptionByLabel("val"); + + $this->byId("order_order_desc")->click(); + $this->byXPath("(//input[@value='Go'])[1]")->click(); + + $this->_helper->waitForElement( + "byXPath", + "//div[@class='success' and " + . "contains(., 'Your SQL query has been executed successfully')]" + ); + + $this->byLinkText("Browse")->click(); + $this->_helper->waitForElement("byId", "table_results"); + + $this->assertEquals( + "2", + $this->_helper->getTable("table_results.1.5") + ); + } + + /** + * Test for moving a table + * + * @return void + */ + public function testMoveTable() + { + $this->byCssSelector("form#moveTableForm input[name='new_name']")->value("2"); + + $this->byXPath("(//input[@value='Go'])[2]")->click(); + + $this->_helper->waitForElement( + "byXPath", + "//div[@class='success' and " + . "contains(., 'Table `" . $this->_dbname . "`.`test_table` has been " + . "moved to `" . $this->_dbname . "`.`test_table2`.')]" + ); + + $result = $this->_helper->dbQuery("SHOW TABLES"); + $row = $result->fetch_assoc(); + $this->assertEquals( + "test_table2", + $row["Tables_in_" . $this->_dbname] + ); + } + + /** + * Test for renaming a table + * + * @return void + */ + public function testRenameTable() + { + $this->byCssSelector("form#tableOptionsForm input[name='new_name']") + ->value("2"); + + $this->byName("comment")->value("foobar"); + + $this->byXPath("(//input[@value='Go'])[3]")->click(); + + $this->_helper->waitForElement( + "byXPath", + "//div[@class='success' and " + . "contains(., 'Table test_table has been renamed to test_table2')]" + ); + + $this->assertNotNull( + $this->_helper->waitForElement( + "byXPath", + "//span[@id='span_table_comment' and contains(., 'foobar')]" + ) + ); + + $result = $this->_helper->dbQuery("SHOW TABLES"); + $row = $result->fetch_assoc(); + $this->assertEquals( + "test_table2", + $row["Tables_in_" . $this->_dbname] + ); + } + + /** + * Test for copying a table + * + * @return void + */ + public function testCopyTable() + { + $this->byCssSelector("form#copyTable input[name='new_name']")->value("2"); + $this->byCssSelector("label[for='what_data']")->click(); + $this->byXPath("(//input[@value='Go'])[4]")->click(); + + $this->_helper->waitForElement( + "byXPath", + "//div[@class='success' and " + . "contains(., 'Table `" . $this->_dbname . "`.`test_table` has been " + . "copied to `" . $this->_dbname . "`.`test_table2`.')]" + ); + + $result = $this->_helper->dbQuery("SELECT COUNT(*) as c FROM test_table2"); + $row = $result->fetch_assoc(); + $this->assertEquals( + 2, + $row["c"] + ); + } + + /** + * Test for truncating a table + * + * @return void + */ + public function testTruncateTable() + { + $this->byId("truncate_tbl_anchor")->click(); + $this->byXPath("//button[contains(., 'OK')]")->click(); + + $this->_helper->waitForElement( + "byXPath", + "//div[@class='success' and " + . "contains(., 'MySQL returned an empty result set')]" + ); + + $result = $this->_helper->dbQuery("SELECT COUNT(*) as c FROM test_table"); + $row = $result->fetch_assoc(); + $this->assertEquals( + 0, + $row["c"] + ); + } + + /** + * Test for dropping a table + * + * @return void + */ + public function testDropTable() + { + $this->byId("drop_tbl_anchor")->click(); + $this->byXPath("//button[contains(., 'OK')]")->click(); + + $this->_helper->waitForElement( + "byXPath", + "//div[@class='success' and " + . "contains(., 'MySQL returned an empty result set')]" + ); + + $this->_helper->waitForElement( + "byXPath", + "//a[@class='tabactive' and contains(., 'Structure')]" + ); + + $result = $this->_helper->dbQuery("SHOW TABLES"); + $this->assertEquals( + 0, + $result->num_rows + ); + } + + /** + * Tear Down function for test cases + * + * @return void + */ + public function tearDown() + { + $this->_helper->dbQuery('DROP DATABASE ' . $this->_dbname); + } +} diff --git a/test/selenium/PmaSeleniumTableStructureTest.php b/test/selenium/PmaSeleniumTableStructureTest.php new file mode 100644 index 0000000000..e8e96db6db --- /dev/null +++ b/test/selenium/PmaSeleniumTableStructureTest.php @@ -0,0 +1,173 @@ +_helper = new Helper($this); + $this->setBrowser($this->_helper->getBrowserString()); + $this->setBrowserUrl(TESTSUITE_PHPMYADMIN_HOST . TESTSUITE_PHPMYADMIN_URL); + $this->_helper->dbConnect(); + $this->_dbname = 'pma_db_test'; + $this->_helper->dbQuery('CREATE DATABASE ' . $this->_dbname); + $this->_helper->dbQuery('USE ' . $this->_dbname); + $this->_helper->dbQuery( + "CREATE TABLE `test_table` (" + . " `id` int(11) NOT NULL AUTO_INCREMENT," + . " `val` int(11) NOT NULL," + . " `val2` int(11) NOT NULL," + . " PRIMARY KEY (`id`)" + . ")" + ); + } + + /** + * setUp function that can use the selenium session (called before each test) + * + * @return void + */ + public function setUpPage() + { + $this->_helper->login(TESTSUITE_USER, TESTSUITE_PASSWORD); + $this->byLinkText($this->_dbname)->click(); + + $this->_helper->waitForElement( + "byXPath", + "(//a[contains(., 'Structure')])[2]" + )->click(); + + $this->_helper->waitForElement("byId", "tablestructure"); + } + + /** + * Test for adding a new column + * + * @return void + */ + public function testAddColumn() + { + $this->byCssSelector("label[for='field_where_after']")->click(); + $this->byCssSelector("input[value='Go']")->click(); + + $this->_helper->waitForElement("byClassName", "append_fields_form"); + + $this->byId("field_0_1")->value('val3'); + $this->byCssSelector("input[name='do_save_data']")->click(); + + $this->_helper->waitForElement( + "byXPath", + "//div[@class='success' and contains(., 'Table test_table has been altered successfully')]" + ); + + $this->byLinkText("Structure")->click(); + $this->_helper->waitForElement("byId", "tablestructure"); + + $this->assertEquals( + "val3", + $this->byCssSelector('label[for=checkbox_row_2]')->text() + ); + + $this->assertEquals( + "int(11)", + $this->_helper->getTable("tablestructure.2.4") + ); + } + + /** + * Test for changing a column + * + * @return void + */ + public function testChangeColumn() + { + $this->byXPath("(//a[contains(., 'Change')])[2]")->click(); + + $this->_helper->waitForElement("byClassName", "append_fields_form"); + + $this->assertEquals("val", $this->byId("field_0_1")->value()); + $this->byId("field_0_1")->clear(); + $this->byId("field_0_1")->value('val3'); + $this->byCssSelector("input[name='do_save_data']")->click(); + + $this->_helper->waitForElement( + "byXPath", + "//div[@class='success' and contains(., 'Table test_table has been altered successfully')]" + ); + + $this->assertEquals( + "val3", + $this->byCssSelector('label[for=checkbox_row_2]')->text() + ); + } + + /** + * Test for dropping columns + * + * @return void + */ + public function testDropColumns() + { + $this->byCssSelector('label[for=checkbox_row_2]')->click(); + $this->byCssSelector('label[for=checkbox_row_3]')->click(); + $this->byXPath("//button[@class='mult_submit' and contains(., 'Drop')]")->click(); + + $this->_helper->waitForElement( + "byCssSelector", "input[id='buttonYes']" + ) + ->click(); + + $this->_helper->waitForElement( + "byXPath", + "//div[@class='success' and contains(., 'Your SQL query has been executed successfully')]" + ); + + $this->assertFalse( + $this->_helper->isElementPresent( + 'byCssSelector', 'label[for=checkbox_row_2]' + ) + ); + } + + /** + * Tear Down function for test cases + * + * @return void + */ + public function tearDown() + { + $this->_helper->dbQuery('DROP DATABASE ' . $this->_dbname); + } +}