From 0c0538b99decec8bd4d572dbcf78aafa27698fe1 Mon Sep 17 00:00:00 2001 From: ayushchd Date: Wed, 21 Aug 2013 21:38:26 +0530 Subject: [PATCH] Merge Helper and PmaSeleniumTestCase classes --- test/selenium/Helper.php | 184 ++++++++++++++++-- .../PmaSeleniumCreateDropDatabaseTest.php | 15 +- test/selenium/PmaSeleniumLoginTest.php | 26 +-- test/selenium/PmaSeleniumPrivilegesTest.php | 15 +- .../PmaSeleniumTablesInsertDataTest.php | 28 +-- test/selenium/PmaSeleniumTablesTest.php | 23 ++- test/selenium/PmaSeleniumTestCase.php | 176 ----------------- test/selenium/PmaSeleniumXssTest.php | 15 +- 8 files changed, 238 insertions(+), 244 deletions(-) delete mode 100644 test/selenium/PmaSeleniumTestCase.php diff --git a/test/selenium/Helper.php b/test/selenium/Helper.php index e0af035d29..5628e87311 100644 --- a/test/selenium/Helper.php +++ b/test/selenium/Helper.php @@ -1,7 +1,7 @@ _txtUsername = 'input_username'; + $this->_txtPassword = 'input_password'; + $this->_btnLogin = 'input_go'; + $this->_config = new TestConfig(); + $this->_selenium = $selenium; + $this->_mysqli = null; } - public static function isLoggedIn($selenium) + /** + * perform a login + * + * @param string $username Username + * @param string $password Password + * + * @return void + */ + public function login($username, $password) { - return $selenium->isElementPresent('//*[@id="serverinfo"]/a[1]'); + $this->_selenium->open($this->_config->getLoginURL()); + $this->_selenium->type($this->_txtUsername, $username); + $this->_selenium->type($this->_txtPassword, $password); + $this->_selenium->clickAndWait($this->_btnLogin); + //$this->_selenium->waitForPageToLoad($this->_config->getTimeoutValue()); } - public static function logOutIfLoggedIn($selenium) + /** + * Checks whether the login is successful + * + * @return boolean + */ + public function isSuccessLogin() { - if (self::isLoggedIn($selenium)) { - $selenium->clickAndWait("css=img.icon.ic_s_loggoff"); + if ($this->_selenium->isElementPresent("//*[@id=\"serverinfo\"]")) { + return true; + } else { + return false; } } - public static function getBrowserString() + /** + * Checks whether the login is unsuccessful + * + * @return boolean + */ + public function isUnsuccessLogin() { - $browserString = self::$config->getCurrentBrowser(); + if ($this->_selenium->isElementPresent("css=div.error")) { + return true; + } else { + return false; + } + } + + /** + * Used to go to the homepage + * + * @return void + */ + public function gotoHomepage() + { + $this->_selenium->click("css=div#serverinfo a:contains('Server:')"); + $this->_selenium->waitForElementNotPresent('css=div#loading_parent'); + } + + /** + * Establishes a connection with the local database + * + * @return void + */ + public function dbConnect() + { + if ($this->_mysqli === null) { + list($user, $pass) = $this->_config->getDBCredentials(); + + $this->_mysqli = new mysqli( + "localhost", $user, $pass + ); + + if ($this->_mysqli->connect_errno) { + throw new Exception( + 'Failed to connect to MySQL (' . $this->_mysqli->error . ')' + ); + } + } + } + + /** + * Executes a database query + * + * @param string $query SQL Query to be executed + * + * @return void + */ + public function dbQuery($query) + { + if ($this->_mysqli === null) { + throw new Exception( + 'MySQL not connected' + ); + } + $this->_mysqli->query($query); + } + + /** + * Check if user is logged in to phpmyadmin + * + * @return boolean Where or not user is logged in + */ + public function isLoggedIn() + { + return $this->_selenium->isElementPresent('//*[@id="serverinfo"]/a[1]'); + } + + /** + * Perform a logout, if logged in + * + * @return void + */ + public function logOutIfLoggedIn() + { + if ($this->isLoggedIn()) { + $this->_selenium->clickAndWait("css=img.icon.ic_s_loggoff"); + } + } + + /** + * Get current browser string + * + * @return string Browser String + */ + public function getBrowserString() + { + $browserString = $this->_config->getCurrentBrowser(); return $browserString; } } diff --git a/test/selenium/PmaSeleniumCreateDropDatabaseTest.php b/test/selenium/PmaSeleniumCreateDropDatabaseTest.php index e35ababc0e..4fd508c384 100644 --- a/test/selenium/PmaSeleniumCreateDropDatabaseTest.php +++ b/test/selenium/PmaSeleniumCreateDropDatabaseTest.php @@ -6,7 +6,6 @@ * @package PhpMyAdmin-test * @subpackage Selenium */ -require_once 'PmaSeleniumTestCase.php'; require_once 'Helper.php'; /** @@ -25,11 +24,11 @@ class PmaSeleniumCreateDropDatabaseTest extends PHPUnit_Extensions_SeleniumTestC private $_dbname; /** - * PmaSeleniumTestCase Object + * Helper Object * * @var obj */ - private $_seleniumTasks; + private $_helper; /** * Setup the browser environment to run the selenium test case @@ -38,10 +37,10 @@ class PmaSeleniumCreateDropDatabaseTest extends PHPUnit_Extensions_SeleniumTestC */ public function setUp() { - $helper = new Helper(); - $this->setBrowser(Helper::getBrowserString()); + $this->_helper = new Helper($this); + $this->setBrowser($this->_helper->getBrowserString()); $this->setBrowserUrl(TESTSUITE_PHPMYADMIN_HOST . TESTSUITE_PHPMYADMIN_URL); - $this->_seleniumTasks = new PmaSeleniumTestCase($this); + } /** @@ -52,7 +51,7 @@ class PmaSeleniumCreateDropDatabaseTest extends PHPUnit_Extensions_SeleniumTestC public function testCreateDropDatabase() { $this->_dbname = 'pma_testdb' . time(); - $this->_seleniumTasks->login(TESTSUITE_USER, TESTSUITE_PASSWORD); + $this->_helper->login(TESTSUITE_USER, TESTSUITE_PASSWORD); $this->click("link=Databases"); $this->waitForElementPresent("id=text_create_db"); $this->type("id=text_create_db", $this->_dbname); @@ -69,7 +68,7 @@ class PmaSeleniumCreateDropDatabaseTest extends PHPUnit_Extensions_SeleniumTestC */ private function _dropDatabase() { - $this->_seleniumTasks->gotoHomepage(); + $this->_helper->gotoHomepage(); $this->click("css=ul#topmenu a:contains('Databases')"); $this->waitForElementNotPresent('css=div#loading_parent'); $this->click( diff --git a/test/selenium/PmaSeleniumLoginTest.php b/test/selenium/PmaSeleniumLoginTest.php index 4330887bec..77a0fa5ae1 100644 --- a/test/selenium/PmaSeleniumLoginTest.php +++ b/test/selenium/PmaSeleniumLoginTest.php @@ -6,7 +6,6 @@ * @package PhpMyAdmin-test * @subpackage Selenium */ -require_once 'PmaSeleniumTestCase.php'; require_once 'Helper.php'; /** @@ -17,6 +16,13 @@ require_once 'Helper.php'; */ class PmaSeleniumLoginTest extends PHPUnit_Extensions_SeleniumTestCase { + /** + * Helper Object + * + * @var obj + */ + private $_helper; + /** * Setup the browser environment to run the selenium test case * @@ -24,8 +30,8 @@ class PmaSeleniumLoginTest extends PHPUnit_Extensions_SeleniumTestCase */ public function setUp() { - $helper = new Helper(); - $this->setBrowser(Helper::getBrowserString()); + $this->_helper = new Helper($this); + $this->setBrowser($this->_helper->getBrowserString()); $this->setBrowserUrl(TESTSUITE_PHPMYADMIN_HOST . TESTSUITE_PHPMYADMIN_URL); } @@ -36,10 +42,9 @@ class PmaSeleniumLoginTest extends PHPUnit_Extensions_SeleniumTestCase */ public function testSuccessfulLogin() { - $log = new PmaSeleniumTestCase($this); - $log->login(TESTSUITE_USER, TESTSUITE_PASSWORD); - $this->assertTrue($log->isSuccessLogin()); - Helper::logOutIfLoggedIn($this); + $this->_helper->login(TESTSUITE_USER, TESTSUITE_PASSWORD); + $this->assertTrue($this->_helper->isSuccessLogin()); + $this->_helper->logOutIfLoggedIn(); } /** @@ -49,10 +54,9 @@ class PmaSeleniumLoginTest extends PHPUnit_Extensions_SeleniumTestCase */ public function testLoginWithWrongPassword() { - $log = new PmaSeleniumTestCase($this); - $log->login("Admin", "Admin"); - $this->assertTrue($log->isUnsuccessLogin()); - Helper::logOutIfLoggedIn($this); + $this->_helper->login("Admin", "Admin"); + $this->assertTrue($this->_helper->isUnsuccessLogin()); + $this->_helper->logOutIfLoggedIn(); } } ?> diff --git a/test/selenium/PmaSeleniumPrivilegesTest.php b/test/selenium/PmaSeleniumPrivilegesTest.php index c3361c69f0..84e125edae 100644 --- a/test/selenium/PmaSeleniumPrivilegesTest.php +++ b/test/selenium/PmaSeleniumPrivilegesTest.php @@ -7,7 +7,6 @@ * @subpackage Selenium */ -require_once 'PmaSeleniumTestCase.php'; require_once 'Helper.php'; /** @@ -18,6 +17,13 @@ require_once 'Helper.php'; */ class PmaSeleniumPrivilegesTest extends PHPUnit_Extensions_SeleniumTestCase { + /** + * Helper Object + * + * @var obj + */ + private $_helper; + /** * Setup the browser environment to run the selenium test case * @@ -25,8 +31,8 @@ class PmaSeleniumPrivilegesTest extends PHPUnit_Extensions_SeleniumTestCase */ public function setUp() { - $helper = new Helper(); - $this->setBrowser(Helper::getBrowserString()); + $this->_helper = new Helper($this); + $this->setBrowser($this->_helper->getBrowserString()); $this->setBrowserUrl(TESTSUITE_PHPMYADMIN_HOST . TESTSUITE_PHPMYADMIN_URL); } @@ -37,8 +43,7 @@ class PmaSeleniumPrivilegesTest extends PHPUnit_Extensions_SeleniumTestCase */ public function testChangePassword() { - $log = new PmaSeleniumTestCase($this); - $log->login(TESTSUITE_USER, TESTSUITE_PASSWORD); + $this->_helper->login(TESTSUITE_USER, TESTSUITE_PASSWORD); $this->click("link=Change password"); $this->waitForElementPresent("id=change_password_anchor"); try { diff --git a/test/selenium/PmaSeleniumTablesInsertDataTest.php b/test/selenium/PmaSeleniumTablesInsertDataTest.php index abbbbb795a..8133db4ae1 100644 --- a/test/selenium/PmaSeleniumTablesInsertDataTest.php +++ b/test/selenium/PmaSeleniumTablesInsertDataTest.php @@ -6,7 +6,6 @@ * @package PhpMyAdmin-test * @subpackage Selenium */ -require_once 'PmaSeleniumTestCase.php'; require_once 'Helper.php'; /** @@ -25,11 +24,11 @@ class PmaSeleniumTablesInsertDataTest extends PHPUnit_Extensions_SeleniumTestCas private $_dbname; /** - * PmaSeleniumTestCase Object + * Helper Object * * @var obj */ - private $_seleniumTasks; + private $_helper; /** * Setup the browser environment to run the selenium test case @@ -38,16 +37,15 @@ class PmaSeleniumTablesInsertDataTest extends PHPUnit_Extensions_SeleniumTestCas */ public function setUp() { - $helper = new Helper(); - $this->setBrowser(Helper::getBrowserString()); + $this->_helper = new Helper($this); + $this->setBrowser($this->_helper->getBrowserString()); $this->setBrowserUrl(TESTSUITE_PHPMYADMIN_HOST . TESTSUITE_PHPMYADMIN_URL); $this->start(); - $this->_seleniumTasks = new PmaSeleniumTestCase($this); - $this->_seleniumTasks->dbConnect(); + $this->_helper->dbConnect(); $this->_dbname = 'pma_db_' . time(); - $this->_seleniumTasks->dbQuery('CREATE DATABASE ' . $this->_dbname); - $this->_seleniumTasks->dbQuery('USE ' . $this->_dbname); - $this->_seleniumTasks->dbQuery( + $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," . " `name` varchar(20) NOT NULL," @@ -55,7 +53,7 @@ class PmaSeleniumTablesInsertDataTest extends PHPUnit_Extensions_SeleniumTestCas . " PRIMARY KEY (`id`)" . ")" ); - $this->_seleniumTasks->login(TESTSUITE_USER, TESTSUITE_PASSWORD); + $this->_helper->login(TESTSUITE_USER, TESTSUITE_PASSWORD); $this->click('link='. $this->_dbname.''); $this->waitForElementPresent("link=test_table"); } @@ -142,8 +140,14 @@ class PmaSeleniumTablesInsertDataTest extends PHPUnit_Extensions_SeleniumTestCas $this->getTable("table_results.3.6") ); } + + /** + * Tear Down function for test cases + * + * @return void + */ public function tearDown() { - $this->_seleniumTasks->dbQuery('DROP DATABASE ' . $this->_dbname); + $this->_helper->dbQuery('DROP DATABASE ' . $this->_dbname); } } diff --git a/test/selenium/PmaSeleniumTablesTest.php b/test/selenium/PmaSeleniumTablesTest.php index 30c4d383e5..7dc580a8ae 100644 --- a/test/selenium/PmaSeleniumTablesTest.php +++ b/test/selenium/PmaSeleniumTablesTest.php @@ -6,7 +6,6 @@ * @package PhpMyAdmin-test * @subpackage Selenium */ -require_once 'PmaSeleniumTestCase.php'; require_once 'Helper.php'; /** @@ -25,11 +24,11 @@ class PmaSeleniumTablesTest extends PHPUnit_Extensions_SeleniumTestCase private $_dbname; /** - * PmaSeleniumTestCase Object + * Helper Object * * @var obj */ - private $_seleniumTasks; + private $_helper; /** * Setup the browser environment to run the selenium test case @@ -38,13 +37,12 @@ class PmaSeleniumTablesTest extends PHPUnit_Extensions_SeleniumTestCase */ public function setUp() { - $helper = new Helper(); - $this->setBrowser(Helper::getBrowserString()); + $this->_helper = new Helper($this); + $this->setBrowser($this->_helper->getBrowserString()); $this->setBrowserUrl(TESTSUITE_PHPMYADMIN_HOST . TESTSUITE_PHPMYADMIN_URL); - $this->_seleniumTasks = new PmaSeleniumTestCase($this); - $this->_seleniumTasks->dbConnect(); + $this->_helper->dbConnect(); $this->_dbname = 'pma_db_' . time(); - $this->_seleniumTasks->dbQuery('CREATE DATABASE ' . $this->_dbname); + $this->_helper->dbQuery('CREATE DATABASE ' . $this->_dbname); } /** @@ -54,7 +52,7 @@ class PmaSeleniumTablesTest extends PHPUnit_Extensions_SeleniumTestCase */ public function testCreateTable() { - $this->_seleniumTasks->login(TESTSUITE_USER, TESTSUITE_PASSWORD); + $this->_helper->login(TESTSUITE_USER, TESTSUITE_PASSWORD); $this->click('link='. $this->_dbname.''); $this->waitForElementPresent('id=create_table_form_minimal'); $this->type( @@ -179,8 +177,13 @@ class PmaSeleniumTablesTest extends PHPUnit_Extensions_SeleniumTestCase ); } + /** + * Tear down functions for test cases + * + * @return void + */ public function tearDown() { - $this->_seleniumTasks->dbQuery('DROP DATABASE ' . $this->_dbname); + $this->_helper->dbQuery('DROP DATABASE ' . $this->_dbname); } } diff --git a/test/selenium/PmaSeleniumTestCase.php b/test/selenium/PmaSeleniumTestCase.php deleted file mode 100644 index 3c0943f2ba..0000000000 --- a/test/selenium/PmaSeleniumTestCase.php +++ /dev/null @@ -1,176 +0,0 @@ -_txtUsername = 'input_username'; - $this->_txtPassword = 'input_password'; - $this->_btnLogin = 'input_go'; - $this->_config = new TestConfig(); - $this->_selenium = $selenium; - $this->_mysqli = null; - } - - /** - * perform a login - * - * @param string $username Username - * @param string $password Password - * - * @return void - */ - public function login($username, $password) - { - $this->_selenium->open($this->_config->getLoginURL()); - $this->_selenium->type($this->_txtUsername, $username); - $this->_selenium->type($this->_txtPassword, $password); - $this->_selenium->clickAndWait($this->_btnLogin); - //$this->_selenium->waitForPageToLoad($this->_config->getTimeoutValue()); - } - - /** - * Checks whether the login is successful - * - * @return boolean - */ - public function isSuccessLogin() - { - if ($this->_selenium->isElementPresent("//*[@id=\"serverinfo\"]")) { - return true; - } else { - return false; - } - } - - /** - * Checks whether the login is unsuccessful - * - * @return boolean - */ - public function isUnsuccessLogin() - { - if ($this->_selenium->isElementPresent("css=div.error")) { - return true; - } else { - return false; - } - } - - /** - * Used to go to the homepage - * - * @return void - */ - public function gotoHomepage() - { - $this->_selenium->click("css=div#serverinfo a:contains('Server:')"); - $this->_selenium->waitForElementNotPresent('css=div#loading_parent'); - } - - /** - * Establishes a connection with the local database - * - * @return void - */ - public function dbConnect() - { - if ($this->_mysqli === null) { - list($user, $pass) = $this->_config->getDBCredentials(); - - $this->_mysqli = new mysqli( - "localhost", $user, $pass - ); - - if ($this->_mysqli->connect_errno) { - throw new Exception( - 'Failed to connect to MySQL (' . $this->_mysqli->error . ')' - ); - } - } - } - - /** - * Executes a database query - * - * @param string $query SQL Query to be executed - * - * @return void - */ - public function dbQuery($query) - { - if ($this->_mysqli === null) { - throw new Exception( - 'MySQL not connected' - ); - } - $this->_mysqli->query($query); - } -} -?> diff --git a/test/selenium/PmaSeleniumXssTest.php b/test/selenium/PmaSeleniumXssTest.php index 344d680594..1db92cd490 100644 --- a/test/selenium/PmaSeleniumXssTest.php +++ b/test/selenium/PmaSeleniumXssTest.php @@ -7,7 +7,6 @@ * @subpackage Selenium */ -require_once 'PmaSeleniumTestCase.php'; require_once 'Helper.php'; /** @@ -18,6 +17,13 @@ require_once 'Helper.php'; */ class PmaSeleniumXSSTest extends PHPUnit_Extensions_SeleniumTestCase { + /** + * Helper Object + * + * @var obj + */ + private $_helper; + /** * Setup the browser environment to run the selenium test case * @@ -25,8 +31,8 @@ class PmaSeleniumXSSTest extends PHPUnit_Extensions_SeleniumTestCase */ public function setUp() { - $helper = new Helper(); - $this->setBrowser(Helper::getBrowserString()); + $this->_helper = new Helper($this); + $this->setBrowser($this->_helper->getBrowserString()); $this->setBrowserUrl( TESTSUITE_PHPMYADMIN_HOST . TESTSUITE_PHPMYADMIN_URL ); @@ -39,8 +45,7 @@ class PmaSeleniumXSSTest extends PHPUnit_Extensions_SeleniumTestCase */ public function testQueryTabWithNullValue() { - $log = new PmaSeleniumTestCase($this); - $log->login(TESTSUITE_USER, TESTSUITE_PASSWORD); + $this->_helper->login(TESTSUITE_USER, TESTSUITE_PASSWORD); $this->click("link=SQL"); $this->waitForElementPresent("id=queryboxf"); $this->click("button_submit_query");