-
-
Notifications
You must be signed in to change notification settings - Fork 360
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #145 from spatie/respect-robots
Respect robots
- Loading branch information
Showing
9 changed files
with
286 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
<?php | ||
|
||
namespace Spatie\Crawler\Test; | ||
|
||
use Spatie\Crawler\Crawler; | ||
|
||
class CrawlerRobotsTest extends TestCase | ||
{ | ||
public function setUp() | ||
{ | ||
parent::setUp(); | ||
|
||
$this->skipIfTestServerIsNotRunning(); | ||
|
||
$this->resetLog(); | ||
} | ||
|
||
/** @test */ | ||
public function it_should_not_follow_robots_txt_disallowed_links() | ||
{ | ||
$this->createCrawler() | ||
->startCrawling('http://localhost:8080'); | ||
|
||
$this->assertNotCrawled([['url' => 'http://localhost:8080/txt-disallow', 'foundOn' => 'http://localhost:8080/']]); | ||
} | ||
|
||
/** @test */ | ||
public function it_does_not_allow_a_root_ignored_url() | ||
{ | ||
$this->createCrawler() | ||
->startCrawling('http://localhost:8080/txt-disallow'); | ||
|
||
$this->assertNotCrawled([['url' => 'http://localhost:8080/txt-disallow', 'foundOn' => 'http://localhost:8080/']]); | ||
} | ||
|
||
/** @test */ | ||
public function it_should_follow_robots_txt_disallowed_links_when_robots_are_ignored() | ||
{ | ||
$this->createCrawler() | ||
->ignoreRobots() | ||
->startCrawling('http://localhost:8080'); | ||
|
||
$this->assertCrawledOnce([['url' => 'http://localhost:8080/txt-disallow', 'foundOn' => 'http://localhost:8080/']]); | ||
} | ||
|
||
/** @test */ | ||
public function it_should_not_follow_robots_meta_disallowed_links() | ||
{ | ||
$this->createCrawler() | ||
->startCrawling('http://localhost:8080'); | ||
|
||
$this->assertNotCrawled([['url' => 'http://localhost:8080/meta-disallow', 'foundOn' => 'http://localhost:8080/']]); | ||
} | ||
|
||
/** @test */ | ||
public function it_should_follow_robots_meta_disallowed_links_when_robots_are_ignored() | ||
{ | ||
$this->createCrawler() | ||
->ignoreRobots() | ||
->startCrawling('http://localhost:8080'); | ||
|
||
$this->assertCrawledOnce([['url' => 'http://localhost:8080/meta-disallow', 'foundOn' => 'http://localhost:8080/']]); | ||
} | ||
|
||
/** @test */ | ||
public function it_should_not_follow_robots_header_disallowed_links() | ||
{ | ||
$this->createCrawler() | ||
->startCrawling('http://localhost:8080'); | ||
|
||
$this->assertNotCrawled([['url' => 'http://localhost:8080/header-disallow', 'foundOn' => 'http://localhost:8080/']]); | ||
} | ||
|
||
/** @test */ | ||
public function it_should_follow_robots_header_disallowed_links_when_robots_are_ignored() | ||
{ | ||
$this->createCrawler() | ||
->ignoreRobots() | ||
->startCrawling('http://localhost:8080'); | ||
|
||
$this->assertCrawledOnce([['url' => 'http://localhost:8080/header-disallow', 'foundOn' => 'http://localhost:8080/']]); | ||
} | ||
|
||
private function createCrawler(): Crawler | ||
{ | ||
return Crawler::create() | ||
->setMaximumDepth(1) | ||
->setCrawlObserver(new CrawlLogger()); | ||
} | ||
} |
Oops, something went wrong.