class PHPUnit_Extensions_Selenium2TestCase_Custom extends PHPUnit_Extensions_Selenium2TestCase {
/**
* Pre-setup
*/
function __construct($name = NULL, array $data = array(), $dataName = '') {
parent::__construct($name, $data, $dataName);
$this->setBrowser('firefox');
$this->setBrowserUrl('');
}
/**
* Redirect to specified URL or return current URL <p>
* Absolute or relative URL will be accepted
* @param string|null $url - URL, absolute or relative. If relative - always relative to root
* @return string - Current URL
*/
function url($url = null) {
$urlParsed = parse_url($url);
$currUrlParsed = parse_url(parent::url());
// Blank page, base url is not set
if (!empty($currUrlParsed['scheme']) && $currUrlParsed['scheme'] == 'about') {
$currUrlParsed = [];
}
// Passed URL is absolute
if (!empty($urlParsed['scheme'])) {
return parent::url($url);
// Passed URL is relative
} else {
if (empty($currUrlParsed['host'])) {
trigger_error('Unable to use relative URL: Current domain is not set', E_USER_ERROR);
}
$genUrl = $currUrlParsed['scheme'].'://'.$currUrlParsed['host'];
if (substr($url, 0, 1) != '/') {
$genUrl .= '/';
}
$genUrl .= $url;
return parent::url($genUrl);
}
}
}