Skip to content

Commit

Permalink
Handle missing id inside Event and Place denormalizer
Browse files Browse the repository at this point in the history
  • Loading branch information
LucWollants committed Aug 9, 2023
1 parent 77c7a9d commit d5ef9e9
Show file tree
Hide file tree
Showing 3 changed files with 174 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ public function denormalize($data, $class, $format = null, array $context = [])
throw new UnsupportedException('Organizer data should be an associative array.');
}

if (!isset($data['@id'])) {
throw new UnsupportedException('Organizer data should contain an @id property.');
}

$organizerIdUrl = new Url($data['@id']);
$organizerId = $this->organizerIDParser->fromUrl($organizerIdUrl);

Expand Down
48 changes: 48 additions & 0 deletions tests/Model/Serializer/Event/EventDenormalizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1822,6 +1822,54 @@ public function it_handles_invalid_organizer_reference(): void
$this->assertEquals($expected, $actual);
}

/**
* @test
*/
public function it_handles_missing_organizer_reference_id(): void
{
$eventData = [
'@id' => 'https://io.uitdatabank.be/event/9f34efc7-a528-4ea8-a53e-a183f21abbab',
'@type' => 'Event',
'@context' => '/contexts/event',
'mainLanguage' => 'nl',
'name' => [
'nl' => 'Titel voorbeeld',
],
'location' => [
'@id' => 'https://io.uitdatabank.be/place/dbe91250-4e4b-495c-b692-3da9563b0d52',
],
'organizer' => [
'id' => 'https://io.uitdatabank.be/organizers/236f736e-5308-4c3a-94f3-da0bd768da7d',
],
'calendarType' => 'permanent',
'terms' => [
[
'id' => '0.50.1.0.1',
],
],
];

$expected = new ImmutableEvent(
new UUID('9f34efc7-a528-4ea8-a53e-a183f21abbab'),
new Language('nl'),
new TranslatedTitle(
new Language('nl'),
new Title('Titel voorbeeld')
),
new PermanentCalendar(new OpeningHours()),
PlaceReference::createWithPlaceId(new UUID('dbe91250-4e4b-495c-b692-3da9563b0d52')),
new Categories(
new Category(
new CategoryID('0.50.1.0.1')
)
)
);

$actual = $this->denormalizer->denormalize($eventData, ImmutableEvent::class);

$this->assertEquals($expected, $actual);
}

/**
* @test
*/
Expand Down
122 changes: 122 additions & 0 deletions tests/Model/Serializer/Place/PlaceDenormalizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -968,6 +968,128 @@ public function it_should_denormalize_place_data_with_optional_properties(): voi
$this->assertEquals($expected, $actual);
}

/**
* @test
*/
public function it_handles_place_with_invalid_organizer_id(): void
{
$placeData = [
'@id' => 'https://io.uitdatabank.be/place/9f34efc7-a528-4ea8-a53e-a183f21abbab',
'@type' => 'Place',
'@context' => '/contexts/place',
'mainLanguage' => 'nl',
'name' => [
'nl' => 'Titel voorbeeld',
],
'address' => [
'nl' => [
'streetAddress' => 'Henegouwenkaai 41-43',
'postalCode' => '1080',
'addressLocality' => 'Brussel',
'addressCountry' => 'BE',
],
],
'calendarType' => 'permanent',
'terms' => [
[
'id' => '0.50.1.0.1',
],
],
'organizer' => [
'@id' => 'Invalid id',
],
];

$expected = new ImmutablePlace(
new UUID('9f34efc7-a528-4ea8-a53e-a183f21abbab'),
new Language('nl'),
new TranslatedTitle(
new Language('nl'),
new Title('Titel voorbeeld')
),
new PermanentCalendar(new OpeningHours()),
new TranslatedAddress(
new Language('nl'),
new Address(
new Street('Henegouwenkaai 41-43'),
new PostalCode('1080'),
new Locality('Brussel'),
new CountryCode('BE')
)
),
new Categories(
new Category(
new CategoryID('0.50.1.0.1')
)
)
);

$actual = $this->denormalizer->denormalize($placeData, ImmutablePlace::class);

$this->assertEquals($expected, $actual);
}

/**
* @test
*/
public function it_handles_place_with_organizer_with_missing_id(): void
{
$placeData = [
'@id' => 'https://io.uitdatabank.be/place/9f34efc7-a528-4ea8-a53e-a183f21abbab',
'@type' => 'Place',
'@context' => '/contexts/place',
'mainLanguage' => 'nl',
'name' => [
'nl' => 'Titel voorbeeld',
],
'address' => [
'nl' => [
'streetAddress' => 'Henegouwenkaai 41-43',
'postalCode' => '1080',
'addressLocality' => 'Brussel',
'addressCountry' => 'BE',
],
],
'calendarType' => 'permanent',
'terms' => [
[
'id' => '0.50.1.0.1',
],
],
'organizer' => [
'id' => 'https://io.uitdatabank.be/organizers/236f736e-5308-4c3a-94f3-da0bd768da7d',
],
];

$expected = new ImmutablePlace(
new UUID('9f34efc7-a528-4ea8-a53e-a183f21abbab'),
new Language('nl'),
new TranslatedTitle(
new Language('nl'),
new Title('Titel voorbeeld')
),
new PermanentCalendar(new OpeningHours()),
new TranslatedAddress(
new Language('nl'),
new Address(
new Street('Henegouwenkaai 41-43'),
new PostalCode('1080'),
new Locality('Brussel'),
new CountryCode('BE')
)
),
new Categories(
new Category(
new CategoryID('0.50.1.0.1')
)
)
);

$actual = $this->denormalizer->denormalize($placeData, ImmutablePlace::class);

$this->assertEquals($expected, $actual);
}

/**
* @test
*/
Expand Down

0 comments on commit d5ef9e9

Please sign in to comment.