diff --git a/Content/Application/ContentDataMapper/DataMapper/AuthorDataMapper.php b/Content/Application/ContentDataMapper/DataMapper/AuthorDataMapper.php index a01e64e1..f4bf7cf7 100644 --- a/Content/Application/ContentDataMapper/DataMapper/AuthorDataMapper.php +++ b/Content/Application/ContentDataMapper/DataMapper/AuthorDataMapper.php @@ -47,11 +47,19 @@ public function map( private function setAuthorData(AuthorInterface $dimensionContent, array $data): void { if (\array_key_exists('author', $data)) { - $dimensionContent->setAuthor($this->contactFactory->create($data['author'])); + $dimensionContent->setAuthor( + $data['author'] + ? $this->contactFactory->create($data['author']) + : null + ); } if (\array_key_exists('authored', $data)) { - $dimensionContent->setAuthored(new \DateTimeImmutable($data['authored'])); + $dimensionContent->setAuthored( + $data['authored'] + ? new \DateTimeImmutable($data['authored']) + : null + ); } } } diff --git a/Tests/Unit/Content/Application/ContentDataMapper/DataMapper/AuthorDataMapperTest.php b/Tests/Unit/Content/Application/ContentDataMapper/DataMapper/AuthorDataMapperTest.php index f578c267..e3af297b 100644 --- a/Tests/Unit/Content/Application/ContentDataMapper/DataMapper/AuthorDataMapperTest.php +++ b/Tests/Unit/Content/Application/ContentDataMapper/DataMapper/AuthorDataMapperTest.php @@ -100,4 +100,27 @@ public function testMapData(): void $this->assertNotNull($authored); $this->assertSame('2020-05-08T00:00:00+00:00', $authored->format('c')); } + + public function testMapDataNull(): void + { + $data = [ + 'author' => null, + 'authored' => null, + ]; + + $example = new Example(); + $unlocalizedDimensionContent = new ExampleDimensionContent($example); + $localizedDimensionContent = new ExampleDimensionContent($example); + $localizedDimensionContent->setAuthor(new Contact()); + $localizedDimensionContent->setAuthored(new \DateTimeImmutable()); + + $this->contactFactory->create(Argument::cetera()) + ->shouldNotBeCalled(); + + $authorMapper = $this->createAuthorDataMapperInstance(); + $authorMapper->map($unlocalizedDimensionContent, $localizedDimensionContent, $data); + + $this->assertNull($localizedDimensionContent->getAuthor()); + $this->assertNull($localizedDimensionContent->getAuthored()); + } }