diff --git a/test/selenium/Helper.php b/test/selenium/Helper.php index fc985a464d..b234610c9a 100644 --- a/test/selenium/Helper.php +++ b/test/selenium/Helper.php @@ -205,6 +205,14 @@ class Helper return $browserString; } + /** + * Wait for an element to be present on the page + * + * @param string $func Locate using - byCss, byXPath, etc + * @param string $arg Selector + * + * @return PHPUnit_Extensions_Selenium2TestCase_Element Element waited for + */ public function waitForElement($func, $arg) { $this->_selenium->timeouts()->implicitWait(10000); @@ -215,10 +223,17 @@ class Helper return $element; } + /** + * Wait for an element to disappear + * + * @param string $func Locate using - byCss, byXPath, etc + * @param string $arg Selector + * + * @return bool Whether or not the element disappeared + */ public function waitForElementNotPresent($func, $arg) { - while(true) - { + while (true) { if (!$this->isElementPresent($func, $arg)) { return true; } @@ -226,6 +241,14 @@ class Helper } } + /** + * Check if element is present or not + * + * @param string $func Locate using - byCss, byXPath, etc + * @param string $arg Selector + * + * @return bool Whether or not the element is present + */ public function isElementPresent($func, $arg) { try { @@ -240,16 +263,30 @@ class Helper return true; } + /** + * Get table cell data + * + * @param string $identifier Identifier: tableId.row.column + * + * @return text Data from the particular table cell + */ public function getTable($identifier) { list($tableID, $row, $column) = explode(".", $identifier); - $selector = "table#{$tableID} tbody tr:nth-child({$row}) td:nth-child({$column})"; + $sel = "table#{$tableID} tbody tr:nth-child({$row}) td:nth-child({$column})"; $element = $this->_selenium->byCssSelector( - $selector + $sel ); return $element->text(); } + /** + * Type text in textarea (CodeMirror enabled) + * + * @param string $text Text to type + * + * @return void + */ public function typeInTextArea($text) { $text = str_replace( diff --git a/test/selenium/PmaSeleniumDbEventsTest.php b/test/selenium/PmaSeleniumDbEventsTest.php index 90a154d56b..2eec5f23d4 100644 --- a/test/selenium/PmaSeleniumDbEventsTest.php +++ b/test/selenium/PmaSeleniumDbEventsTest.php @@ -125,7 +125,8 @@ class PmaSeleniumDbEventsTest extends PHPUnit_Extensions_Selenium2TestCase $ele = $this->_helper->waitForElement( "byXPath", - "//div[@class='success' and contains(., 'Event `test_event` has been created')]" + "//div[@class='success' and contains(., " + . "'Event `test_event` has been created')]" ); $this->assertTrue( @@ -177,7 +178,8 @@ class PmaSeleniumDbEventsTest extends PHPUnit_Extensions_Selenium2TestCase $ele = $this->_helper->waitForElement( "byXPath", - "//div[@class='success' and contains(., 'Event `test_event` has been modified')]" + "//div[@class='success' and contains(., " + . "'Event `test_event` has been modified')]" ); usleep(2000000); @@ -209,7 +211,7 @@ class PmaSeleniumDbEventsTest extends PHPUnit_Extensions_Selenium2TestCase $this->byLinkText("Drop")->click(); $this->_helper->waitForElement( "byXPath", "//button[contains(., 'OK')]" - )->click(); + )->click(); $this->_helper->waitForElement("byId", "nothing2display"); diff --git a/test/selenium/PmaSeleniumDbOperationsTest.php b/test/selenium/PmaSeleniumDbOperationsTest.php index 285e7aba71..898e9782ba 100644 --- a/test/selenium/PmaSeleniumDbOperationsTest.php +++ b/test/selenium/PmaSeleniumDbOperationsTest.php @@ -93,7 +93,7 @@ class PmaSeleniumDbOperationsTest extends PHPUnit_Extensions_Selenium2TestCase $this->_helper->waitForElement( "byXPath", "//button[contains(., 'OK')]" - )->click(); + )->click(); $this->_helper->waitForElement( "byXPath", diff --git a/test/selenium/PmaSeleniumDbProceduresTest.php b/test/selenium/PmaSeleniumDbProceduresTest.php index 8e63ca2c2d..d8dc1dbcd8 100644 --- a/test/selenium/PmaSeleniumDbProceduresTest.php +++ b/test/selenium/PmaSeleniumDbProceduresTest.php @@ -102,14 +102,14 @@ class PmaSeleniumDbProceduresTest extends PHPUnit_Extensions_Selenium2TestCase $this->byName("item_param_name[0]")->value("inp"); $this->select( $this->byName("item_param_type[0]") - )->selectOptionByLabel("VARCHAR"); + )->selectOptionByLabel("VARCHAR"); $this->byName("item_param_length[0]")->value("10"); $this->byCssSelector("input[value='Add parameter']")->click(); $this->select( $this->byName("item_param_dir[1]") - )->selectOptionByLabel("OUT"); + )->selectOptionByLabel("OUT"); $ele = $this->_helper->waitForElement("byName", "item_param_name[1]"); $ele->value("outp"); @@ -118,13 +118,14 @@ class PmaSeleniumDbProceduresTest extends PHPUnit_Extensions_Selenium2TestCase $this->select( $this->byName("item_sqldataaccess") - )->selectOptionByLabel("READS SQL DATA"); + )->selectOptionByLabel("READS SQL DATA"); $this->byXPath("//button[contains(., 'Go')]")->click(); $ele = $this->_helper->waitForElement( "byXPath", - "//div[@class='success' and contains(., 'Routine `test_procedure` has been created')]" + "//div[@class='success' and contains(., " + . "'Routine `test_procedure` has been created')]" ); $result = $this->_helper->dbQuery( @@ -162,7 +163,8 @@ class PmaSeleniumDbProceduresTest extends PHPUnit_Extensions_Selenium2TestCase $ele = $this->_helper->waitForElement( "byXPath", - "//div[@class='success' and contains(., 'Routine `test_procedure` has been modified')]" + "//div[@class='success' and contains(., " + . "'Routine `test_procedure` has been modified')]" ); $this->_executeProcedure("abcabcabcabcabcabcabc", 12); @@ -189,7 +191,7 @@ class PmaSeleniumDbProceduresTest extends PHPUnit_Extensions_Selenium2TestCase $this->byLinkText("Drop")->click(); $this->_helper->waitForElement( "byXPath", "//button[contains(., 'OK')]" - )->click(); + )->click(); $this->_helper->waitForElement("byId", "nothing2display"); @@ -203,6 +205,9 @@ class PmaSeleniumDbProceduresTest extends PHPUnit_Extensions_Selenium2TestCase /** * Execute procedure * + * @param string $text String to pass as inp param + * @param int $length Expected output length + * * @return void */ private function _executeProcedure($text, $length) diff --git a/test/selenium/PmaSeleniumDbStructureTest.php b/test/selenium/PmaSeleniumDbStructureTest.php index 4cf89d4fda..829c676ab9 100644 --- a/test/selenium/PmaSeleniumDbStructureTest.php +++ b/test/selenium/PmaSeleniumDbStructureTest.php @@ -89,12 +89,13 @@ class PmaSeleniumDbStructureTest extends PHPUnit_Extensions_Selenium2TestCase $this->_helper->waitForElement( "byXPath", "//button[contains(., 'OK')]" - )->click(); + )->click(); $this->assertNotNull( $this->_helper->waitForElement( "byXPath", - "//div[@class='success' and contains(., 'MySQL returned an empty result')]" + "//div[@class='success' and contains(., " + . "'MySQL returned an empty result')]" ) ); diff --git a/test/selenium/PmaSeleniumDbTriggersTest.php b/test/selenium/PmaSeleniumDbTriggersTest.php index edae2e2df1..453eb683f3 100644 --- a/test/selenium/PmaSeleniumDbTriggersTest.php +++ b/test/selenium/PmaSeleniumDbTriggersTest.php @@ -51,7 +51,8 @@ class PmaSeleniumDbTriggersTest extends PHPUnit_Extensions_Selenium2TestCase . " PRIMARY KEY (`id`)" . ")" ); - $this->_helper->dbQuery( + + $this->_helper->dbQuery( "CREATE TABLE `test_table2` (" . " `id` int(11) NOT NULL AUTO_INCREMENT," . " `val` int(11) NOT NULL," @@ -123,7 +124,8 @@ class PmaSeleniumDbTriggersTest extends PHPUnit_Extensions_Selenium2TestCase $ele = $this->_helper->waitForElement( "byXPath", - "//div[@class='success' and contains(., 'Trigger `test_trigger` has been created')]" + "//div[@class='success' and contains(., " + . "'Trigger `test_trigger` has been created')]" ); $this->assertTrue( @@ -172,7 +174,8 @@ class PmaSeleniumDbTriggersTest extends PHPUnit_Extensions_Selenium2TestCase $ele = $this->_helper->waitForElement( "byXPath", - "//div[@class='success' and contains(., 'Trigger `test_trigger` has been modified')]" + "//div[@class='success' and contains(., " + . "'Trigger `test_trigger` has been modified')]" ); // test trigger @@ -203,7 +206,7 @@ class PmaSeleniumDbTriggersTest extends PHPUnit_Extensions_Selenium2TestCase $this->byLinkText("Drop")->click(); $this->_helper->waitForElement( "byXPath", "//button[contains(., 'OK')]" - )->click(); + )->click(); $this->_helper->waitForElement("byId", "nothing2display"); diff --git a/test/selenium/PmaSeleniumExportTest.php b/test/selenium/PmaSeleniumExportTest.php new file mode 100644 index 0000000000..c1e47c27dc --- /dev/null +++ b/test/selenium/PmaSeleniumExportTest.php @@ -0,0 +1,227 @@ +_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(); + $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," + . " PRIMARY KEY (`id`)" + . ")" + ); + $this->_helper->dbQuery( + "INSERT INTO `test_table` (val) VALUES (2);" + ); + } + + /** + * 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 export + * + * @param string $plugin Export format + * @param array $expected Array of expected strings + * + * @return void + * @dataProvider exportDataProvider + */ + public function testServerImport($plugin, $expected) + { + $text = $this->_doExport('server', $plugin); + + foreach ($expected as $str) { + $this->assertContains($str, $text); + } + + } + + /** + * Test for db level export + * + * @param string $plugin Export format + * @param array $expected Array of expected strings + * + * @return void + * @dataProvider exportDataProvider + */ + public function testDbExport($plugin, $expected) + { + $this->_helper->waitForElement("byLinkText", $this->_dbname)->click(); + $this->_helper->waitForElement( + "byXPath", + "//a[@class='item' and contains(., 'Database: ". $this->_dbname ."')]" + ); + + $text = $this->_doExport('db', $plugin); + + foreach ($expected as $str) { + $this->assertContains($str, $text); + } + } + + /** + * Test for table level export + * + * @param string $plugin Export format + * @param array $expected Array of expected strings + * + * @return void + * @dataProvider exportDataProvider + */ + public function testTableExport($plugin, $expected) + { + $this->_helper->dbQuery("INSERT INTO `test_table` (val) VALUES (3);"); + + // go to database page + $this->_helper->waitForElement("byLinkText", $this->_dbname)->click(); + + // got to table page + $this->_helper->waitForElement("byLinkText", "test_table")->click(); + $this->_helper->waitForElement( + "byXPath", + "//a[@class='tabactive' and contains(., 'Browse')]" + ); + + $text = $this->_doExport('table', $plugin); + + foreach ($expected as $str) { + $this->assertContains($str, $text); + } + } + + + /** + * Data provider for testServerExport + * + * @return array Test cases data + */ + public function exportDataProvider() + { + return array( + array( + 'CSV', + array('"1","2"') + ), + array( + 'SQL', + array( + "CREATE TABLE IF NOT EXISTS `test_table`", + "INSERT INTO `test_table` (`id`, `val`) VALUES (1, 2);" + ) + ), + array( + 'JSON', + array('[{"id":"1","val":"2"}]') + ) + ); + } + + /** + * Function that goes to the import page, uploads a file and submit form + * + * @param string $type level: server, db or import + * @param string $plugin format: csv, json, etc + * + * @return string export string + */ + private function _doExport($type, $plugin) + { + $this->byLinkText("Export")->click(); + + $this->_helper->waitForElement("byName", "dump"); + $this->byCssSelector("label[for=radio_custom_export]")->click(); + + if ($type == 'server') { + $this->byLinkText('Unselect All')->click(); + $this->byCssSelector("option[value=" . $this->_dbname . "]")->click(); + } + + if ($type == 'table') { + $this->byCssSelector("label[for=radio_allrows_0]")->click(); + $this->byName("limit_to")->clear(); + $this->byName("limit_to")->value("1"); + } + + $this->select($this->byId("plugins"))->selectOptionByLabel($plugin); + $this->byCssSelector("label[for=radio_view_as_text]")->click(); + + if ($plugin == "SQL") { + $this->byCssSelector( + "label[for=radio_sql_structure_or_data_structure_and_data]" + )->click(); + + if ($type != "table") { + $this->byCssSelector( + "label[for=checkbox_sql_create_database]" + )->click(); + } + } + + $this->byId("buttonGo")->click(); + + $text = $this->_helper->waitForElement("byId", "textSQLDUMP")->text(); + + return $text; + } + + /** + * Tear Down function for test cases + * + * @return void + */ + public function tearDown() + { + $this->_helper->dbQuery('DROP DATABASE IF EXISTS ' . $this->_dbname); + } + +} diff --git a/test/selenium/PmaSeleniumServerSettingsTest.php b/test/selenium/PmaSeleniumServerSettingsTest.php new file mode 100644 index 0000000000..1f68406d03 --- /dev/null +++ b/test/selenium/PmaSeleniumServerSettingsTest.php @@ -0,0 +1,164 @@ +_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(); + $this->_helper->dbQuery('CREATE DATABASE ' . $this->_dbname); + $this->_helper->dbQuery('USE ' . $this->_dbname); + } + + /** + * setUp function that can use the selenium session (called before each test) + * + * @return void + */ + public function setUpPage() + { + $this->_helper->login(TESTSUITE_USER, TESTSUITE_PASSWORD); + $more = $this->byLinkText("More"); + $this->moveto($more); + $this->_helper->waitForElement("byLinkText", "Settings")->click(); + $this->_helper->waitForElement( + "byXPath", "//a[@class='tabactive' and contains(., 'Settings')]" + ); + } + + /** + * Tests whether hiding a database works or not + * + * @return void + */ + public function testHideDatabase() + { + $this->byLinkText("Features")->click(); + + $this->_helper->waitForElement("byId", "Servers-1-hide_db") + ->value($this->_dbname); + $this->byName("submit_save")->click(); + $this->_helper->waitForElement( + "byXPath", + "//div[@class='success' and contains(., 'Configuration has been saved')]" + ); + $this->assertFalse( + $this->_helper->isElementPresent("byLinkText", $this->_dbname) + ); + + $this->byCssSelector("a[href='#Servers-1-hide_db']")->click(); + $this->byName("submit_save")->click(); + $this->_helper->waitForElement( + "byXPath", + "//div[@class='success' and contains(., 'Configuration has been saved')]" + ); + $this->assertTrue( + $this->_helper->isElementPresent("byLinkText", $this->_dbname) + ); + } + + /** + * Tests whether the various settings tabs are displayed when clicked + * + * @return void + */ + public function testSettingsTabsAreDisplayed() + { + $this->byLinkText("SQL queries")->click(); + $this->_helper->waitForElement('byClassName', 'tabs'); + + $this->byLinkText("SQL Query box")->click(); + $this->assertTrue( + $this->byId("Sql_box")->displayed() + ); + $this->assertFalse( + $this->byId("Sql_queries")->displayed() + ); + + $this->byCssSelector("a[href='#Sql_queries']")->click(); + $this->assertFalse( + $this->byId("Sql_box")->displayed() + ); + $this->assertTrue( + $this->byId("Sql_queries")->displayed() + ); + } + + /** + * Tests if hiding the logo works or not + * + * @return void + */ + public function testHideLogo() + { + $this->byLinkText("Navigation panel")->click(); + + $this->_helper->waitForElement("byName", "NavigationDisplayLogo") + ->click(); + $this->byName("submit_save")->click(); + $this->_helper->waitForElement( + "byXPath", + "//div[@class='success' and contains(., 'Configuration has been saved')]" + ); + $this->assertFalse( + $this->_helper->isElementPresent("byId", "imgpmalogo") + ); + + $this->byCssSelector("a[href='#NavigationDisplayLogo']")->click(); + $this->byName("submit_save")->click(); + $this->_helper->waitForElement( + "byXPath", + "//div[@class='success' and contains(., 'Configuration has been saved')]" + ); + $this->assertTrue( + $this->_helper->isElementPresent("byId", "imgpmalogo") + ); + } + + /** + * Tear Down function for test cases + * + * @return void + */ + public function tearDown() + { + $this->_helper->dbQuery('DROP DATABASE IF EXISTS ' . $this->_dbname); + } + +} diff --git a/test/selenium/PmaSeleniumTableBrowseTest.php b/test/selenium/PmaSeleniumTableBrowseTest.php index 50e936ccc7..9e338508e9 100644 --- a/test/selenium/PmaSeleniumTableBrowseTest.php +++ b/test/selenium/PmaSeleniumTableBrowseTest.php @@ -171,7 +171,7 @@ class PmaSeleniumTableBrowseTest extends PHPUnit_Extensions_Selenium2TestCase { $this->byCssSelector( "table#table_results tbody tr:nth-child(2) td:nth-child(2) a" - )->click(); + )->click(); $this->_helper->waitForElement("byId", "insertForm"); $this->assertEquals( @@ -253,7 +253,7 @@ class PmaSeleniumTableBrowseTest extends PHPUnit_Extensions_Selenium2TestCase { $this->byCssSelector( "table#table_results tbody tr:nth-child(3) td:nth-child(3) a" - )->click(); + )->click(); $this->_helper->waitForElement("byId", "insertForm"); diff --git a/test/selenium/PmaSeleniumTableCreateTest.php b/test/selenium/PmaSeleniumTableCreateTest.php index 0e2b23edb7..94bbaee553 100644 --- a/test/selenium/PmaSeleniumTableCreateTest.php +++ b/test/selenium/PmaSeleniumTableCreateTest.php @@ -146,7 +146,8 @@ class PmaSeleniumTableCreateTest extends PHPUnit_Extensions_Selenium2TestCase $this->assertFalse( $this->_helper->isElementPresent( 'byCssSelector', - 'table#tablestructure tbody tr:nth-child(1) ul.table-structure-actions li.primary a' + 'table#tablestructure tbody tr:nth-child(1) " + . "ul.table-structure-actions li.primary a' ) ); @@ -178,7 +179,8 @@ class PmaSeleniumTableCreateTest extends PHPUnit_Extensions_Selenium2TestCase $this->assertFalse( $this->_helper->isElementPresent( - 'byCssSelector', 'css=ul.table-structure-actions:nth-child(2) li.primary a' + 'byCssSelector', + 'css=ul.table-structure-actions:nth-child(2) li.primary a' ) ); } diff --git a/test/selenium/PmaSeleniumTableInsertTest.php b/test/selenium/PmaSeleniumTableInsertTest.php index 97ca865a2b..d315d4893b 100644 --- a/test/selenium/PmaSeleniumTableInsertTest.php +++ b/test/selenium/PmaSeleniumTableInsertTest.php @@ -98,7 +98,7 @@ class PmaSeleniumTableInsertTest extends PHPUnit_Extensions_Selenium2TestCase // post $this->byCssSelector( "input[value=Go]" - )->click(); + )->click(); $this->_helper->waitForElementNotPresent("byId", "loading_parent"); $ele = $this->_helper->waitForElement("byClassName", "success"); @@ -106,6 +106,11 @@ class PmaSeleniumTableInsertTest extends PHPUnit_Extensions_Selenium2TestCase $this->_assertDataPresent(); } + /** + * Assert various data present in results table + * + * @return void + */ private function _assertDataPresent() { $this->byLinkText("Browse")->click(); diff --git a/test/selenium/PmaSeleniumTableOperationsTest.php b/test/selenium/PmaSeleniumTableOperationsTest.php index 7bae707484..a1afc2d138 100644 --- a/test/selenium/PmaSeleniumTableOperationsTest.php +++ b/test/selenium/PmaSeleniumTableOperationsTest.php @@ -116,7 +116,8 @@ class PmaSeleniumTableOperationsTest extends PHPUnit_Extensions_Selenium2TestCas */ public function testMoveTable() { - $this->byCssSelector("form#moveTableForm input[name='new_name']")->value("2"); + $this->byCssSelector("form#moveTableForm input[name='new_name']") + ->value("2"); $this->byXPath("(//input[@value='Go'])[2]")->click(); diff --git a/test/selenium/PmaSeleniumTableStructureTest.php b/test/selenium/PmaSeleniumTableStructureTest.php index c162841422..2c4391cf82 100644 --- a/test/selenium/PmaSeleniumTableStructureTest.php +++ b/test/selenium/PmaSeleniumTableStructureTest.php @@ -89,7 +89,8 @@ class PmaSeleniumTableStructureTest extends PHPUnit_Extensions_Selenium2TestCase $this->_helper->waitForElement( "byXPath", - "//div[@class='success' and contains(., 'Table test_table has been altered successfully')]" + "//div[@class='success' and contains(., " + . "'Table test_table has been altered successfully')]" ); $this->byLinkText("Structure")->click(); @@ -124,7 +125,8 @@ class PmaSeleniumTableStructureTest extends PHPUnit_Extensions_Selenium2TestCase $this->_helper->waitForElement( "byXPath", - "//div[@class='success' and contains(., 'Table test_table has been altered successfully')]" + "//div[@class='success' and contains(., " + . "'Table test_table has been altered successfully')]" ); $this->assertEquals( @@ -142,16 +144,18 @@ class PmaSeleniumTableStructureTest extends PHPUnit_Extensions_Selenium2TestCase { $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->byXPath( + "//button[@class='mult_submit' and contains(., 'Drop')]" + )->click(); $this->_helper->waitForElement( "byCssSelector", "input[id='buttonYes']" - ) - ->click(); + )->click(); $this->_helper->waitForElement( "byXPath", - "//div[@class='success' and contains(., 'Your SQL query has been executed successfully')]" + "//div[@class='success' and contains(., " + . "'Your SQL query has been executed successfully')]" ); $this->assertFalse(