-
-
Notifications
You must be signed in to change notification settings - Fork 290
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add crawl_profile config to set custom CrawlProfile implementation (#94)
* add crawl_profile config to set custom CrawlProfile implementation, fixes #90
* apply style ci fixes
* add tests for custom crawl profile
* apply fixes from style ci
* remove empty line
- Loading branch information
1 parent
2a5d6f7
commit ab890d2
Showing
6 changed files
with
102 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
namespace Spatie\Sitemap\Test; | ||
|
||
use Spatie\Crawler\Crawler; | ||
use Spatie\Sitemap\Sitemap; | ||
use Spatie\Sitemap\Crawler\Profile; | ||
use Spatie\Sitemap\SitemapGenerator; | ||
|
||
class CrawlProfileTest extends TestCase | ||
{ | ||
/** | ||
* @var Crawler | ||
*/ | ||
private $crawler; | ||
|
||
public function setUp() | ||
{ | ||
parent::setUp(); | ||
|
||
$this->crawler = $this->createMock(Crawler::class); | ||
|
||
$this->crawler->method('setCrawlObserver')->willReturn($this->crawler); | ||
$this->crawler->method('setConcurrency')->willReturn($this->crawler); | ||
} | ||
|
||
/** @test */ | ||
public function it_should_use_the_default_crawl_profile() | ||
{ | ||
$this->crawler | ||
->method('setCrawlProfile') | ||
->with($this->isInstanceOf(Profile::class)) | ||
->willReturn($this->crawler); | ||
|
||
$sitemapGenerator = new SitemapGenerator($this->crawler); | ||
|
||
$sitemap = $sitemapGenerator->getSitemap(); | ||
|
||
$this->assertInstanceOf(Sitemap::class, $sitemap); | ||
} | ||
|
||
/** @test */ | ||
public function it_should_use_a_custom_crawl_profile() | ||
{ | ||
config(['sitemap.crawl_profile' => CustomCrawlProfile::class]); | ||
|
||
$this->crawler | ||
->method('setCrawlProfile') | ||
->with($this->isInstanceOf(CustomCrawlProfile::class)) | ||
->willReturn($this->crawler); | ||
|
||
$sitemapGenerator = new SitemapGenerator($this->crawler); | ||
|
||
$sitemap = $sitemapGenerator->getSitemap(); | ||
|
||
$this->assertInstanceOf(Sitemap::class, $sitemap); | ||
} | ||
} |
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,21 @@ | ||
<?php | ||
|
||
namespace Spatie\Sitemap\Test; | ||
|
||
use Spatie\Crawler\Url; | ||
use Spatie\Crawler\CrawlProfile; | ||
|
||
class CustomCrawlProfile implements CrawlProfile | ||
{ | ||
/** | ||
* Determine if the given url should be crawled. | ||
* | ||
* @param \Spatie\Crawler\Url $url | ||
* | ||
* @return bool | ||
*/ | ||
public function shouldCrawl(Url $url): bool | ||
{ | ||
return true; | ||
} | ||
} |