This repository has been archived by the owner on Jun 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
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 #65 from cultuurnet/feature/III-1768
III-1768 Prevent removal of categories.
- Loading branch information
Showing
16 changed files
with
691 additions
and
140 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,39 @@ | ||
<?php | ||
|
||
namespace CultuurNet\UDB3\CdbXmlService\CultureFeed; | ||
|
||
use CultureFeed_Cdb_Data_CategoryList; | ||
use CultuurNet\UDB3\CdbXmlService\CultureFeed\CategorySpecification\CategorySpecificationInterface; | ||
|
||
class CategoryListFilter | ||
{ | ||
/** | ||
* @var CategorySpecificationInterface | ||
*/ | ||
private $spec; | ||
|
||
/** | ||
* @param CategorySpecificationInterface $spec | ||
*/ | ||
public function __construct(CategorySpecificationInterface $spec) | ||
{ | ||
$this->spec = $spec; | ||
} | ||
|
||
/** | ||
* @param CultureFeed_Cdb_Data_CategoryList $categories | ||
* @return CultureFeed_Cdb_Data_CategoryList | ||
*/ | ||
public function filter(CultureFeed_Cdb_Data_CategoryList $categories) | ||
{ | ||
$matchingCategories = new CultureFeed_Cdb_Data_CategoryList(); | ||
|
||
foreach ($categories as $category) { | ||
if ($this->spec->matches($category)) { | ||
$matchingCategories->add($category); | ||
} | ||
} | ||
|
||
return $matchingCategories; | ||
} | ||
} |
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,42 @@ | ||
<?php | ||
|
||
namespace CultuurNet\UDB3\CdbXmlService\CultureFeed\CategorySpecification; | ||
|
||
use CultureFeed_Cdb_Data_Category; | ||
|
||
class AnyOff implements CategorySpecificationInterface | ||
{ | ||
/** | ||
* @var CategorySpecificationInterface[] | ||
*/ | ||
private $wrapped; | ||
|
||
public function __construct() | ||
{ | ||
$args = func_get_args(); | ||
|
||
foreach ($args as $index => $arg) { | ||
if (!$arg instanceof CategorySpecificationInterface) { | ||
throw new \InvalidArgumentException( | ||
"Invalid argument received at position $index, expected an implementation of CategorySpecificationInterface" | ||
); | ||
} | ||
} | ||
|
||
$this->wrapped = $args; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function matches(CultureFeed_Cdb_Data_Category $category) | ||
{ | ||
foreach ($this->wrapped as $wrapped) { | ||
if ($wrapped->matches($category)) { | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/CultureFeed/CategorySpecification/CategorySpecificationInterface.php
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,14 @@ | ||
<?php | ||
|
||
namespace CultuurNet\UDB3\CdbXmlService\CultureFeed\CategorySpecification; | ||
|
||
use CultureFeed_Cdb_Data_Category; | ||
|
||
interface CategorySpecificationInterface | ||
{ | ||
/** | ||
* @param CultureFeed_Cdb_Data_Category $category | ||
* @return bool | ||
*/ | ||
public function matches(CultureFeed_Cdb_Data_Category $category); | ||
} |
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,30 @@ | ||
<?php | ||
|
||
namespace CultuurNet\UDB3\CdbXmlService\CultureFeed\CategorySpecification; | ||
|
||
use CultureFeed_Cdb_Data_Category; | ||
|
||
class Not implements CategorySpecificationInterface | ||
{ | ||
/** | ||
* @var CategorySpecificationInterface | ||
*/ | ||
private $wrapped; | ||
|
||
/** | ||
* Not constructor. | ||
* @param CategorySpecificationInterface $wrapped | ||
*/ | ||
public function __construct(CategorySpecificationInterface $wrapped) | ||
{ | ||
$this->wrapped = $wrapped; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function matches(CultureFeed_Cdb_Data_Category $category) | ||
{ | ||
return !$this->wrapped->matches($category); | ||
} | ||
} |
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,29 @@ | ||
<?php | ||
|
||
namespace CultuurNet\UDB3\CdbXmlService\CultureFeed\CategorySpecification; | ||
|
||
use CultureFeed_Cdb_Data_Category; | ||
|
||
class Type implements CategorySpecificationInterface | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
private $type; | ||
|
||
/** | ||
* @param string $type | ||
*/ | ||
public function __construct($type) | ||
{ | ||
$this->type = $type; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function matches(CultureFeed_Cdb_Data_Category $category) | ||
{ | ||
return $category->getType() == $this->type; | ||
} | ||
} |
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,84 @@ | ||
<?php | ||
|
||
namespace CultuurNet\UDB3\CdbXmlService\CultureFeed\CategorySpecification; | ||
|
||
use CultureFeed_Cdb_Data_Category; | ||
|
||
class AnyOffTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @var CategorySpecificationInterface | ||
*/ | ||
private $trueCategorySpecification; | ||
|
||
/** | ||
* @var CategorySpecificationInterface | ||
*/ | ||
private $falseCategorySpecification; | ||
|
||
/** | ||
* @var AnyOff | ||
*/ | ||
private $anyOff; | ||
|
||
protected function setUp() | ||
{ | ||
$this->falseCategorySpecification = $this->createCategorySpecification(false); | ||
|
||
$this->trueCategorySpecification = $this->createCategorySpecification(true); | ||
|
||
$this->anyOff = new AnyOff( | ||
$this->falseCategorySpecification, | ||
$this->trueCategorySpecification | ||
); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function it_matches_when_at_least_one_specification_matches() | ||
{ | ||
$category = new CultureFeed_Cdb_Data_Category( | ||
'eventtype', | ||
'0.50.4.0.0', | ||
'concert' | ||
); | ||
|
||
$this->assertTrue($this->anyOff->matches($category)); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function it_throws_exception_when_parameter_has_wrong_type() | ||
{ | ||
$this->expectException(\InvalidArgumentException::class); | ||
$this->expectExceptionMessage( | ||
'Invalid argument received at position 2, expected an implementation of CategorySpecificationInterface' | ||
); | ||
|
||
$this->anyOff = new AnyOff( | ||
$this->falseCategorySpecification, | ||
$this->trueCategorySpecification, | ||
'I am a string' | ||
); | ||
} | ||
|
||
/** | ||
* @param bool $result | ||
* @return CategorySpecificationInterface | ||
*/ | ||
private function createCategorySpecification($result) | ||
{ | ||
/** @var CategorySpecificationInterface|\PHPUnit_Framework_MockObject_MockObject $categorySpecification */ | ||
$categorySpecification = $this->createMock( | ||
CategorySpecificationInterface::class | ||
); | ||
|
||
$categorySpecification | ||
->method('matches') | ||
->willReturn($result); | ||
|
||
return $categorySpecification; | ||
} | ||
} |
Oops, something went wrong.