Handle relation to single "containedInPlace"

Only multiple containedInPlace were supported.
Some instances only have a single containedInPlace. This is now handled
as well.
This commit is contained in:
Daniel Siepmann 2021-05-10 09:34:38 +02:00
parent bbf7ada1d2
commit 22932545d3
2 changed files with 35 additions and 1 deletions

View file

@ -88,6 +88,12 @@ class Parser
*/ */
public function getContainedInPlaceIds(array $jsonLD): array public function getContainedInPlaceIds(array $jsonLD): array
{ {
if (isset($jsonLD['schema:containedInPlace']['@id'])) {
return [
$jsonLD['schema:containedInPlace']['@id'],
];
}
return array_map(function (array $place) { return array_map(function (array $place) {
return $place['@id']; return $place['@id'];
}, $jsonLD['schema:containedInPlace']); }, $jsonLD['schema:containedInPlace']);

View file

@ -178,7 +178,7 @@ class ParserTest extends TestCase
/** /**
* @test * @test
*/ */
public function returnsContainedInPlaceIds(): void public function returnsContainedInPlaceIdsForMultipleEntries(): void
{ {
$genericFields = $this->prophesize(GenericFields::class); $genericFields = $this->prophesize(GenericFields::class);
$openingHours = $this->prophesize(OpeningHours::class); $openingHours = $this->prophesize(OpeningHours::class);
@ -211,6 +211,34 @@ class ParserTest extends TestCase
], $result); ], $result);
} }
/**
* @test
*/
public function returnsContainedInPlaceIdsForSingleEntry(): void
{
$genericFields = $this->prophesize(GenericFields::class);
$openingHours = $this->prophesize(OpeningHours::class);
$address = $this->prophesize(Address::class);
$media = $this->prophesize(Media::class);
$subject = new Parser(
$genericFields->reveal(),
$openingHours->reveal(),
$address->reveal(),
$media->reveal()
);
$result = $subject->getContainedInPlaceIds([
'schema:containedInPlace' => [
'@id' => 'https://thuecat.org/resources/043064193523-jcyt',
],
]);
self::assertSame([
'https://thuecat.org/resources/043064193523-jcyt',
], $result);
}
/** /**
* @test * @test
*/ */