Skip to content

Commit

Permalink
add test and patch for the spatie/crawler#271
Browse files Browse the repository at this point in the history
  • Loading branch information
James committed Feb 23, 2020
1 parent b26bd7c commit c3cf298
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jhodges/sitemap",
"description": "generate full sitemap report",
"description": "Generate full sitemap report using spatie/crawler",
"type": "project",
"require": {
"php": "^7.1",
Expand All @@ -26,6 +26,9 @@
"patches": {
"spatie/crawler": {
"add crawled again observer": "https://patch-diff.githubusercontent.com/raw/spatie/crawler/pull/280.patch"
},
"guzzlehttp/guzzle": {
"Status code must be an integer value between 1xx and 5xx": "https://patch-diff.githubusercontent.com/raw/guzzle/guzzle/pull/2591.patch"
}
}
}
Expand Down
10 changes: 10 additions & 0 deletions tests/CrawlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public function testFullSite(){
'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],
Expand Down Expand Up @@ -165,6 +166,15 @@ public function testInternalServerError(){
], print_r($sitemap,true));
}

public function testInvalidStatusCode(){
$crawler=new Crawler();
$crawler->crawl('http://localhost:8080/invalidStatusCode');
$sitemap=$crawler->getResults();
$this->assertTreeContains($sitemap,[
'http://localhost:8080/invalidStatusCode' => ['code' => '---'],
], print_r($sitemap,true));
}

public function assertTreeContains($haystack, $contains, $crumbs=''){
foreach($contains as $k=>$v){
$this->assertArrayHasKey($k, $haystack, $crumbs);
Expand Down
5 changes: 5 additions & 0 deletions tests/server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ app.get('/', function (request, response) {
' <li><a href="/redirectLoop">redirectLoop</a></li>',
' <li><a href="/timeout">timeout</a></li>',
' <li><a href="/internalServerError">internalServerError</a></li>',
' <li><a href="/invalidStatusCode">invalidStatusCode</a></li>',
' <li><a href="/twoRedirectsToSameLocation">twoRedirectsToSameLocation</a></li>',
' <li><a href="mailto:test@example.com">mailto</a></li>',
' <li><a href="tel:+4412345678">tel</a></li>',
Expand Down Expand Up @@ -78,6 +79,10 @@ app.get('/internalServerError', function (request, response) {
response.status(500).end();
});

app.get('/invalidStatusCode', function (request, response) {
response.status(999).end();
});

app.get('/interlinked1', function (request, response) {
response.end('<a href="/interlinked1">1</a><a href="/interlinked2">2</a><a href="/interlinked3">3</a>');
});
Expand Down

0 comments on commit c3cf298

Please sign in to comment.