Add drone.yml and fix tests to be compatable with docker pipeline #1

Merged
jhodges merged 14 commits from tests into master 2020-09-30 15:13:57 +01:00
Showing only changes of commit b9f9de56c9 - Show all commits

View File

@ -6,188 +6,200 @@ use GuzzleHttp\RequestOptions;
class CrawlerTest extends TestCase{
private $url='http://localhost:8080';
public function __construct(){
parent::__construct();
if(getenv('URL')){
$this->url=getenv('URL');
}
echo $this->url;
}
public function testFullSite(){
echo $this->url;
$crawler=new Crawler([RequestOptions::CONNECT_TIMEOUT => 3, RequestOptions::TIMEOUT => 3]);
$crawler->crawl('http://localhost:8080/');
$crawler->crawl($this->url);
$sitemap=$crawler->getResults();
$this->assertTreeContains($sitemap,[
'http://example.com/' => ['code' => 200],
'http://localhost:8080/deeplink1' => ['code' => 200],
'http://localhost:8080/deeplink2' => ['code' => 200],
'http://localhost:8080/deeplink3' => ['code' => 200],
'http://localhost:8080/externalLink' => ['code' => 200],
'http://localhost:8080/found' => ['code' => 200],
'http://localhost:8080/interlinked1' => ['code' => 200],
'http://localhost:8080/interlinked2' => ['code' => 200],
'http://localhost:8080/interlinked3' => ['code' => 200],
'http://localhost:8080/internalServerError' => ['code' => 500],
'http://localhost:8080/invalidStatusCode' => ['code' => '---'],
'http://localhost:8080/notFound' => ['code' => 404],
'http://localhost:8080/redirect1' => ['code' => 302],
'http://localhost:8080/redirect2' => ['code' => 302],
'http://localhost:8080/redirectLoop' => ['code' => '---'],
'http://localhost:8080/redirectToFound' => ['code' => 302 ],
'http://localhost:8080/redirectToNotFound' => ['code' => 302 ],
'http://localhost:8080/redirectToRedirectToNotFound' => ['code' => 302],
'http://localhost:8080/timeout' => ['code' => '---'],
'http://localhost:8080/twoRedirectsToSameLocation' => ['code' => 200],
$this->url.'/deeplink1' => ['code' => 200],
$this->url.'/deeplink2' => ['code' => 200],
$this->url.'/deeplink3' => ['code' => 200],
$this->url.'/externalLink' => ['code' => 200],
$this->url.'/found' => ['code' => 200],
$this->url.'/interlinked1' => ['code' => 200],
$this->url.'/interlinked2' => ['code' => 200],
$this->url.'/interlinked3' => ['code' => 200],
$this->url.'/internalServerError' => ['code' => 500],
$this->url.'/invalidStatusCode' => ['code' => '---'],
$this->url.'/notFound' => ['code' => 404],
$this->url.'/redirect1' => ['code' => 302],
$this->url.'/redirect2' => ['code' => 302],
$this->url.'/redirectLoop' => ['code' => '---'],
$this->url.'/redirectToFound' => ['code' => 302 ],
$this->url.'/redirectToNotFound' => ['code' => 302 ],
$this->url.'/redirectToRedirectToNotFound' => ['code' => 302],
$this->url.'/timeout' => ['code' => '---'],
$this->url.'/twoRedirectsToSameLocation' => ['code' => 200],
], print_r($sitemap,true));
}
public function testFound(){
$crawler=new Crawler();
$crawler->crawl('http://localhost:8080/found');
$crawler->crawl($this->url.'/found');
$sitemap=$crawler->getResults();
$this->assertTreeContains($sitemap,[
'http://localhost:8080/found' => ['code' => 200],
$this->url.'/found' => ['code' => 200],
], print_r($sitemap,true));
}
public function testNotFound(){
$crawler=new Crawler();
$crawler->crawl('http://localhost:8080/notFound');
$crawler->crawl($this->url.'/notFound');
$sitemap=$crawler->getResults();
$this->assertTreeContains($sitemap,[
'http://localhost:8080/notFound' => ['code' => 404],
$this->url.'/notFound' => ['code' => 404],
], print_r($sitemap,true));
}
public function testExternalLink(){
$crawler=new Crawler();
$crawler->crawl('http://localhost:8080/externalLink');
$crawler->crawl($this->url.'/externalLink');
$sitemap=$crawler->getResults();
$this->assertTreeContains($sitemap,[
'http://localhost:8080/externalLink' => ['code' => 200],
$this->url.'/externalLink' => ['code' => 200],
'http://example.com/' => ['code' => 200],
], print_r($sitemap,true));
}
public function testDeeplink(){
$crawler=new Crawler();
$crawler->crawl('http://localhost:8080/deeplink1');
$crawler->crawl($this->url.'/deeplink1');
$sitemap=$crawler->getResults();
$this->assertTreeContains($sitemap,[
'http://localhost:8080/deeplink1' => ['code' => 200],
'http://localhost:8080/deeplink2' => ['code' => 200],
'http://localhost:8080/deeplink3' => ['code' => 200],
$this->url.'/deeplink1' => ['code' => 200],
$this->url.'/deeplink2' => ['code' => 200],
$this->url.'/deeplink3' => ['code' => 200],
], print_r($sitemap,true));
}
public function testInterlinked(){
$crawler=new Crawler();
$crawler->crawl('http://localhost:8080/interlinked1');
$crawler->crawl('http://localhost:8080/interlinked4'); //this ensures the order or results for the URL tracking test PART2
$crawler->crawl($this->url.'/interlinked1');
$crawler->crawl($this->url.'/interlinked4'); //this ensures the order or results for the URL tracking test PART2
$sitemap=$crawler->getResults();
$this->assertTreeContains($sitemap,[
'http://localhost:8080/interlinked1' => ['code' => 200 , 'foundOn' => [
'http://localhost:8080/interlinked1' => 1,
'http://localhost:8080/interlinked2' => 1,
'http://localhost:8080/interlinked3' => 1,
'http://localhost:8080/interlinked4' => 1,
$this->url.'/interlinked1' => ['code' => 200 , 'foundOn' => [
$this->url.'/interlinked1' => 1,
$this->url.'/interlinked2' => 1,
$this->url.'/interlinked3' => 1,
$this->url.'/interlinked4' => 1,
]],
'http://localhost:8080/interlinked2' => ['code' => 200 , 'foundOn' => [
'http://localhost:8080/interlinked1' => 1,
'http://localhost:8080/interlinked2' => 1,
'http://localhost:8080/interlinked3' => 1,
'http://localhost:8080/interlinked4' => 1,
$this->url.'/interlinked2' => ['code' => 200 , 'foundOn' => [
$this->url.'/interlinked1' => 1,
$this->url.'/interlinked2' => 1,
$this->url.'/interlinked3' => 1,
$this->url.'/interlinked4' => 1,
]],
'http://localhost:8080/interlinked3' => ['code' => 200 , 'foundOn' => [
'http://localhost:8080/interlinked1' => 1,
'http://localhost:8080/interlinked2' => 1,
'http://localhost:8080/interlinked3' => 1,
'http://localhost:8080/interlinked4' => 1,
$this->url.'/interlinked3' => ['code' => 200 , 'foundOn' => [
$this->url.'/interlinked1' => 1,
$this->url.'/interlinked2' => 1,
$this->url.'/interlinked3' => 1,
$this->url.'/interlinked4' => 1,
]],
'http://localhost:8080/found' => ['code' => 200 , 'foundOn' => [
'http://localhost:8080/interlinked1' => 1,
'http://localhost:8080/interlinked2' => 1,
'http://localhost:8080/interlinked3' => 1,
'http://localhost:8080/interlinked4' => 1,
$this->url.'/found' => ['code' => 200 , 'foundOn' => [
$this->url.'/interlinked1' => 1,
$this->url.'/interlinked2' => 1,
$this->url.'/interlinked3' => 1,
$this->url.'/interlinked4' => 1,
]],
'http://localhost:8080/redirectToFound' => ['code' => 302 , 'foundOn' => [
'http://localhost:8080/interlinked1' => 1,
'http://localhost:8080/interlinked2' => 1,
'http://localhost:8080/interlinked3' => 1,
'http://localhost:8080/interlinked4' => 1,
$this->url.'/redirectToFound' => ['code' => 302 , 'foundOn' => [
$this->url.'/interlinked1' => 1,
$this->url.'/interlinked2' => 1,
$this->url.'/interlinked3' => 1,
$this->url.'/interlinked4' => 1,
]],
], print_r($sitemap,true));
}
public function testRedirectToFound(){
$crawler=new Crawler();
$crawler->crawl('http://localhost:8080/redirectToFound');
$crawler->crawl($this->url.'/redirectToFound');
$sitemap=$crawler->getResults();
$this->assertTreeContains($sitemap,[
'http://localhost:8080/redirectToFound' => ['code' => 302],
'http://localhost:8080/found' => ['code' => 200 ],
$this->url.'/redirectToFound' => ['code' => 302],
$this->url.'/found' => ['code' => 200 ],
], print_r($sitemap,true));
}
public function testRedirectToNotFound(){
$crawler=new Crawler();
$crawler->crawl('http://localhost:8080/redirectToNotFound');
$crawler->crawl($this->url.'/redirectToNotFound');
$sitemap=$crawler->getResults();
$this->assertTreeContains($sitemap,[
'http://localhost:8080/redirectToNotFound' => ['code' => 302],
'http://localhost:8080/notFound' => ['code' => 404 ],
$this->url.'/redirectToNotFound' => ['code' => 302],
$this->url.'/notFound' => ['code' => 404 ],
], print_r($sitemap,true));
}
public function testRedirectToRedirectToNotFound(){
$crawler=new Crawler();
$crawler->crawl('http://localhost:8080/redirectToRedirectToNotFound');
$crawler->crawl($this->url.'/redirectToRedirectToNotFound');
$sitemap=$crawler->getResults();
$this->assertTreeContains($sitemap,[
'http://localhost:8080/redirectToRedirectToNotFound' => ['code' => 302],
'http://localhost:8080/redirectToNotFound' => ['code' => 302],
'http://localhost:8080/notFound' => ['code' => 404],
$this->url.'/redirectToRedirectToNotFound' => ['code' => 302],
$this->url.'/redirectToNotFound' => ['code' => 302],
$this->url.'/notFound' => ['code' => 404],
], print_r($sitemap,true));
}
public function testTwoRedirectsToSameLocation(){
$crawler=new Crawler();
$crawler->crawl('http://localhost:8080/twoRedirectsToSameLocation');
$crawler->crawl($this->url.'/twoRedirectsToSameLocation');
$sitemap=$crawler->getResults();
$this->assertTreeContains($sitemap,[
'http://localhost:8080/twoRedirectsToSameLocation' => ['code' => 200],
'http://localhost:8080/redirect1' => ['code' => 302],
'http://localhost:8080/redirect2' => ['code' => 302],
'http://localhost:8080/found' => ['code' => 200],
$this->url.'/twoRedirectsToSameLocation' => ['code' => 200],
$this->url.'/redirect1' => ['code' => 302],
$this->url.'/redirect2' => ['code' => 302],
$this->url.'/found' => ['code' => 200],
], print_r($sitemap,true));
}
public function testTimeout(){
$crawler=new Crawler([RequestOptions::CONNECT_TIMEOUT => 3, RequestOptions::TIMEOUT => 3]);
$crawler->crawl('http://localhost:8080/timeout');
$crawler->crawl($this->url.'/timeout');
$sitemap=$crawler->getResults();
$this->assertTreeContains($sitemap,[
'http://localhost:8080/timeout' => ['code' => '---'],
$this->url.'/timeout' => ['code' => '---'],
], print_r($sitemap,true));
}
public function testRedirectLoop(){
$crawler=new Crawler();
$crawler->crawl('http://localhost:8080/redirectLoop');
$crawler->crawl($this->url.'/redirectLoop');
$sitemap=$crawler->getResults();
$this->assertTreeContains($sitemap,[
'http://localhost:8080/redirectLoop' => ['code' => '---'],
$this->url.'/redirectLoop' => ['code' => '---'],
], print_r($sitemap,true));
}
public function testInternalServerError(){
$crawler=new Crawler();
$crawler->crawl('http://localhost:8080/internalServerError');
$crawler->crawl($this->url.'/internalServerError');
$sitemap=$crawler->getResults();
$this->assertTreeContains($sitemap,[
'http://localhost:8080/internalServerError' => ['code' => 500],
$this->url.'/internalServerError' => ['code' => 500],
], print_r($sitemap,true));
}
public function testInvalidStatusCode(){
$crawler=new Crawler();
$crawler->crawl('http://localhost:8080/invalidStatusCode');
$crawler->crawl($this->url.'/invalidStatusCode');
$sitemap=$crawler->getResults();
$this->assertTreeContains($sitemap,[
'http://localhost:8080/invalidStatusCode' => ['code' => '---'],
$this->url.'/invalidStatusCode' => ['code' => '---'],
], print_r($sitemap,true));
}