This repository has been archived by the owner on Sep 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27
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 #247 from symfony-cmf/feature/ISSUE-240_voter_for_…
…sitemap_aware_docuemtents implement voter for SitemapAwareDocuments
- Loading branch information
Showing
6 changed files
with
95 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
namespace Symfony\Cmf\Bundle\SeoBundle\Sitemap; | ||
|
||
use Symfony\Cmf\Bundle\SeoBundle\SitemapAwareInterface; | ||
|
||
/** | ||
* Implementing the SitemapAwareInterface will give the chance the let the document decide | ||
* whether it wants to be displayed on sitemap or not. | ||
* | ||
* @author Maximilian Berghoff <[email protected]> | ||
*/ | ||
class SitemapAwareDocumentVoter implements VoterInterface | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function exposeOnSitemap($content, $sitemap) | ||
{ | ||
if (!$content instanceof SitemapAwareInterface) { | ||
return true; | ||
} | ||
|
||
return $content->isVisibleInSitemap($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 |
---|---|---|
|
@@ -13,21 +13,20 @@ | |
namespace Symfony\Cmf\Bundle\SeoBundle; | ||
|
||
/** | ||
* Models implementing this interface can indicate whether they should be listed in the sitemap or not. | ||
* | ||
* For PHPCR-ODM documents used with the \Symfony\Cmf\Bundle\SeoBundle\Doctrine\Phpcr\SitemapUrlInformationProvider, | ||
* make sure to call the property that stores this information "visible_for_sitemap", | ||
* as the provider uses the property in the query rather than loading all documents and checking the method. | ||
* Models implementing this interface can indicate whether they should be listed in the sitemap | ||
* with a given sitemap name or not. | ||
* | ||
* @author Maximilian Berghoff <[email protected]> | ||
*/ | ||
interface SitemapElementInterface | ||
interface SitemapAwareInterface | ||
{ | ||
/** | ||
* Decision whether a document should be visible | ||
* in sitemap or not. | ||
* | ||
* @param $sitemap | ||
* | ||
* @return bool | ||
*/ | ||
public function isVisibleInSitemap(); | ||
public function isVisibleInSitemap($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
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,48 @@ | ||
<?php | ||
|
||
namespace Symfony\Cmf\Bundle\SeoBundle\Tests\Unit\Sitemap; | ||
|
||
use Symfony\Cmf\Bundle\SeoBundle\Sitemap\SitemapAwareDocumentVoter; | ||
use Symfony\Cmf\Bundle\SeoBundle\Sitemap\VoterInterface; | ||
|
||
/** | ||
* @author Maximilian Berghoff <[email protected]> | ||
*/ | ||
class SitemapAwareDocumentVoterTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @var VoterInterface | ||
*/ | ||
protected $voter; | ||
protected $sitemapAwareDocument; | ||
|
||
public function setUp() | ||
{ | ||
$this->voter = new SitemapAwareDocumentVoter(); | ||
$this->sitemapAwareDocument = $this->getMock('\Symfony\Cmf\Bundle\SeoBundle\SitemapAwareInterface'); | ||
} | ||
|
||
public function testSitemapAwareDocumentShouldReturnTrueWhenDocumentIsExposed() | ||
{ | ||
$this->sitemapAwareDocument | ||
->expects($this->once()) | ||
->method('isVisibleInSitemap') | ||
->will($this->returnValue(true)); | ||
$this->assertTrue($this->voter->exposeOnSitemap($this->sitemapAwareDocument, 'some-sitemap')); | ||
} | ||
|
||
|
||
public function testSitemapAwareDocumentShouldReturnFalseWhenDocumentIsNotExposed() | ||
{ | ||
$this->sitemapAwareDocument | ||
->expects($this->once()) | ||
->method('isVisibleInSitemap') | ||
->will($this->returnValue(false)); | ||
$this->assertFalse($this->voter->exposeOnSitemap($this->sitemapAwareDocument, 'some-sitemap')); | ||
} | ||
|
||
public function testInvalidDocumentShouldReturnTrueToBeAwareForTheOtherVoters() | ||
{ | ||
$this->assertTrue($this->voter->exposeOnSitemap(new \stdClass(), 'some-sitemap')); | ||
} | ||
} |