From 22932545d3f91b042bb804fa60d1dd35ad93ca35 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Mon, 10 May 2021 09:34:38 +0200 Subject: [PATCH] Handle relation to single "containedInPlace" Only multiple containedInPlace were supported. Some instances only have a single containedInPlace. This is now handled as well. --- Classes/Domain/Import/JsonLD/Parser.php | 6 ++++ .../Unit/Domain/Import/JsonLD/ParserTest.php | 30 ++++++++++++++++++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/Classes/Domain/Import/JsonLD/Parser.php b/Classes/Domain/Import/JsonLD/Parser.php index 3d01c27..e093d23 100644 --- a/Classes/Domain/Import/JsonLD/Parser.php +++ b/Classes/Domain/Import/JsonLD/Parser.php @@ -88,6 +88,12 @@ class Parser */ public function getContainedInPlaceIds(array $jsonLD): array { + if (isset($jsonLD['schema:containedInPlace']['@id'])) { + return [ + $jsonLD['schema:containedInPlace']['@id'], + ]; + } + return array_map(function (array $place) { return $place['@id']; }, $jsonLD['schema:containedInPlace']); diff --git a/Tests/Unit/Domain/Import/JsonLD/ParserTest.php b/Tests/Unit/Domain/Import/JsonLD/ParserTest.php index 08b559d..0a30b36 100644 --- a/Tests/Unit/Domain/Import/JsonLD/ParserTest.php +++ b/Tests/Unit/Domain/Import/JsonLD/ParserTest.php @@ -178,7 +178,7 @@ class ParserTest extends TestCase /** * @test */ - public function returnsContainedInPlaceIds(): void + public function returnsContainedInPlaceIdsForMultipleEntries(): void { $genericFields = $this->prophesize(GenericFields::class); $openingHours = $this->prophesize(OpeningHours::class); @@ -211,6 +211,34 @@ class ParserTest extends TestCase ], $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 */