Skip to content

Commit

Permalink
Add max depth + redirects test
Browse files Browse the repository at this point in the history
  • Loading branch information
David Racovan committed Jul 10, 2024
1 parent 90aa275 commit 858a9a7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
12 changes: 12 additions & 0 deletions tests/CrawlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,18 @@ public function shouldCrawl(UriInterface $url): bool
assertCrawledUrlCount(3);
});

it('should handle redirects correctly when max depth is specified', function () {
createCrawler([
RequestOptions::ALLOW_REDIRECTS => [
'track_redirects' => true,
],
])
->setMaximumDepth(5)
->startCrawling('http://localhost:8080/redirect-home/');

expect(['url' => 'http://localhost:8080/link1', 'foundOn' => 'http://localhost:8080/'])->toBeCrawledOnce();
});

it('respects the requested delay between requests', function () {
$baseUrl = 'http://localhost:8080';

Expand Down
4 changes: 4 additions & 0 deletions tests/server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ app.get('/meta-nofollow', function (request, response) {
response.end('<html><head>\n<meta name="robots" content="index, nofollow">\n</head><body><a href="/meta-nofollow-target">no follow it</a></body></html>');
});

app.get('/redirect-home/', function (request, response) {
response.redirect(301, '/');
});

app.get('/dir1/internal-redirect-entry/', function (request, response) {
response.end('<a href="../loop-generator/internal-redirect/trapped/">trapped</a> <a href="../../dir1/internal-redirect/trap/">trap-start</a>');
});
Expand Down

0 comments on commit 858a9a7

Please sign in to comment.