-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/aggregate facility use modifier (#109)
* Add an Order feed modifier that filters out Order elements that should not be present on Order objects when they are in the Orders RPDE feed. Also add a test case to check it works.
- Loading branch information
Showing
3 changed files
with
90 additions
and
1 deletion.
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,29 @@ | ||
<?php | ||
/** | ||
* AggregateFacilityUseProviderModifier | ||
* | ||
* Removes the provider attribute from the aggregateFacilityUse | ||
* property of an OrderedItem's FacilityUse. | ||
* | ||
* Used to modify the C1/C2/B order output if the provider has | ||
* been added in during construction of Slot OrderedItems | ||
* | ||
* This typically happens because the Orders feed requires the | ||
* provider to be present and the C1/C2/B steps require it to | ||
* be omitted. It depends how your renderer for FacilityUse has | ||
* been setup | ||
*/ | ||
|
||
namespace OpenActive\Modifiers; | ||
|
||
class AggregateFacilityUseProviderModifier | ||
{ | ||
public function __invoke($class, $key, $value) | ||
{ | ||
if ($key == 'aggregateFacilityUse' && isset($value['provider'])) { | ||
unset($value['provider']); | ||
} | ||
|
||
return $value; | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
tests/Unit/Modifiers/AggregateFacilityUseProviderModifierTest.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,60 @@ | ||
<?php | ||
|
||
namespace OpenActive\Models\Tests\Unit\Modifiers; | ||
|
||
use OpenActive\Modifiers\AggregateFacilityUseProviderModifier; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class AggregateFacilityUseProviderModifierTest extends TestCase | ||
{ | ||
protected function getTestData() | ||
{ | ||
return [ | ||
'id' => 1, | ||
'provider' => 'https://example.com/openactive/sellers/1' | ||
]; | ||
} | ||
|
||
public function testModifierRemovesProvider() | ||
{ | ||
// Data for this test | ||
$testData = $this->getTestData(); | ||
|
||
// Check the test data has both keys | ||
$this->assertArrayHasKey('id', $testData); | ||
$this->assertArrayHasKey('provider', $testData); | ||
|
||
// Create a new modifier | ||
$modifier = new AggregateFacilityUseProviderModifier(); | ||
|
||
// Run the modifier against the test data | ||
$resultData = $modifier('', 'aggregateFacilityUse', $testData); | ||
|
||
// Check that the result still has the ID key | ||
$this->assertArrayHasKey('id', $resultData); | ||
|
||
// Check that the provider key has been removed | ||
$this->assertArrayNotHasKey('provider', $resultData); | ||
} | ||
|
||
public function testModifierDoesNotRemoveProvider() | ||
{ | ||
// Data for this test | ||
$testData = $this->getTestData(); | ||
|
||
// Check the test data has both keys | ||
$this->assertArrayHasKey('id', $testData); | ||
$this->assertArrayHasKey('provider', $testData); | ||
|
||
// Create a new modifier | ||
$modifier = new AggregateFacilityUseProviderModifier(); | ||
|
||
// Run the modifier against the test data for a key it should | ||
// not modify | ||
$resultData = $modifier('', 'someOtherIgnoredType', $testData); | ||
|
||
// Check the result data has both keys | ||
$this->assertArrayHasKey('id', $resultData); | ||
$this->assertArrayHasKey('provider', $resultData); | ||
} | ||
} |