diff --git a/tests/CrawlerTest.php b/tests/CrawlerTest.php index b762356..ccfd953 100644 --- a/tests/CrawlerTest.php +++ b/tests/CrawlerTest.php @@ -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'; diff --git a/tests/server/server.js b/tests/server/server.js index b0dd455..bfc8e3e 100644 --- a/tests/server/server.js +++ b/tests/server/server.js @@ -70,6 +70,10 @@ app.get('/meta-nofollow', function (request, response) { response.end('
\n\nno follow it'); }); +app.get('/redirect-home/', function (request, response) { + response.redirect(301, '/'); +}); + app.get('/dir1/internal-redirect-entry/', function (request, response) { response.end('trapped trap-start'); });