Skip to content

Commit

Permalink
add usage of tag 'sulu.rlp' to detect route property
Browse files Browse the repository at this point in the history
  • Loading branch information
wachterjohannes committed Sep 30, 2021
1 parent 817d852 commit 10feff2
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ public function map(
private function getRouteProperty(StructureMetadata $metadata): ?PropertyMetadata
{
foreach ($metadata->getProperties() as $property) {
if ('route' === $property->getType()) {
if ('route' === $property->getType() || $property->hasTag('sulu.rlp')) {
return $property;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ public function testMapNoRouteProperty(): void
$property = $this->prophesize(PropertyMetadata::class);
$property->getType()->willReturn('text_line');
$property->getName()->willReturn('url');
$property->hasTag('sulu.rlp')->willReturn(false);

$metadata->getProperties()->WillReturn([$property->reveal()]);

Expand Down Expand Up @@ -732,6 +733,68 @@ public function testMap(): void
$mapper->map($data, $dimensionContentCollection->reveal());
}

public function testMapDifferentType(): void
{
$data = [
'template' => 'default',
'url' => '/test',
];

$unlocalizedDimensionContent = $this->prophesize(DimensionContentInterface::class);
$localizedDimensionContent = $this->prophesize(DimensionContentInterface::class);
$localizedDimensionContent->willImplement(RoutableInterface::class);
$localizedDimensionContent->willImplement(TemplateInterface::class);

$dimensionContentCollection = $this->prophesize(DimensionContentCollectionInterface::class);
$dimensionContentCollection->getDimensionAttributes()->willReturn(['stage' => 'draft', 'locale' => 'de']);
$dimensionContentCollection->getDimensionContent(['stage' => 'draft', 'locale' => null])
->willReturn($unlocalizedDimensionContent);
$dimensionContentCollection->getDimensionContent(['stage' => 'draft', 'locale' => 'de'])
->willReturn($this->wrapRoutableMock($localizedDimensionContent));

$factory = $this->prophesize(StructureMetadataFactoryInterface::class);
$routeGenerator = $this->prophesize(RouteGeneratorInterface::class);
$routeManager = $this->prophesize(RouteManagerInterface::class);
$conflictResolver = $this->prophesize(ConflictResolverInterface::class);

$metadata = $this->prophesize(StructureMetadata::class);
$property = $this->prophesize(PropertyMetadata::class);
$property->getType()->willReturn('test_line');
$property->getName()->willReturn('url');
$property->hasTag('sulu.rlp')->willReturn(true);

$metadata->getProperties()->WillReturn([$property->reveal()]);

$localizedDimensionContent->getTemplateData()->willReturn([]);
$factory->getStructureMetadata('mock-template-type', 'default')->willReturn($metadata->reveal())->shouldBeCalled();

$localizedDimensionContent->getResourceId()->willReturn('123-123-123');
$localizedDimensionContent->getLocale()->willReturn('en');

$routeGenerator->generate(Argument::any())->shouldNotBeCalled();

$route = $this->prophesize(RouteInterface::class);
$route->getPath()->willReturn('/test');
$routeManager->createOrUpdateByAttributes(
'mock-content-class',
'123-123-123',
'en',
'/test'
)->willReturn($route->reveal());

$conflictResolver->resolve($route->reveal())->shouldBeCalled();
$localizedDimensionContent->setTemplateData(Argument::cetera())->shouldNotBeCalled();

$mapper = $this->createRouteDataMapperInstance(
$factory->reveal(),
$routeGenerator->reveal(),
$routeManager->reveal(),
$conflictResolver->reveal()
);

$mapper->map($data, $dimensionContentCollection->reveal());
}

public function testMapConflictingRoute(): void
{
$data = [
Expand Down

0 comments on commit 10feff2

Please sign in to comment.