Skip to content

Commit

Permalink
Showing 7 changed files with 34 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -2,6 +2,9 @@

All notable changes to `laravel-sitemap` will be documented in this file

## 3.2.0 - 2017-10-03
- add `crawl_profile` config key

## 3.1.0 - 2017-09-22

- add ability to execute JavaScript
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -17,6 +17,7 @@
],
"require": {
"php": "^7.0",
"guzzlehttp/guzzle": "^6.3",
"illuminate/support": "~5.5.0",
"nesbot/carbon": "^1.21",
"spatie/crawler": "^2.3",
2 changes: 1 addition & 1 deletion src/SitemapServiceProvider.php
Original file line number Diff line number Diff line change
@@ -30,7 +30,7 @@ public function boot()
});

$this->app->bind(Profile::class, function ($app, $params) {
return new Profile(reset($params));
return new Profile(...$params);
});
}

4 changes: 2 additions & 2 deletions tests/CrawlProfileTest.php
Original file line number Diff line number Diff line change
@@ -25,7 +25,7 @@ public function setUp()
}

/** @test */
public function it_should_use_the_default_crawl_profile()
public function it_can_use_the_default_profile()
{
$this->crawler
->method('setCrawlProfile')
@@ -40,7 +40,7 @@ public function it_should_use_the_default_crawl_profile()
}

/** @test */
public function it_should_use_a_custom_crawl_profile()
public function it_can_use_the_custom_profile()
{
config(['sitemap.crawl_profile' => CustomCrawlProfile::class]);

6 changes: 5 additions & 1 deletion tests/CustomCrawlProfile.php
Original file line number Diff line number Diff line change
@@ -16,6 +16,10 @@ class CustomCrawlProfile implements CrawlProfile
*/
public function shouldCrawl(Url $url): bool
{
return true;
if ($url->host !== 'localhost') {
return false;
}

return is_null($url->segment(1));
}
}
13 changes: 13 additions & 0 deletions tests/SitemapGeneratorTest.php
Original file line number Diff line number Diff line change
@@ -79,6 +79,19 @@ public function it_will_not_crawl_an_url_if_should_crawl_returns_false()
$this->assertMatchesXmlSnapshot(file_get_contents($sitemapPath));
}

/** @test */
public function it_can_use_a_custom_profile()
{
config(['sitemap.crawl_profile' => CustomCrawlProfile::class]);

$sitemapPath = $this->temporaryDirectory->path('test.xml');

SitemapGenerator::create('http://localhost:4020')
->writeToFile($sitemapPath);

$this->assertMatchesXmlSnapshot(file_get_contents($sitemapPath));
}

protected function skipIfTestServerIsNotRunning()
{
try {
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml">
<url>
<loc>http://localhost:4020/</loc>
<lastmod>2016-01-01T00:00:00+00:00</lastmod>
<changefreq>daily</changefreq>
<priority>0.8</priority>
</url>
</urlset>

0 comments on commit 8681a0c

Please sign in to comment.