phpmyadmin/test/selenium/PmaSeleniumTestCase.php
2013-08-15 20:14:41 +05:30

177 lines
3.6 KiB
PHP

<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Selenium parent class for TestCases
*
* @package PhpMyAdmin-test
* @subpackage Selenium
*/
/**
* PmaSeleniumTestCase class
*
* @package PhpMyAdmin-test
* @subpackage Selenium
*/
class PmaSeleniumTestCase
{
/**
* Username of the user
*
* @access private
* @var string
*/
private $_txtUsername;
/**
* Password for the user
*
* @access private
* @var string
*/
private $_txtPassword;
/**
* id of the login button
*
* @access private
* @var string
*/
private $_btnLogin;
/**
* Selenium Context
*
* @access private
* @var object
*/
private $_selenium;
/**
* Configuration Instance
*
* @access private
* @var object
*/
private $_config;
/**
* mysqli object
*
* @access private
* @var object
*/
private $_mysqli;
/**
* constructor
*
* @param object $selenium Selenium Context
*/
public function __construct($selenium)
{
$this->_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);
}
}
?>