This commit is contained in:
James
2019-09-18 09:58:46 +01:00
commit 4c7995a935
7 changed files with 1879 additions and 0 deletions

24
src/BrowserTest.php Normal file
View File

@@ -0,0 +1,24 @@
<?php
namespace JHodges\PHPUnitBase;
abstract class BrowserTest extends PHPUnit_Extensions_Selenium2TestCase{
public function setUp(){
$this->setHost('localhost');
$this->setPort(4444);
$this->setDesiredCapabilities(['moz:firefoxOptions'=>['args'=>['-headless','screenshot','window-size='.getenv('SeleniumWindowSize')]]]);
$this->setBrowserUrl(getenv('SeleniumBrowserUrl'));
$this->setBrowser(getenv('SeleniumBrowser'));
}
public function tearDown(){
if ($this->hasFailed()) {
if($path=getenv('SeleniumScreenshotPath')){
$filedata = $this->currentScreenshot();
file_put_contents($path.$this->getName().'.png', $filedata);
}
}
$this->stop();
}
}

View File

@@ -0,0 +1,72 @@
<?php
namespace JHodges\PHPUnitBase;
abstract class DomainRedirectTest extends UrlRedirectTest{
/**
* @return string the source domain
**/
abstract protected function getSourceDomain();
/**
* @return string the destination URL
**/
abstract protected function getDestinationURL();
/**
* Test source domain with HTTP:// redirects correctly to the destination URL
**/
public function testHttp(){
$this->assertUrlRedirect('http://'.$this->getSourceDomain().'',$this->getDestinationURL());
}
/**
* Test source domain with HTTPS:// redirects correctly to the destination URL
**/
public function testHttps(){
$this->assertUrlRedirect('https://'.$this->getSourceDomain().'',$this->getDestinationURL());
}
/**
* Test source domain with HTTP://WWW. redirects correctly to the destination URL
**/
public function testHttpWww(){
$this->assertUrlRedirect('http://www.'.$this->getSourceDomain().'',$this->getDestinationURL());
}
/**
* Test source domain with HTTPS://www. redirects correctly to the destination URL
**/
public function testHttpsWww(){
$this->assertUrlRedirect('https://www.'.$this->getSourceDomain().'',$this->getDestinationURL());
}
/**
* Test source domain with HTTP:// and a trailing slash redirects correctly to the destination URL
**/
public function testHttpSlash(){
$this->assertUrlRedirect('http://'.$this->getSourceDomain().'/',$this->getDestinationURL());
}
/**
* Test source domain with HTTPS:// and a trailing slash redirects correctly to the destination URL
**/
public function testHttpsSlash(){
$this->assertUrlRedirect('https://'.$this->getSourceDomain().'/',$this->getDestinationURL());
}
/**
* Test source domain with HTTP://www. and a trailing slash redirects correctly to the destination URL
**/
public function testHttpWwwSlash(){
$this->assertUrlRedirect('http://www.'.$this->getSourceDomain().'/',$this->getDestinationURL());
}
/**
* Test source domain with HTTPS://www. and a trailing slash redirects correctly to the destination URL
**/
public function testHttpsWwwSlash(){
$this->assertUrlRedirect('https://www.'.$this->getSourceDomain().'/',$this->getDestinationURL());
}
}

24
src/UrlRedirectTest.php Normal file
View File

@@ -0,0 +1,24 @@
<?php
namespace JHodges\PHPUnitBase;
use PHPUnit\Framework\TestCase;
abstract class UrlRedirectTest extends TestCase{
/**
* Test $from redirects to $to
* @param string $from source URL
* @param string $to dest URL
**/
public function assertUrlRedirect($from,$to){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $from);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
$html = curl_exec($ch);
$redirectedUrl = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
curl_close($ch);
$this->assertEquals($to,$redirectedUrl,"From: {$from}");
}
}