From 265cb27236eba3d5f3749fce3d4b2246664a4059 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Tue, 31 Aug 2021 08:10:46 +0200 Subject: [PATCH] Support multiple provided URLs An object might have more then a single URL. This is now added. --- Classes/Domain/Import/Entity/Minimum.php | 16 +++--- .../Typo3Converter/GeneralConverter.php | 2 +- .../Import/EntityMapping/BaseInfosTest.php | 4 +- .../Import/EntityMapping/PlaceInfosTest.php | 51 +++++++++++++++++++ 4 files changed, 64 insertions(+), 9 deletions(-) diff --git a/Classes/Domain/Import/Entity/Minimum.php b/Classes/Domain/Import/Entity/Minimum.php index a553af0..32dc453 100644 --- a/Classes/Domain/Import/Entity/Minimum.php +++ b/Classes/Domain/Import/Entity/Minimum.php @@ -53,9 +53,9 @@ abstract class Minimum /** * URL to official version of this thing outside of ThüCAT. * - * @var string + * @var string[] */ - protected $url = ''; + protected $urls = []; public function getId(): string { @@ -77,9 +77,9 @@ abstract class Minimum return $this->description; } - public function getUrl(): string + public function getUrls(): array { - return $this->url; + return $this->urls; } /** @@ -108,10 +108,14 @@ abstract class Minimum /** * @internal for mapping via Symfony component. + * @param string|array $url */ - public function setUrl(string $url): void + public function setUrl($url): void { - $this->url = $url; + if (is_string($url)) { + $url = [$url]; + } + $this->urls = $url; } public static function getPriority(): int diff --git a/Classes/Domain/Import/Typo3Converter/GeneralConverter.php b/Classes/Domain/Import/Typo3Converter/GeneralConverter.php index 86d8026..21b3b63 100644 --- a/Classes/Domain/Import/Typo3Converter/GeneralConverter.php +++ b/Classes/Domain/Import/Typo3Converter/GeneralConverter.php @@ -325,7 +325,7 @@ class GeneralConverter implements Converter 'type' => $mediaObject->getType(), 'title' => $mediaObject->getName(), 'description' => $mediaObject->getDescription(), - 'url' => $mediaObject->getUrl(), + 'url' => $mediaObject->getUrls()[0] ?? '', 'copyrightYear' => $mediaObject->getCopyrightYear(), 'license' => [ 'type' => $mediaObject->getLicense(), diff --git a/Tests/Functional/Import/EntityMapping/BaseInfosTest.php b/Tests/Functional/Import/EntityMapping/BaseInfosTest.php index 24e4193..e9d46d8 100644 --- a/Tests/Functional/Import/EntityMapping/BaseInfosTest.php +++ b/Tests/Functional/Import/EntityMapping/BaseInfosTest.php @@ -68,7 +68,7 @@ class BaseInfosTest extends TestCase self::assertSame('', $result->getId()); self::assertSame('', $result->getName()); self::assertSame('', $result->getDescription()); - self::assertSame('', $result->getUrl()); + self::assertSame([], $result->getUrls()); self::assertNull($result->getPhoto()); self::assertSame([], $result->getImages()); self::assertNull($result->getManagedBy()); @@ -94,7 +94,7 @@ class BaseInfosTest extends TestCase self::assertSame('https://thuecat.org/resources/835224016581-dara', $result->getId()); self::assertSame('The name of the Thing', $result->getName()); self::assertSame('This is some long description describing this Thing.', $result->getDescription()); - self::assertSame('https://example.com/the-thing', $result->getUrl()); + self::assertSame(['https://example.com/the-thing'], $result->getUrls()); } /** diff --git a/Tests/Functional/Import/EntityMapping/PlaceInfosTest.php b/Tests/Functional/Import/EntityMapping/PlaceInfosTest.php index 064336a..c9f18dd 100644 --- a/Tests/Functional/Import/EntityMapping/PlaceInfosTest.php +++ b/Tests/Functional/Import/EntityMapping/PlaceInfosTest.php @@ -236,4 +236,55 @@ class PlaceInfosTest extends TestCase self::assertSame('', $result->getAddress()->getFaxNumber()); self::assertSame('dominformation@domberg-erfurt.de', $result->getAddress()->getEmail()); } + + /** + * @test + */ + public function mapsIncomingMultipleUrls(): void + { + $subject = new EntityMapper(); + + $result = $subject->mapDataToEntity([ + 'schema:url' => [ + 0 => [ + '@type' => 'schema:URL', + '@value' => 'https://example.com/1', + ], + 1 => [ + '@type' => 'schema:URL', + '@value' => 'https://example.com/2', + ], + ], + ], Place::class, [ + JsonDecode::ACTIVE_LANGUAGE => 'de', + ]); + + self::assertInstanceOf(Place::class, $result); + self::assertSame([ + 'https://example.com/1', + 'https://example.com/2', + ], $result->getUrls()); + } + + /** + * @test + */ + public function mapsIncomingSingleUrl(): void + { + $subject = new EntityMapper(); + + $result = $subject->mapDataToEntity([ + 'schema:url' => [ + '@type' => 'schema:URL', + '@value' => 'https://example.com/1', + ], + ], Place::class, [ + JsonDecode::ACTIVE_LANGUAGE => 'de', + ]); + + self::assertInstanceOf(Place::class, $result); + self::assertSame([ + 'https://example.com/1', + ], $result->getUrls()); + } }