From 3b40e7b6c92f65461af93ce657a2dc7b44801515 Mon Sep 17 00:00:00 2001 From: nnatter Date: Tue, 19 May 2020 18:21:38 +0200 Subject: [PATCH] Add constants for keys of ContentWorkflow transition context (#143) --- .../ContentWorkflow/ContentWorkflow.php | 6 ++--- .../ContentWorkflowInterface.php | 4 +++ .../PublishTransitionSubscriber.php | 7 +++--- .../RemoveDraftTransitionSubscriber.php | 5 ++-- .../UnpublishTransitionSubscriber.php | 5 ++-- .../Sulu/Sitemap/ContentSitemapProvider.php | 3 ++- .../Sulu/Teaser/ContentTeaserProvider.php | 3 ++- .../PublishTransitionSubscriberTest.php | 25 ++++++++++--------- .../RemoveDraftTransitionSubscriberTest.php | 9 ++++--- .../UnpublishTransitionSubscriberTest.php | 17 +++++++------ 10 files changed, 48 insertions(+), 36 deletions(-) diff --git a/Content/Application/ContentWorkflow/ContentWorkflow.php b/Content/Application/ContentWorkflow/ContentWorkflow.php index 3ec021ce..3cff46ae 100644 --- a/Content/Application/ContentWorkflow/ContentWorkflow.php +++ b/Content/Application/ContentWorkflow/ContentWorkflow.php @@ -118,9 +118,9 @@ public function apply( try { $workflow->apply($localizedDimensionContent, $transitionName, [ - 'contentRichEntity' => $contentRichEntity, - 'dimensionContentCollection' => $dimensionContentCollection, - 'dimensionAttributes' => $dimensionAttributes, + ContentWorkflowInterface::CONTENT_RICH_ENTITY_CONTEXT_KEY => $contentRichEntity, + ContentWorkflowInterface::DIMENSION_CONTENT_COLLECTION_CONTEXT_KEY => $dimensionContentCollection, + ContentWorkflowInterface::DIMENSION_ATTRIBUTES_CONTEXT_KEY => $dimensionAttributes, ]); } catch (UndefinedTransitionException $e) { throw new UnknownContentTransitionException($e->getMessage(), $e->getCode(), $e); diff --git a/Content/Application/ContentWorkflow/ContentWorkflowInterface.php b/Content/Application/ContentWorkflow/ContentWorkflowInterface.php index fdafa81a..19d3e6c1 100644 --- a/Content/Application/ContentWorkflow/ContentWorkflowInterface.php +++ b/Content/Application/ContentWorkflow/ContentWorkflowInterface.php @@ -18,6 +18,10 @@ interface ContentWorkflowInterface { + const CONTENT_RICH_ENTITY_CONTEXT_KEY = 'contentRichEntity'; + const DIMENSION_CONTENT_COLLECTION_CONTEXT_KEY = 'dimensionContentCollection'; + const DIMENSION_ATTRIBUTES_CONTEXT_KEY = 'dimensionAttributes'; + /** * @param mixed[] $dimensionAttributes */ diff --git a/Content/Application/ContentWorkflow/Subscriber/PublishTransitionSubscriber.php b/Content/Application/ContentWorkflow/Subscriber/PublishTransitionSubscriber.php index 4ec97737..a2fc3493 100644 --- a/Content/Application/ContentWorkflow/Subscriber/PublishTransitionSubscriber.php +++ b/Content/Application/ContentWorkflow/Subscriber/PublishTransitionSubscriber.php @@ -14,6 +14,7 @@ namespace Sulu\Bundle\ContentBundle\Content\Application\ContentWorkflow\Subscriber; use Sulu\Bundle\ContentBundle\Content\Application\ContentCopier\ContentCopierInterface; +use Sulu\Bundle\ContentBundle\Content\Application\ContentWorkflow\ContentWorkflowInterface; use Sulu\Bundle\ContentBundle\Content\Domain\Model\ContentRichEntityInterface; use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentCollectionInterface; use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentInterface; @@ -50,9 +51,9 @@ public function onPublish(TransitionEvent $transitionEvent): void $context = $transitionEvent->getContext(); - $dimensionContentCollection = $context['dimensionContentCollection'] ?? null; - $dimensionAttributes = $context['dimensionAttributes'] ?? null; - $contentRichEntity = $context['contentRichEntity'] ?? null; + $dimensionContentCollection = $context[ContentWorkflowInterface::DIMENSION_CONTENT_COLLECTION_CONTEXT_KEY] ?? null; + $dimensionAttributes = $context[ContentWorkflowInterface::DIMENSION_ATTRIBUTES_CONTEXT_KEY] ?? null; + $contentRichEntity = $context[ContentWorkflowInterface::CONTENT_RICH_ENTITY_CONTEXT_KEY] ?? null; if (!$dimensionAttributes) { throw new \RuntimeException('No "dimensionAttributes" given.'); diff --git a/Content/Application/ContentWorkflow/Subscriber/RemoveDraftTransitionSubscriber.php b/Content/Application/ContentWorkflow/Subscriber/RemoveDraftTransitionSubscriber.php index d1620a55..07e268c0 100644 --- a/Content/Application/ContentWorkflow/Subscriber/RemoveDraftTransitionSubscriber.php +++ b/Content/Application/ContentWorkflow/Subscriber/RemoveDraftTransitionSubscriber.php @@ -14,6 +14,7 @@ namespace Sulu\Bundle\ContentBundle\Content\Application\ContentWorkflow\Subscriber; use Sulu\Bundle\ContentBundle\Content\Application\ContentCopier\ContentCopierInterface; +use Sulu\Bundle\ContentBundle\Content\Application\ContentWorkflow\ContentWorkflowInterface; use Sulu\Bundle\ContentBundle\Content\Domain\Model\ContentRichEntityInterface; use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentInterface; use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionInterface; @@ -41,12 +42,12 @@ public function onRemoveDraft(TransitionEvent $transitionEvent): void $context = $transitionEvent->getContext(); - $dimensionAttributes = $context['dimensionAttributes'] ?? null; + $dimensionAttributes = $context[ContentWorkflowInterface::DIMENSION_ATTRIBUTES_CONTEXT_KEY] ?? null; if (!$dimensionAttributes) { throw new \RuntimeException('Transition context must contain "dimensionAttributes".'); } - $contentRichEntity = $context['contentRichEntity'] ?? null; + $contentRichEntity = $context[ContentWorkflowInterface::CONTENT_RICH_ENTITY_CONTEXT_KEY] ?? null; if (!$contentRichEntity instanceof ContentRichEntityInterface) { throw new \RuntimeException('Transition context must contain "contentRichEntity".'); } diff --git a/Content/Application/ContentWorkflow/Subscriber/UnpublishTransitionSubscriber.php b/Content/Application/ContentWorkflow/Subscriber/UnpublishTransitionSubscriber.php index 01edfb3b..c2b927fe 100644 --- a/Content/Application/ContentWorkflow/Subscriber/UnpublishTransitionSubscriber.php +++ b/Content/Application/ContentWorkflow/Subscriber/UnpublishTransitionSubscriber.php @@ -14,6 +14,7 @@ namespace Sulu\Bundle\ContentBundle\Content\Application\ContentWorkflow\Subscriber; use Doctrine\ORM\EntityManagerInterface; +use Sulu\Bundle\ContentBundle\Content\Application\ContentWorkflow\ContentWorkflowInterface; use Sulu\Bundle\ContentBundle\Content\Domain\Exception\ContentNotFoundException; use Sulu\Bundle\ContentBundle\Content\Domain\Model\ContentRichEntityInterface; use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentInterface; @@ -65,12 +66,12 @@ public function onUnpublish(TransitionEvent $transitionEvent): void $context = $transitionEvent->getContext(); - $dimensionAttributes = $context['dimensionAttributes'] ?? null; + $dimensionAttributes = $context[ContentWorkflowInterface::DIMENSION_ATTRIBUTES_CONTEXT_KEY] ?? null; if (!$dimensionAttributes) { throw new \RuntimeException('Transition context must contain "dimensionAttributes".'); } - $contentRichEntity = $context['contentRichEntity'] ?? null; + $contentRichEntity = $context[ContentWorkflowInterface::CONTENT_RICH_ENTITY_CONTEXT_KEY] ?? null; if (!$contentRichEntity instanceof ContentRichEntityInterface) { throw new \RuntimeException('Transition context must contain "contentRichEntity".'); } diff --git a/Content/Infrastructure/Sulu/Sitemap/ContentSitemapProvider.php b/Content/Infrastructure/Sulu/Sitemap/ContentSitemapProvider.php index 5bd4a73f..6fcccfa1 100644 --- a/Content/Infrastructure/Sulu/Sitemap/ContentSitemapProvider.php +++ b/Content/Infrastructure/Sulu/Sitemap/ContentSitemapProvider.php @@ -18,6 +18,7 @@ use Doctrine\ORM\NoResultException; use Doctrine\ORM\Query\Expr\Join; use Doctrine\ORM\QueryBuilder; +use Sulu\Bundle\ContentBundle\Content\Application\ContentWorkflow\ContentWorkflowInterface; use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionInterface; use Sulu\Bundle\RouteBundle\Model\RouteInterface; use Sulu\Bundle\WebsiteBundle\Sitemap\Sitemap; @@ -31,7 +32,7 @@ class ContentSitemapProvider implements SitemapProviderInterface { const ROUTE_ALIAS = 'route'; - const CONTENT_RICH_ENTITY_ALIAS = 'contentRichEntity'; + const CONTENT_RICH_ENTITY_ALIAS = ContentWorkflowInterface::CONTENT_RICH_ENTITY_CONTEXT_KEY; const LOCALIZED_DIMENSION_CONTENT_ALIAS = 'localizedDimensionContent'; const LOCALIZED_DIMENSION_ALIAS = 'localizedDimension'; diff --git a/Content/Infrastructure/Sulu/Teaser/ContentTeaserProvider.php b/Content/Infrastructure/Sulu/Teaser/ContentTeaserProvider.php index 3973b9d4..44056ab8 100644 --- a/Content/Infrastructure/Sulu/Teaser/ContentTeaserProvider.php +++ b/Content/Infrastructure/Sulu/Teaser/ContentTeaserProvider.php @@ -15,6 +15,7 @@ use Doctrine\ORM\EntityManagerInterface; use Sulu\Bundle\ContentBundle\Content\Application\ContentManager\ContentManagerInterface; +use Sulu\Bundle\ContentBundle\Content\Application\ContentWorkflow\ContentWorkflowInterface; use Sulu\Bundle\ContentBundle\Content\Domain\Exception\ContentNotFoundException; use Sulu\Bundle\ContentBundle\Content\Domain\Model\ContentRichEntityInterface; use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentInterface; @@ -27,7 +28,7 @@ abstract class ContentTeaserProvider implements TeaserProviderInterface { - const CONTENT_RICH_ENTITY_ALIAS = 'contentRichEntity'; + const CONTENT_RICH_ENTITY_ALIAS = ContentWorkflowInterface::CONTENT_RICH_ENTITY_CONTEXT_KEY; /** * @var ContentManagerInterface diff --git a/Tests/Unit/Content/Application/ContentWorkflow/Subscriber/PublishTransitionSubscriberTest.php b/Tests/Unit/Content/Application/ContentWorkflow/Subscriber/PublishTransitionSubscriberTest.php index fe2c691b..21b6a5e2 100644 --- a/Tests/Unit/Content/Application/ContentWorkflow/Subscriber/PublishTransitionSubscriberTest.php +++ b/Tests/Unit/Content/Application/ContentWorkflow/Subscriber/PublishTransitionSubscriberTest.php @@ -16,6 +16,7 @@ use PHPUnit\Framework\TestCase; use Prophecy\Argument; use Sulu\Bundle\ContentBundle\Content\Application\ContentCopier\ContentCopierInterface; +use Sulu\Bundle\ContentBundle\Content\Application\ContentWorkflow\ContentWorkflowInterface; use Sulu\Bundle\ContentBundle\Content\Application\ContentWorkflow\Subscriber\PublishTransitionSubscriber; use Sulu\Bundle\ContentBundle\Content\Domain\Model\ContentRichEntityInterface; use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentCollectionInterface; @@ -72,8 +73,8 @@ public function testOnPublishNoDimensionContentCollection(): void new Marking() ); $event->setContext([ - 'dimensionAttributes' => $dimensionAttributes, - 'contentRichEntity' => $contentRichEntity->reveal(), + ContentWorkflowInterface::DIMENSION_ATTRIBUTES_CONTEXT_KEY => $dimensionAttributes, + ContentWorkflowInterface::CONTENT_RICH_ENTITY_CONTEXT_KEY => $contentRichEntity->reveal(), ]); $contentCopier = $this->prophesize(ContentCopierInterface::class); @@ -99,8 +100,8 @@ public function testOnPublishNoContentRichEntity(): void new Marking() ); $event->setContext([ - 'dimensionAttributes' => $dimensionAttributes, - 'dimensionContentCollection' => $dimensionContentCollection->reveal(), + ContentWorkflowInterface::DIMENSION_ATTRIBUTES_CONTEXT_KEY => $dimensionAttributes, + ContentWorkflowInterface::DIMENSION_CONTENT_COLLECTION_CONTEXT_KEY => $dimensionContentCollection->reveal(), ]); $contentCopier = $this->prophesize(ContentCopierInterface::class); @@ -126,8 +127,8 @@ public function testOnPublishNoDimensionAttributes(): void new Marking() ); $event->setContext([ - 'dimensionContentCollection' => $dimensionContentCollection->reveal(), - 'contentRichEntity' => $contentRichEntity->reveal(), + ContentWorkflowInterface::DIMENSION_CONTENT_COLLECTION_CONTEXT_KEY => $dimensionContentCollection->reveal(), + ContentWorkflowInterface::CONTENT_RICH_ENTITY_CONTEXT_KEY => $contentRichEntity->reveal(), ]); $contentCopier = $this->prophesize(ContentCopierInterface::class); @@ -155,9 +156,9 @@ public function testOnPublish(): void new Marking() ); $event->setContext([ - 'dimensionContentCollection' => $dimensionContentCollection->reveal(), - 'dimensionAttributes' => $dimensionAttributes, - 'contentRichEntity' => $contentRichEntity->reveal(), + ContentWorkflowInterface::DIMENSION_CONTENT_COLLECTION_CONTEXT_KEY => $dimensionContentCollection->reveal(), + ContentWorkflowInterface::DIMENSION_ATTRIBUTES_CONTEXT_KEY => $dimensionAttributes, + ContentWorkflowInterface::CONTENT_RICH_ENTITY_CONTEXT_KEY => $contentRichEntity->reveal(), ]); $contentCopier = $this->prophesize(ContentCopierInterface::class); @@ -194,9 +195,9 @@ public function testOnPublishExistingPublished(): void new Marking() ); $event->setContext([ - 'dimensionContentCollection' => $dimensionContentCollection->reveal(), - 'dimensionAttributes' => $dimensionAttributes, - 'contentRichEntity' => $contentRichEntity->reveal(), + ContentWorkflowInterface::DIMENSION_CONTENT_COLLECTION_CONTEXT_KEY => $dimensionContentCollection->reveal(), + ContentWorkflowInterface::DIMENSION_ATTRIBUTES_CONTEXT_KEY => $dimensionAttributes, + ContentWorkflowInterface::CONTENT_RICH_ENTITY_CONTEXT_KEY => $contentRichEntity->reveal(), ]); $contentCopier = $this->prophesize(ContentCopierInterface::class); diff --git a/Tests/Unit/Content/Application/ContentWorkflow/Subscriber/RemoveDraftTransitionSubscriberTest.php b/Tests/Unit/Content/Application/ContentWorkflow/Subscriber/RemoveDraftTransitionSubscriberTest.php index 213b6a08..a155c4c0 100644 --- a/Tests/Unit/Content/Application/ContentWorkflow/Subscriber/RemoveDraftTransitionSubscriberTest.php +++ b/Tests/Unit/Content/Application/ContentWorkflow/Subscriber/RemoveDraftTransitionSubscriberTest.php @@ -16,6 +16,7 @@ use PHPUnit\Framework\TestCase; use Prophecy\Argument; use Sulu\Bundle\ContentBundle\Content\Application\ContentCopier\ContentCopierInterface; +use Sulu\Bundle\ContentBundle\Content\Application\ContentWorkflow\ContentWorkflowInterface; use Sulu\Bundle\ContentBundle\Content\Application\ContentWorkflow\Subscriber\RemoveDraftTransitionSubscriber; use Sulu\Bundle\ContentBundle\Content\Domain\Model\ContentRichEntityInterface; use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentInterface; @@ -70,7 +71,7 @@ public function testOnRemoveDraftNoDimensionAttributes(): void new Marking() ); $event->setContext([ - 'contentRichEntity' => $contentRichEntity->reveal(), + ContentWorkflowInterface::CONTENT_RICH_ENTITY_CONTEXT_KEY => $contentRichEntity->reveal(), ]); $contentCopier = $this->prophesize(ContentCopierInterface::class); @@ -94,7 +95,7 @@ public function testOnRemoveDraftNoContentRichEntity(): void new Marking() ); $event->setContext([ - 'dimensionAttributes' => $dimensionAttributes, + ContentWorkflowInterface::DIMENSION_ATTRIBUTES_CONTEXT_KEY => $dimensionAttributes, ]); $contentCopier = $this->prophesize(ContentCopierInterface::class); @@ -116,8 +117,8 @@ public function testOnRemoveDraft(): void new Marking() ); $event->setContext([ - 'dimensionAttributes' => $dimensionAttributes, - 'contentRichEntity' => $contentRichEntity->reveal(), + ContentWorkflowInterface::DIMENSION_ATTRIBUTES_CONTEXT_KEY => $dimensionAttributes, + ContentWorkflowInterface::CONTENT_RICH_ENTITY_CONTEXT_KEY => $contentRichEntity->reveal(), ]); $contentCopier = $this->prophesize(ContentCopierInterface::class); diff --git a/Tests/Unit/Content/Application/ContentWorkflow/Subscriber/UnpublishTransitionSubscriberTest.php b/Tests/Unit/Content/Application/ContentWorkflow/Subscriber/UnpublishTransitionSubscriberTest.php index 4a9e138f..9c0b2eb0 100644 --- a/Tests/Unit/Content/Application/ContentWorkflow/Subscriber/UnpublishTransitionSubscriberTest.php +++ b/Tests/Unit/Content/Application/ContentWorkflow/Subscriber/UnpublishTransitionSubscriberTest.php @@ -16,6 +16,7 @@ use Doctrine\ORM\EntityManagerInterface; use PHPUnit\Framework\TestCase; use Prophecy\Argument; +use Sulu\Bundle\ContentBundle\Content\Application\ContentWorkflow\ContentWorkflowInterface; use Sulu\Bundle\ContentBundle\Content\Application\ContentWorkflow\Subscriber\UnpublishTransitionSubscriber; use Sulu\Bundle\ContentBundle\Content\Domain\Exception\ContentNotFoundException; use Sulu\Bundle\ContentBundle\Content\Domain\Model\ContentRichEntityInterface; @@ -91,7 +92,7 @@ public function testOnUnpublishNoDimensionAttributes(): void new Marking() ); $event->setContext([ - 'contentRichEntity' => $contentRichEntity->reveal(), + ContentWorkflowInterface::CONTENT_RICH_ENTITY_CONTEXT_KEY => $contentRichEntity->reveal(), ]); $dimensionRepository = $this->prophesize(DimensionRepositoryInterface::class); @@ -122,7 +123,7 @@ public function testOnUnpublishNoContentRichEntity(): void new Marking() ); $event->setContext([ - 'dimensionAttributes' => $dimensionAttributes, + ContentWorkflowInterface::DIMENSION_ATTRIBUTES_CONTEXT_KEY => $dimensionAttributes, ]); $dimensionRepository = $this->prophesize(DimensionRepositoryInterface::class); @@ -153,8 +154,8 @@ public function testOnUnpublishEmptyDimensionCollection(): void new Marking() ); $event->setContext([ - 'dimensionAttributes' => $dimensionAttributes, - 'contentRichEntity' => $contentRichEntity->reveal(), + ContentWorkflowInterface::DIMENSION_ATTRIBUTES_CONTEXT_KEY => $dimensionAttributes, + ContentWorkflowInterface::CONTENT_RICH_ENTITY_CONTEXT_KEY => $contentRichEntity->reveal(), ]); $dimensionRepository = $this->prophesize(DimensionRepositoryInterface::class); @@ -192,8 +193,8 @@ public function testOnUnpublishNoLocalizedDimensionContent(): void new Marking() ); $event->setContext([ - 'dimensionAttributes' => $dimensionAttributes, - 'contentRichEntity' => $contentRichEntity->reveal(), + ContentWorkflowInterface::DIMENSION_ATTRIBUTES_CONTEXT_KEY => $dimensionAttributes, + ContentWorkflowInterface::CONTENT_RICH_ENTITY_CONTEXT_KEY => $contentRichEntity->reveal(), ]); $dimensionRepository = $this->prophesize(DimensionRepositoryInterface::class); @@ -241,8 +242,8 @@ public function testOnUnpublish(): void new Marking() ); $event->setContext([ - 'dimensionAttributes' => $dimensionAttributes, - 'contentRichEntity' => $contentRichEntity->reveal(), + ContentWorkflowInterface::DIMENSION_ATTRIBUTES_CONTEXT_KEY => $dimensionAttributes, + ContentWorkflowInterface::CONTENT_RICH_ENTITY_CONTEXT_KEY => $contentRichEntity->reveal(), ]); $dimensionRepository = $this->prophesize(DimensionRepositoryInterface::class);