Skip to content

Commit

Permalink
fix review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
wachterjohannes committed Nov 18, 2019
1 parent effa69c commit 8448d1e
Show file tree
Hide file tree
Showing 13 changed files with 884 additions and 33 deletions.
21 changes: 16 additions & 5 deletions Content/Application/ContentDimensionFactory/Mapper/RouteMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

namespace Sulu\Bundle\ContentBundle\Content\Application\ContentDimensionFactory\Mapper;

use Sulu\Bundle\ContentBundle\Content\Domain\Model\ContentDimensionInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\RoutableInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\TemplateInterface;
use Sulu\Bundle\RouteBundle\Generator\RouteGeneratorInterface;
use Sulu\Bundle\RouteBundle\Manager\RouteManagerInterface;
use Sulu\Component\Content\Metadata\Factory\StructureMetadataFactoryInterface;
Expand Down Expand Up @@ -53,10 +53,14 @@ public function map(
object $contentDimension,
?object $localizedContentDimension = null
): void {
if (!$localizedContentDimension || !$localizedContentDimension instanceof RoutableInterface || !$localizedContentDimension instanceof ContentDimensionInterface) {
if (!$localizedContentDimension || !$localizedContentDimension instanceof RoutableInterface) {
return;
}

if (!$localizedContentDimension instanceof TemplateInterface) {
throw new \RuntimeException('ContentDimension needs to extend the TemplateInterface');
}

if (!isset($data['template'])) {
throw new \RuntimeException('Expected "template" to be set in the data array.');
}
Expand All @@ -80,13 +84,20 @@ public function map(
return;
}

$locale = $localizedContentDimension->getDimension()->getLocale();
$locale = $localizedContentDimension->getLocale();
if (!$locale) {
return;
}

$routePath = $data[$property->getName()] ?? null;
/** @var string $name */
$name = $property->getName();
if (!\array_key_exists($name, $data)) {
return;
}

$routePath = $data[$name] ?? null;
if (!$routePath) {
// FIXME this should be handled directly in the form - see pages as an example
$routePath = $this->routeGenerator->generate(
$localizedContentDimension,
['route_schema' => '/{object.getTitle()}']
Expand All @@ -95,7 +106,7 @@ public function map(
$localizedContentDimension->setTemplateData(
array_merge(
$localizedContentDimension->getTemplateData(),
[$property->getName() => $routePath]
[$name => $routePath]
)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ private function getTemplateData(array $data, string $type, string $template): a
$name = (string) $name;
}

if (array_key_exists($name, $data)) {
if (\array_key_exists($name, $data)) {
$value = $data[$name];
}

Expand Down
4 changes: 3 additions & 1 deletion Content/Domain/Model/RoutableInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@
/**
* Marker interface for autoloading the doctrine metadata for routables.
*/
interface RoutableInterface extends TemplateInterface
interface RoutableInterface
{
public function getContentClass(): string;

/**
* @return mixed
*/
public function getContentId();

public function getLocale(): ?string;
}
24 changes: 24 additions & 0 deletions Content/Domain/Model/RoutableTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

/*
* This file is part of Sulu.
*
* (c) Sulu GmbH
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

namespace Sulu\Bundle\ContentBundle\Content\Domain\Model;

trait RoutableTrait
{
public function getLocale(): ?string
{
return $this->getDimension()->getLocale();
}

abstract public function getDimension(): DimensionInterface;
}
8 changes: 5 additions & 3 deletions Content/Infrastructure/Sulu/Route/ContentDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@
use Sulu\Bundle\ContentBundle\Content\Domain\Model\TemplateInterface;
use Sulu\Component\Content\Document\Behavior\ExtensionBehavior;

/**
* @codeCoverageIgnore
*/
class ContentDocument implements ExtensionBehavior
{
/**
Expand All @@ -39,6 +36,11 @@ public function __construct(TemplateInterface $content, string $locale)
$this->locale = $locale;
}

public function getContent(): TemplateInterface
{
return $this->content;
}

/**
* @return mixed[]
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ protected function loadEntity(string $entityClass, string $id, string $locale):
}

try {
// FIXME use the live workflow-stage when publishing is implemented

return $this->handle(
new LoadContentViewMessage($content, ['locale' => $locale, 'workflowStage' => 'draft'])
);
Expand Down
5 changes: 1 addition & 4 deletions Content/Infrastructure/Sulu/Route/ContentStructureBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@
use Sulu\Component\Content\Metadata\PropertyMetadata;
use Sulu\Component\Content\Metadata\StructureMetadata;

/**
* @codeCoverageIgnore
*/
class ContentStructureBridge implements StructureInterface
{
/**
Expand Down Expand Up @@ -87,7 +84,7 @@ public function getContent(): TemplateInterface

public function setLanguageCode($locale): void
{
$this->locale = $locale;
$this->readOnlyException(__METHOD__);
}

public function getLanguageCode(): string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Sulu\Bundle\ContentBundle\Content\Domain\Model\ExcerptInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\ExcerptTrait;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\RoutableInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\RoutableTrait;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\SeoInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\SeoTrait;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\TemplateInterface;
Expand All @@ -32,6 +33,7 @@ class ExampleDimension extends AbstractContentDimension implements ExcerptInterf
getTemplateData as parentGetTemplateData;
setTemplateData as parentSetTemplateData;
}
use RoutableTrait;

/**
* @var Example
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
use Prophecy\Argument;
use Sulu\Bundle\ContentBundle\Content\Application\ContentDimensionFactory\Mapper\RouteMapper;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\ContentDimensionInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\RoutableInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\TemplateInterface;
use Sulu\Bundle\RouteBundle\Generator\RouteGeneratorInterface;
use Sulu\Bundle\RouteBundle\Manager\RouteManagerInterface;
use Sulu\Component\Content\Metadata\Factory\StructureMetadataFactoryInterface;
Expand Down Expand Up @@ -89,6 +89,7 @@ public function testMapNoTemplate(): void
$contentDimension = $this->prophesize(ContentDimensionInterface::class);
$localizedContentDimension = $this->prophesize(ContentDimensionInterface::class);
$localizedContentDimension->willImplement(RoutableInterface::class);
$localizedContentDimension->willImplement(TemplateInterface::class);

$factory = $this->prophesize(StructureMetadataFactoryInterface::class);
$routeGenerator = $this->prophesize(RouteGeneratorInterface::class);
Expand Down Expand Up @@ -116,6 +117,7 @@ public function testMapNoMetadata(): void
$contentDimension = $this->prophesize(ContentDimensionInterface::class);
$localizedContentDimension = $this->prophesize(ContentDimensionInterface::class);
$localizedContentDimension->willImplement(RoutableInterface::class);
$localizedContentDimension->willImplement(TemplateInterface::class);

$factory = $this->prophesize(StructureMetadataFactoryInterface::class);
$routeGenerator = $this->prophesize(RouteGeneratorInterface::class);
Expand Down Expand Up @@ -144,6 +146,7 @@ public function testMapNoRouteProperty(): void
$contentDimension = $this->prophesize(ContentDimensionInterface::class);
$localizedContentDimension = $this->prophesize(ContentDimensionInterface::class);
$localizedContentDimension->willImplement(RoutableInterface::class);
$localizedContentDimension->willImplement(TemplateInterface::class);

$factory = $this->prophesize(StructureMetadataFactoryInterface::class);
$routeGenerator = $this->prophesize(RouteGeneratorInterface::class);
Expand Down Expand Up @@ -178,6 +181,7 @@ public function testMapNoContentId(): void
$contentDimension = $this->prophesize(ContentDimensionInterface::class);
$localizedContentDimension = $this->prophesize(ContentDimensionInterface::class);
$localizedContentDimension->willImplement(RoutableInterface::class);
$localizedContentDimension->willImplement(TemplateInterface::class);

$factory = $this->prophesize(StructureMetadataFactoryInterface::class);
$routeGenerator = $this->prophesize(RouteGeneratorInterface::class);
Expand Down Expand Up @@ -214,6 +218,7 @@ public function testMapNoLocale(): void
$contentDimension = $this->prophesize(ContentDimensionInterface::class);
$localizedContentDimension = $this->prophesize(ContentDimensionInterface::class);
$localizedContentDimension->willImplement(RoutableInterface::class);
$localizedContentDimension->willImplement(TemplateInterface::class);

$factory = $this->prophesize(StructureMetadataFactoryInterface::class);
$routeGenerator = $this->prophesize(RouteGeneratorInterface::class);
Expand All @@ -231,11 +236,7 @@ public function testMapNoLocale(): void
$factory->getStructureMetadata('example', 'default')->willReturn($metadata->reveal())->shouldBeCalled();

$localizedContentDimension->getContentId()->willReturn('123-123-123');

$dimension = $this->prophesize(DimensionInterface::class);
$dimension->getLocale()->willReturn(null);

$localizedContentDimension->getDimension()->willReturn($dimension->reveal())->shouldBeCalled();
$localizedContentDimension->getLocale()->willReturn(null);

$mapper = $this->createRouteMapperInstance(
$factory->reveal(),
Expand All @@ -250,11 +251,13 @@ public function testMapNoRoutePath(): void
{
$data = [
'template' => 'default',
'url' => null,
];

$contentDimension = $this->prophesize(ContentDimensionInterface::class);
$localizedContentDimension = $this->prophesize(ContentDimensionInterface::class);
$localizedContentDimension->willImplement(RoutableInterface::class);
$localizedContentDimension->willImplement(TemplateInterface::class);

$factory = $this->prophesize(StructureMetadataFactoryInterface::class);
$routeGenerator = $this->prophesize(RouteGeneratorInterface::class);
Expand All @@ -276,10 +279,7 @@ public function testMapNoRoutePath(): void
$localizedContentDimension->getTemplateData()->willReturn(['title' => 'Test', 'url' => null]);
$localizedContentDimension->setTemplateData(['title' => 'Test', 'url' => '/test'])->shouldBeCalled();

$dimension = $this->prophesize(DimensionInterface::class);
$dimension->getLocale()->willReturn('en');

$localizedContentDimension->getDimension()->willReturn($dimension->reveal())->shouldBeCalled();
$localizedContentDimension->getLocale()->willReturn('en');

$routeGenerator->generate($localizedContentDimension, ['route_schema' => '/{object.getTitle()}'])
->willReturn('/test');
Expand Down Expand Up @@ -310,6 +310,7 @@ public function testMap(): void
$contentDimension = $this->prophesize(ContentDimensionInterface::class);
$localizedContentDimension = $this->prophesize(ContentDimensionInterface::class);
$localizedContentDimension->willImplement(RoutableInterface::class);
$localizedContentDimension->willImplement(TemplateInterface::class);

$factory = $this->prophesize(StructureMetadataFactoryInterface::class);
$routeGenerator = $this->prophesize(RouteGeneratorInterface::class);
Expand All @@ -327,11 +328,7 @@ public function testMap(): void

$localizedContentDimension->getContentId()->willReturn('123-123-123');
$localizedContentDimension->getContentClass()->willReturn('App\Entity\Example');

$dimension = $this->prophesize(DimensionInterface::class);
$dimension->getLocale()->willReturn('en');

$localizedContentDimension->getDimension()->willReturn($dimension->reveal())->shouldBeCalled();
$localizedContentDimension->getLocale()->willReturn('en');

$routeGenerator->generate($localizedContentDimension, ['schema' => '/{object.getTitle()}'])
->shouldNotBeCalled();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,19 +103,19 @@ public function testInvalidMetadata(array $interfaces, array $fields, array $man
$entityManager = $this->prophesize(EntityManager::class);
$entityManager->getConfiguration()->willReturn($configuration->reveal());

if (array_key_exists('dimension', $manyToOneAssociations) && !$manyToOneAssociations['dimension']) {
if (\array_key_exists('dimension', $manyToOneAssociations) && !$manyToOneAssociations['dimension']) {
$dimensionClassMetadata = $this->prophesize(ClassMetadata::class);
$dimensionClassMetadata->getIdentifierColumnNames()->willReturn(['id'])->shouldBeCalled();
$entityManager->getClassMetadata(DimensionInterface::class)->willReturn($dimensionClassMetadata->reveal());
}

if (array_key_exists('excerptTags', $manyToManyAssociations) && !$manyToManyAssociations['excerptTags']) {
if (\array_key_exists('excerptTags', $manyToManyAssociations) && !$manyToManyAssociations['excerptTags']) {
$tagClassMetadata = $this->prophesize(ClassMetadata::class);
$tagClassMetadata->getIdentifierColumnNames()->willReturn(['id'])->shouldBeCalled();
$entityManager->getClassMetadata(TagInterface::class)->willReturn($tagClassMetadata->reveal());
}

if (array_key_exists('excerptCategories', $manyToManyAssociations) && !$manyToManyAssociations['excerptCategories']) {
if (\array_key_exists('excerptCategories', $manyToManyAssociations) && !$manyToManyAssociations['excerptCategories']) {
$categoryClassMetadata = $this->prophesize(ClassMetadata::class);
$categoryClassMetadata->getIdentifierColumnNames()->willReturn(['id'])->shouldBeCalled();
$entityManager->getClassMetadata(CategoryInterface::class)->willReturn($categoryClassMetadata->reveal());
Expand Down
Loading

0 comments on commit 8448d1e

Please sign in to comment.