Skip to content

Commit

Permalink
Merge d78539b into 3400ed4
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-schranz committed Oct 14, 2021
2 parents 3400ed4 + d78539b commit e0fc36c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

0 comments on commit e0fc36c

Please sign in to comment.