Skip to content
This repository has been archived by the owner on Jun 28, 2022. It is now read-only.

Commit

Permalink
III-1778: Remove bookingperiod when bookingInfo availability is removed
Browse files Browse the repository at this point in the history
  • Loading branch information
cyberwolf committed Jan 17, 2017
1 parent c17b009 commit 34b2b69
Show file tree
Hide file tree
Showing 6 changed files with 160 additions and 19 deletions.
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -16,7 +16,7 @@
"cultuurnet/geocoding": "~0.1",
"cultuurnet/silex-amqp": "~1.0",
"cultuurnet/udb3": "~0.1",
"cultuurnet/cdb": "~2.2",
"cultuurnet/cdb": "dev-feature/III-1778 as 2.2",
"cultuurnet/udb2-domain-events": "~1.0",
"crell/api-problem": "^1.7",
"doctrine/dbal": "^2.4",
Expand Down
27 changes: 18 additions & 9 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 12 additions & 9 deletions src/ReadModel/OfferToCdbXmlProjector.php
Expand Up @@ -1687,21 +1687,24 @@ private function updateCdbItemByBookingInfo(
) {
// Add the booking Period.
if ($cdbItem instanceof CultureFeed_Cdb_Item_Event) {
$bookingPeriod = $cdbItem->getBookingPeriod();
if (empty($bookingPeriod)) {
$bookingPeriod = new CultureFeed_Cdb_Data_Calendar_BookingPeriod(
null,
null
);
}
$startDate = null;
$endDate = null;

if ($bookingInfo->getAvailabilityStarts()) {
$startDate = new DateTime($bookingInfo->getAvailabilityStarts());
$bookingPeriod->setDateFrom($startDate->getTimestamp());
$startDate = $startDate->getTimestamp();
}
if ($bookingInfo->getAvailabilityEnds()) {
$endDate = new DateTime($bookingInfo->getAvailabilityEnds());
$bookingPeriod->setDateTill($endDate->getTimestamp());
$endDate = $endDate->getTimestamp();
}

$bookingPeriod = null;
if (null !== $startDate || null !== $endDate) {
$bookingPeriod = new CultureFeed_Cdb_Data_Calendar_BookingPeriod(
$startDate,
$endDate
);
}

$cdbItem->setBookingPeriod($bookingPeriod);
Expand Down
48 changes: 48 additions & 0 deletions tests/ReadModel/OfferToCdbXmlProjectorTest.php
Expand Up @@ -849,6 +849,54 @@ public function it_projects_booking_info_events(
$this->execute($test);
}

/**
* @test
* @group issue-III-1778
* @dataProvider genericOfferTestDataProvider
*
* @param OfferType $offerType
* @param $id
* @param $cdbXmlType
*/
public function it_removes_bookingperiod_when_booking_availability_is_removed(
OfferType $offerType,
$id,
$cdbXmlType
) {
$test = $this->given($offerType)
->apply(
new BookingInfoUpdated(
$id,
new BookingInfo(
'http://tickets.example.com',
'Tickets on Example.com',
'+32 666 666',
'tickets@example.com',
'2014-01-31T12:00:00',
'2014-02-20T15:00:00',
'booking name'
)
)
)
->apply(
new BookingInfoUpdated(
$id,
new BookingInfo(
'http://tickets.example.com',
'Tickets on Example.com',
'+32 666 666',
'tickets@example.com',
'',
'',
'booking name'
)
)
)
->expect($cdbXmlType . '-booking-info-availability-removed.xml');

$this->execute($test);
}

/**
* @test
*/
Expand Down
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<cdbxml xmlns="http://www.cultuurdatabank.com/XMLSchema/CdbXSD/3.3/FINAL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.cultuurdatabank.com/XMLSchema/CdbXSD/3.3/FINAL http://www.cultuurdatabank.com/XMLSchema/CdbXSD/3.3/FINAL/CdbXSD.xsd">
<actor availableto="2100-01-01T01:00:00" cdbid="C4ACF936-1D5F-48E8-B2EC-863B313CBDE6" createdby="foobar" creationdate="2016-04-15T11:01:47" externalurl="http://foo.be/item/404EE8DE-E828-9C07-FE7D12DC4EB24480" lastupdated="2016-04-15T11:01:47" lastupdatedby="foo@bar.com" wfstatus="draft" asset="true">
<actordetails>
<actordetail lang="nl">
<title>My Place</title>
</actordetail>
</actordetails>
<categories>
<category catid="8.15.0.0.0" type="actortype">Locatie</category>
</categories>
<contactinfo>
<address>
<physical>
<city>Leuven</city>
<country>BE</country>
<housenr>1</housenr>
<street>Bondgenotenlaan</street>
<zipcode>3000</zipcode>
</physical>
</address>
<mail reservation="true">tickets@example.com</mail>
<phone reservation="true">+32 666 666</phone>
<url reservation="true">http://tickets.example.com</url>
</contactinfo>
</actor>
</cdbxml>
@@ -0,0 +1,54 @@
<?xml version="1.0" encoding="UTF-8"?>
<cdbxml xmlns="http://www.cultuurdatabank.com/XMLSchema/CdbXSD/3.3/FINAL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.cultuurdatabank.com/XMLSchema/CdbXSD/3.3/FINAL http://www.cultuurdatabank.com/XMLSchema/CdbXSD/3.3/FINAL/CdbXSD.xsd">
<event availableto="2014-02-20T16:00:00" cdbid="404EE8DE-E828-9C07-FE7D12DC4EB24480" createdby="foobar" creationdate="2016-04-15T11:01:47" externalurl="http://foo.be/item/404EE8DE-E828-9C07-FE7D12DC4EB24480" lastupdated="2016-04-15T11:01:47" lastupdatedby="foo@bar.com" private="false" wfstatus="draft">
<categories>
<category catid="0.50.6.0.0" type="eventtype">film</category>
<category catid="1.7.6.0.0" type="theme">Griezelfilm of horror</category>
</categories>
<calendar>
<timestamps>
<timestamp>
<date>2014-01-31</date>
<timestart>12:00:00</timestart>
<timeend>15:00:00</timeend>
</timestamp>
<timestamp>
<date>2014-02-20</date>
<timestart>12:00:00</timestart>
<timeend>15:00:00</timeend>
</timestamp>
</timestamps>
</calendar>
<contactinfo>
<address>
<physical>
<city>Leuven</city>
<country>BE</country>
<housenr>1</housenr>
<street>Bondgenotenlaan</street>
<zipcode>3000</zipcode>
</physical>
</address>
<mail reservation="true">tickets@example.com</mail>
<phone reservation="true">+32 666 666</phone>
<url reservation="true">http://tickets.example.com</url>
</contactinfo>
<eventdetails>
<eventdetail lang="nl">
<title>Griezelfilm of horror</title>
</eventdetail>
</eventdetails>
<location>
<address>
<physical>
<city>Leuven</city>
<country>BE</country>
<housenr>1</housenr>
<street>Bondgenotenlaan</street>
<zipcode>3000</zipcode>
</physical>
</address>
<label cdbid="C4ACF936-1D5F-48E8-B2EC-863B313CBDE6">Bibberburcht</label>
</location>
</event>
</cdbxml>

0 comments on commit 34b2b69

Please sign in to comment.