diff --git a/Content/Application/ContentNormalizer/Normalizer/DimensionContentNormalizer.php b/Content/Application/ContentNormalizer/Normalizer/DimensionContentNormalizer.php index 6a8bae7c..da294a0a 100644 --- a/Content/Application/ContentNormalizer/Normalizer/DimensionContentNormalizer.php +++ b/Content/Application/ContentNormalizer/Normalizer/DimensionContentNormalizer.php @@ -28,6 +28,7 @@ public function getIgnoredAttributes(object $object): array 'merged', 'dimension', 'resource', + 'version', ]; } diff --git a/Content/Application/ContentWorkflow/ContentWorkflow.php b/Content/Application/ContentWorkflow/ContentWorkflow.php index 5b18ab23..3eef504b 100644 --- a/Content/Application/ContentWorkflow/ContentWorkflow.php +++ b/Content/Application/ContentWorkflow/ContentWorkflow.php @@ -135,9 +135,11 @@ private function getWorkflow(): SymfonyWorkflowInterface // | New |--------->| Unpublished | | Review |---------->| Published | | draft | | Review draft | // | | | |<---------------------| | | |--------------->| |<----------------------------| | // +-----+ +-------------+ reject +--------+ +------------+ create draft +-------+ reject draft +---------------+ - // A | A | - // +---+ | publish | - // publish +----------------------------------------------------------------+ + // A | A | A | A | + // +---+ +---+ | | restore | | + // restore publish | +----------------------+ | + // | publish | + // +--------------------------------------------------------------------+ // Configures places $definition = $definitionBuilder diff --git a/Content/Application/ContentWorkflow/Subscriber/PublishTransitionSubscriber.php b/Content/Application/ContentWorkflow/Subscriber/PublishTransitionSubscriber.php index 7ed5e537..9001a878 100644 --- a/Content/Application/ContentWorkflow/Subscriber/PublishTransitionSubscriber.php +++ b/Content/Application/ContentWorkflow/Subscriber/PublishTransitionSubscriber.php @@ -19,6 +19,7 @@ use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentCollectionInterface; use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentInterface; use Sulu\Bundle\ContentBundle\Content\Domain\Model\WorkflowInterface; +use Sulu\Bundle\ContentBundle\Content\Domain\Repository\DimensionContentRepositoryInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\Workflow\Event\TransitionEvent; @@ -29,9 +30,17 @@ class PublishTransitionSubscriber implements EventSubscriberInterface */ private $contentCopier; - public function __construct(ContentCopierInterface $contentCopier) - { + /** + * @var DimensionContentRepositoryInterface + */ + private $dimensionContentRepository; + + public function __construct( + ContentCopierInterface $contentCopier, + DimensionContentRepositoryInterface $dimensionContentRepository + ) { $this->contentCopier = $contentCopier; + $this->dimensionContentRepository = $dimensionContentRepository; } public function onPublish(TransitionEvent $transitionEvent): void @@ -68,6 +77,21 @@ public function onPublish(TransitionEvent $transitionEvent): void $dimensionAttributes['stage'] = DimensionContentInterface::STAGE_LIVE; + // create new version + // TODO optimize latest version and publish locales on write process to avoid loading them here? + $version = 1 + $this->dimensionContentRepository->getLatestVersion($contentRichEntity); + $publishLocales = $this->dimensionContentRepository->getLocales($contentRichEntity, $dimensionAttributes); + + foreach ($publishLocales as $publishLocale) { + $this->contentCopier->copy( + $contentRichEntity, + \array_merge($dimensionAttributes, ['locale' => $publishLocale]), + $contentRichEntity, + \array_merge($dimensionAttributes, ['locale' => $publishLocale, 'version' => $version]) + ); + } + + // publish content into live workspace $this->contentCopier->copyFromDimensionContentCollection( $dimensionContentCollection, $contentRichEntity, diff --git a/Content/Domain/Model/DimensionContentInterface.php b/Content/Domain/Model/DimensionContentInterface.php index b6450ca2..15140da3 100644 --- a/Content/Domain/Model/DimensionContentInterface.php +++ b/Content/Domain/Model/DimensionContentInterface.php @@ -18,6 +18,8 @@ interface DimensionContentInterface public const STAGE_DRAFT = 'draft'; public const STAGE_LIVE = 'live'; + public const DEFAULT_VERSION = 0; + public static function getResourceKey(): string; public function getLocale(): ?string; @@ -28,6 +30,10 @@ public function getStage(): string; public function setStage(string $stage): void; + public function getVersion(): int; + + public function setVersion(int $version): void; + public function getResource(): ContentRichEntityInterface; public function isMerged(): bool; diff --git a/Content/Domain/Model/DimensionContentTrait.php b/Content/Domain/Model/DimensionContentTrait.php index e485d22e..e11e6baf 100644 --- a/Content/Domain/Model/DimensionContentTrait.php +++ b/Content/Domain/Model/DimensionContentTrait.php @@ -25,6 +25,11 @@ trait DimensionContentTrait */ protected $stage = DimensionContentInterface::STAGE_DRAFT; + /** + * @var int + */ + protected $version = DimensionContentInterface::DEFAULT_VERSION; + /** * @var bool */ @@ -50,6 +55,16 @@ public function getStage(): string return $this->stage; } + public function setVersion(int $version): void + { + $this->version = $version; + } + + public function getVersion(): int + { + return $this->version; + } + public function isMerged(): bool { return $this->isMerged; @@ -65,6 +80,7 @@ public static function getDefaultDimensionAttributes(): array return [ 'locale' => null, 'stage' => DimensionContentInterface::STAGE_DRAFT, + 'version' => DimensionContentInterface::DEFAULT_VERSION, ]; } diff --git a/Content/Domain/Repository/DimensionContentRepositoryInterface.php b/Content/Domain/Repository/DimensionContentRepositoryInterface.php index e31e9d51..562e1877 100644 --- a/Content/Domain/Repository/DimensionContentRepositoryInterface.php +++ b/Content/Domain/Repository/DimensionContentRepositoryInterface.php @@ -25,4 +25,16 @@ public function load( ContentRichEntityInterface $contentRichEntity, array $dimensionAttributes ): DimensionContentCollectionInterface; + + public function getLatestVersion(ContentRichEntityInterface $contentRichEntity): int; + + /** + * @param mixed[] $dimensionAttributes + * + * @return string[] + */ + public function getLocales( + ContentRichEntityInterface $contentRichEntity, + array $dimensionAttributes + ): array; } diff --git a/Content/Infrastructure/Doctrine/DimensionContentRepository.php b/Content/Infrastructure/Doctrine/DimensionContentRepository.php index 2440b92b..4e7e36f7 100644 --- a/Content/Infrastructure/Doctrine/DimensionContentRepository.php +++ b/Content/Infrastructure/Doctrine/DimensionContentRepository.php @@ -57,8 +57,7 @@ public function load( $queryBuilder = $this->entityManager->createQueryBuilder() ->from($dimensionContentClass, 'dimensionContent') - ->innerJoin('dimensionContent.' . $mappingProperty, 'content') - ->where('content.id = :id') + ->where('IDENTITY(dimensionContent.' . $mappingProperty . ') = :id') ->setParameter('id', $contentRichEntity->getId()); $this->dimensionContentQueryEnhancer->addSelects( @@ -77,4 +76,45 @@ public function load( $dimensionContentClass ); } + + public function getLatestVersion(ContentRichEntityInterface $contentRichEntity): int + { + $dimensionContentClass = $this->contentMetadataInspector->getDimensionContentClass(\get_class($contentRichEntity)); + $mappingProperty = $this->contentMetadataInspector->getDimensionContentPropertyName(\get_class($contentRichEntity)); + + $queryBuilder = $this->entityManager->createQueryBuilder() + ->from($dimensionContentClass, 'dimensionContent') + ->select('dimensionContent.version') + ->orderBy('dimensionContent.version', 'DESC') + ->setMaxResults(1) + ->where('IDENTITY(dimensionContent.' . $mappingProperty . ') = :id') + ->setParameter('id', $contentRichEntity->getId()); + + return (int) $queryBuilder->getQuery()->getSingleScalarResult(); + } + + public function getLocales( + ContentRichEntityInterface $contentRichEntity, + array $dimensionAttributes + ): array { + $dimensionContentClass = $this->contentMetadataInspector->getDimensionContentClass(\get_class($contentRichEntity)); + $mappingProperty = $this->contentMetadataInspector->getDimensionContentPropertyName(\get_class($contentRichEntity)); + + $queryBuilder = $this->entityManager->createQueryBuilder() + ->from($dimensionContentClass, 'dimensionContent') + ->select('dimensionContent.locale') + ->where('IDENTITY(dimensionContent.' . $mappingProperty . ') = :id') + ->andWhere('dimensionContent.locale IS NOT NULL') + ->setParameter('id', $contentRichEntity->getId()); + + unset($dimensionAttributes['locale']); + foreach ($dimensionAttributes as $key => $value) { + $queryBuilder->andWhere('dimensionContent.' . $key . ' = :' . $key) + ->setParameter(':' . $key, $value); + } + + return \array_map(function($row) { + return $row['locale']; + }, $queryBuilder->getQuery()->getArrayResult()); + } } diff --git a/Content/Infrastructure/Doctrine/MetadataLoader.php b/Content/Infrastructure/Doctrine/MetadataLoader.php index 54601194..3de1054e 100644 --- a/Content/Infrastructure/Doctrine/MetadataLoader.php +++ b/Content/Infrastructure/Doctrine/MetadataLoader.php @@ -47,6 +47,7 @@ public function loadClassMetadata(LoadClassMetadataEventArgs $event): void if ($reflection->implementsInterface(DimensionContentInterface::class)) { $this->addField($metadata, 'stage', 'string', ['length' => 16, 'nullable' => false]); $this->addField($metadata, 'locale', 'string', ['length' => 7, 'nullable' => true]); + $this->addField($metadata, 'version', 'integer', ['nullable' => false, 'default' => 0]); } if ($reflection->implementsInterface(SeoInterface::class)) { diff --git a/Resources/config/services.xml b/Resources/config/services.xml index ff43757f..02219228 100644 --- a/Resources/config/services.xml +++ b/Resources/config/services.xml @@ -151,6 +151,7 @@ + diff --git a/Tests/Unit/Content/Application/ContentMerger/ContentMergerTest.php b/Tests/Unit/Content/Application/ContentMerger/ContentMergerTest.php index 748c4c49..97bbf3fc 100644 --- a/Tests/Unit/Content/Application/ContentMerger/ContentMergerTest.php +++ b/Tests/Unit/Content/Application/ContentMerger/ContentMergerTest.php @@ -69,6 +69,8 @@ public function testMerge(): void ->shouldBeCalled(); $mergedDimensionContent->setStage('draft') ->shouldBeCalled(); + $mergedDimensionContent->setVersion(0) + ->shouldBeCalled(); $mergedDimensionContent->markAsMerged() ->shouldBeCalled(); diff --git a/Tests/Unit/Content/Application/ContentNormalizer/Normalizer/DimensionContentNormalizerTest.php b/Tests/Unit/Content/Application/ContentNormalizer/Normalizer/DimensionContentNormalizerTest.php index e2bd14e1..c7fc35cf 100644 --- a/Tests/Unit/Content/Application/ContentNormalizer/Normalizer/DimensionContentNormalizerTest.php +++ b/Tests/Unit/Content/Application/ContentNormalizer/Normalizer/DimensionContentNormalizerTest.php @@ -42,7 +42,7 @@ public function testIgnoredAttributes(): void $object = $this->prophesize(DimensionContentInterface::class); $this->assertSame( - ['id', 'merged', 'dimension', 'resource'], + ['id', 'merged', 'dimension', 'resource', 'version'], $normalizer->getIgnoredAttributes($object->reveal()) ); } diff --git a/Tests/Unit/Content/Application/ContentWorkflow/ContentWorkflowTest.php b/Tests/Unit/Content/Application/ContentWorkflow/ContentWorkflowTest.php index 1b39aacd..c6a2b330 100644 --- a/Tests/Unit/Content/Application/ContentWorkflow/ContentWorkflowTest.php +++ b/Tests/Unit/Content/Application/ContentWorkflow/ContentWorkflowTest.php @@ -83,9 +83,11 @@ public function testTransitionNoWorkflowInterface(): void $dimensionContent1 = $this->prophesize(DimensionContentInterface::class); $dimensionContent1->getStage()->willReturn('draft'); $dimensionContent1->getLocale()->willReturn(null); + $dimensionContent1->getVersion()->willReturn(0); $dimensionContent2 = $this->prophesize(DimensionContentInterface::class); - $dimensionContent1->getStage()->willReturn('draft'); - $dimensionContent1->getLocale()->willReturn('de'); + $dimensionContent2->getStage()->willReturn('draft'); + $dimensionContent2->getLocale()->willReturn('de'); + $dimensionContent2->getVersion()->willReturn(0); $this->expectExceptionMessage(\sprintf( 'Expected "%s" but "%s" given.', @@ -166,11 +168,13 @@ public function testNotExistTransition(): void $dimensionContent1->willImplement(WorkflowInterface::class); $dimensionContent1->getLocale()->willReturn(null); $dimensionContent1->getStage()->willReturn('draft'); + $dimensionContent1->getVersion()->willReturn(0); $dimensionContent2 = $this->prophesize(DimensionContentInterface::class); $dimensionContent2->willImplement(WorkflowInterface::class); $dimensionContent2->getLocale()->willReturn('de'); $dimensionContent2->getStage()->willReturn('draft'); + $dimensionContent2->getVersion()->willReturn(0); $dimensionContent2->getWorkflowPlace() ->willReturn('unpublished') @@ -219,10 +223,12 @@ public function testTransitions( $dimensionContent1->willImplement(WorkflowInterface::class); $dimensionContent1->getLocale()->willReturn(null); $dimensionContent1->getStage()->willReturn('draft'); + $dimensionContent1->getVersion()->willReturn(0); $dimensionContent2 = $this->prophesize(DimensionContentInterface::class); $dimensionContent2->willImplement(WorkflowInterface::class); $dimensionContent2->getLocale()->willReturn('de'); $dimensionContent2->getStage()->willReturn('draft'); + $dimensionContent2->getVersion()->willReturn(0); $dimensionContent2->getWorkflowPlace() ->willReturn($currentPlace) diff --git a/Tests/Unit/Content/Application/ContentWorkflow/Subscriber/PublishTransitionSubscriberTest.php b/Tests/Unit/Content/Application/ContentWorkflow/Subscriber/PublishTransitionSubscriberTest.php index 21b6a5e2..0102e61a 100644 --- a/Tests/Unit/Content/Application/ContentWorkflow/Subscriber/PublishTransitionSubscriberTest.php +++ b/Tests/Unit/Content/Application/ContentWorkflow/Subscriber/PublishTransitionSubscriberTest.php @@ -22,21 +22,30 @@ use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentCollectionInterface; use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentInterface; use Sulu\Bundle\ContentBundle\Content\Domain\Model\WorkflowInterface; +use Sulu\Bundle\ContentBundle\Content\Domain\Repository\DimensionContentRepositoryInterface; use Symfony\Component\Workflow\Event\TransitionEvent; use Symfony\Component\Workflow\Marking; class PublishTransitionSubscriberTest extends TestCase { public function createContentPublisherSubscriberInstance( - ContentCopierInterface $contentCopier + ContentCopierInterface $contentCopier, + DimensionContentRepositoryInterface $dimensionContentRepository ): PublishTransitionSubscriber { - return new PublishTransitionSubscriber($contentCopier); + return new PublishTransitionSubscriber( + $contentCopier, + $dimensionContentRepository + ); } public function testGetSubscribedEvents(): void { $contentCopier = $this->prophesize(ContentCopierInterface::class); - $contentPublishSubscriber = $this->createContentPublisherSubscriberInstance($contentCopier->reveal()); + $dimensionContentRepository = $this->prophesize(DimensionContentRepositoryInterface::class); + $contentPublishSubscriber = $this->createContentPublisherSubscriberInstance( + $contentCopier->reveal(), + $dimensionContentRepository->reveal() + ); $this->assertSame([ 'workflow.content_workflow.transition.publish' => 'onPublish', @@ -54,7 +63,11 @@ public function testOnPublishNoDimensionContentInterface(): void $contentCopier = $this->prophesize(ContentCopierInterface::class); $contentCopier->copyFromDimensionContentCollection(Argument::cetera())->shouldNotBeCalled(); - $contentPublishSubscriber = $this->createContentPublisherSubscriberInstance($contentCopier->reveal()); + $dimensionContentRepository = $this->prophesize(DimensionContentRepositoryInterface::class); + $contentPublishSubscriber = $this->createContentPublisherSubscriberInstance( + $contentCopier->reveal(), + $dimensionContentRepository->reveal() + ); $contentPublishSubscriber->onPublish($event); } @@ -81,7 +94,11 @@ public function testOnPublishNoDimensionContentCollection(): void $contentCopier->copyFromDimensionContentCollection(Argument::any(), Argument::any(), Argument::any()) ->shouldNotBeCalled(); - $contentPublishSubscriber = $this->createContentPublisherSubscriberInstance($contentCopier->reveal()); + $dimensionContentRepository = $this->prophesize(DimensionContentRepositoryInterface::class); + $contentPublishSubscriber = $this->createContentPublisherSubscriberInstance( + $contentCopier->reveal(), + $dimensionContentRepository->reveal() + ); $contentPublishSubscriber->onPublish($event); } @@ -108,7 +125,11 @@ public function testOnPublishNoContentRichEntity(): void $contentCopier->copyFromDimensionContentCollection(Argument::any(), Argument::any(), Argument::any()) ->shouldNotBeCalled(); - $contentPublishSubscriber = $this->createContentPublisherSubscriberInstance($contentCopier->reveal()); + $dimensionContentRepository = $this->prophesize(DimensionContentRepositoryInterface::class); + $contentPublishSubscriber = $this->createContentPublisherSubscriberInstance( + $contentCopier->reveal(), + $dimensionContentRepository->reveal() + ); $contentPublishSubscriber->onPublish($event); } @@ -135,7 +156,11 @@ public function testOnPublishNoDimensionAttributes(): void $contentCopier->copyFromDimensionContentCollection(Argument::any(), Argument::any(), Argument::any()) ->shouldNotBeCalled(); - $contentPublishSubscriber = $this->createContentPublisherSubscriberInstance($contentCopier->reveal()); + $dimensionContentRepository = $this->prophesize(DimensionContentRepositoryInterface::class); + $contentPublishSubscriber = $this->createContentPublisherSubscriberInstance( + $contentCopier->reveal(), + $dimensionContentRepository->reveal() + ); $contentPublishSubscriber->onPublish($event); } @@ -162,19 +187,30 @@ public function testOnPublish(): void ]); $contentCopier = $this->prophesize(ContentCopierInterface::class); - $sourceDimensionAttributes = $dimensionAttributes; - $sourceDimensionAttributes['stage'] = 'live'; + $targetDimensionAttributes = $dimensionAttributes; + $targetDimensionAttributes['stage'] = 'live'; $resolvedCopiedContent = $this->prophesize(DimensionContentInterface::class); $contentCopier->copyFromDimensionContentCollection( $dimensionContentCollection->reveal(), $contentRichEntity->reveal(), - $sourceDimensionAttributes + $targetDimensionAttributes ) ->willReturn($resolvedCopiedContent->reveal()) ->shouldBeCalled(); - $contentPublishSubscriber = $this->createContentPublisherSubscriberInstance($contentCopier->reveal()); + $dimensionContentRepository = $this->prophesize(DimensionContentRepositoryInterface::class); + $dimensionContentRepository->getLatestVersion($contentRichEntity->reveal()) + ->willReturn(0) + ->shouldBeCalled(); + $dimensionContentRepository->getLocales($contentRichEntity->reveal(), $targetDimensionAttributes) + ->willReturn([]) + ->shouldBeCalled(); + + $contentPublishSubscriber = $this->createContentPublisherSubscriberInstance( + $contentCopier->reveal(), + $dimensionContentRepository->reveal() + ); $contentPublishSubscriber->onPublish($event); } @@ -201,19 +237,44 @@ public function testOnPublishExistingPublished(): void ]); $contentCopier = $this->prophesize(ContentCopierInterface::class); - $sourceDimensionAttributes = $dimensionAttributes; - $sourceDimensionAttributes['stage'] = 'live'; + $targetDimensionAttributes = $dimensionAttributes; + $targetDimensionAttributes['stage'] = 'live'; $resolvedCopiedContent = $this->prophesize(DimensionContentInterface::class); $contentCopier->copyFromDimensionContentCollection( $dimensionContentCollection->reveal(), $contentRichEntity->reveal(), - $sourceDimensionAttributes + $targetDimensionAttributes ) ->willReturn($resolvedCopiedContent->reveal()) ->shouldBeCalled(); - $contentPublishSubscriber = $this->createContentPublisherSubscriberInstance($contentCopier->reveal()); + $dimensionContentRepository = $this->prophesize(DimensionContentRepositoryInterface::class); + $dimensionContentRepository->getLatestVersion($contentRichEntity->reveal()) + ->willReturn(0) + ->shouldBeCalled(); + $dimensionContentRepository->getLocales($contentRichEntity->reveal(), $targetDimensionAttributes) + ->willReturn(['en', 'de']) + ->shouldBeCalled(); + + $contentCopier->copy( + $contentRichEntity->reveal(), + \array_merge($targetDimensionAttributes, ['locale' => 'en']), + $contentRichEntity->reveal(), + \array_merge($targetDimensionAttributes, ['locale' => 'en', 'version' => 1]) + )->shouldBeCalled(); + + $contentCopier->copy( + $contentRichEntity->reveal(), + \array_merge($targetDimensionAttributes, ['locale' => 'de']), + $contentRichEntity->reveal(), + \array_merge($targetDimensionAttributes, ['locale' => 'de', 'version' => 1]) + )->shouldBeCalled(); + + $contentPublishSubscriber = $this->createContentPublisherSubscriberInstance( + $contentCopier->reveal(), + $dimensionContentRepository->reveal() + ); $contentPublishSubscriber->onPublish($event); } diff --git a/Tests/Unit/Content/Application/DimensionContentCollectionFactory/DimensionContentCollectionFactoryTest.php b/Tests/Unit/Content/Application/DimensionContentCollectionFactory/DimensionContentCollectionFactoryTest.php index 4217c637..632e57f3 100644 --- a/Tests/Unit/Content/Application/DimensionContentCollectionFactory/DimensionContentCollectionFactoryTest.php +++ b/Tests/Unit/Content/Application/DimensionContentCollectionFactory/DimensionContentCollectionFactoryTest.php @@ -57,15 +57,18 @@ public function testCreateWithExistingDimensionContent(): void $dimensionContent1 = $this->prophesize(DimensionContentInterface::class); $dimensionContent1->getLocale()->willReturn(null); $dimensionContent1->getStage()->willReturn('draft'); + $dimensionContent1->getVersion()->willReturn(0); $dimensionContent2 = $this->prophesize(DimensionContentInterface::class); $dimensionContent2->getLocale()->willReturn('de'); $dimensionContent2->getStage()->willReturn('draft'); + $dimensionContent2->getVersion()->willReturn(0); $contentRichEntity = $this->prophesize(ContentRichEntityInterface::class); $attributes = [ 'locale' => 'de', 'stage' => 'draft', + 'version' => 0, ]; $data = [ @@ -113,15 +116,21 @@ public function testCreateWithoutExistingDimensionContent(): void ->shouldBeCalled(); $dimensionContent1->setStage('draft') ->shouldBeCalled(); + $dimensionContent1->setVersion(0) + ->shouldBeCalled(); $dimensionContent1->getLocale()->willReturn(null); $dimensionContent1->getStage()->willReturn('draft'); + $dimensionContent1->getVersion()->willReturn(0); $dimensionContent2 = $this->prophesize(DimensionContentInterface::class); $dimensionContent2->setLocale('de') ->shouldBeCalled(); $dimensionContent2->setStage('draft') ->shouldBeCalled(); + $dimensionContent2->setVersion(0) + ->shouldBeCalled(); $dimensionContent2->getLocale()->willReturn('de'); $dimensionContent2->getStage()->willReturn('draft'); + $dimensionContent2->getVersion()->willReturn(0); $contentRichEntity = $this->prophesize(ContentRichEntityInterface::class); $contentRichEntity->createDimensionContent()->shouldBeCalledTimes(2) @@ -132,6 +141,7 @@ public function testCreateWithoutExistingDimensionContent(): void $attributes = [ 'locale' => 'de', 'stage' => 'draft', + 'version' => 0, ]; $data = [ @@ -175,13 +185,17 @@ public function testCreateWithoutExistingLocalizedDimensionContent(): void $dimensionContent1 = $this->prophesize(DimensionContentInterface::class); $dimensionContent1->getLocale()->willReturn(null); $dimensionContent1->getStage()->willReturn('draft'); + $dimensionContent1->getVersion()->willReturn(0); $dimensionContent2 = $this->prophesize(DimensionContentInterface::class); $dimensionContent2->setLocale('de') ->shouldBeCalled(); $dimensionContent2->setStage('draft') ->shouldBeCalled(); + $dimensionContent2->setVersion(0) + ->shouldBeCalled(); $dimensionContent2->getLocale()->willReturn('de'); $dimensionContent2->getStage()->willReturn('draft'); + $dimensionContent2->getVersion()->willReturn(0); $contentRichEntity = $this->prophesize(ContentRichEntityInterface::class); $contentRichEntity->createDimensionContent()->shouldBeCalled()->willReturn($dimensionContent2->reveal()); @@ -190,6 +204,7 @@ public function testCreateWithoutExistingLocalizedDimensionContent(): void $attributes = [ 'locale' => 'de', 'stage' => 'draft', + 'version' => 0, ]; $data = [ diff --git a/Tests/Unit/Content/Domain/Model/DimensionContentCollectionTest.php b/Tests/Unit/Content/Domain/Model/DimensionContentCollectionTest.php index 0b8ef4ea..fe5bd047 100644 --- a/Tests/Unit/Content/Domain/Model/DimensionContentCollectionTest.php +++ b/Tests/Unit/Content/Domain/Model/DimensionContentCollectionTest.php @@ -37,9 +37,11 @@ public function testCount(): void $dimensionContent1 = $this->prophesize(DimensionContentInterface::class); $dimensionContent1->getLocale()->willReturn(null); $dimensionContent1->getStage()->willReturn('draft'); + $dimensionContent1->getVersion()->willReturn(0); $dimensionContent2 = $this->prophesize(DimensionContentInterface::class); $dimensionContent2->getLocale()->willReturn('de'); $dimensionContent2->getStage()->willReturn('draft'); + $dimensionContent2->getVersion()->willReturn(0); $attributes = ['locale' => 'de']; @@ -58,9 +60,11 @@ public function testSortedByAttributes(): void $dimensionContent1 = $this->prophesize(DimensionContentInterface::class); $dimensionContent1->getLocale()->willReturn(null); $dimensionContent1->getStage()->willReturn('draft'); + $dimensionContent1->getVersion()->willReturn(0); $dimensionContent2 = $this->prophesize(DimensionContentInterface::class); $dimensionContent2->getLocale()->willReturn('de'); $dimensionContent2->getStage()->willReturn('draft'); + $dimensionContent2->getVersion()->willReturn(0); $attributes = ['locale' => 'de']; @@ -80,9 +84,11 @@ public function testIterator(): void $dimensionContent1 = $this->prophesize(DimensionContentInterface::class); $dimensionContent1->getLocale()->willReturn(null); $dimensionContent1->getStage()->willReturn('draft'); + $dimensionContent1->getVersion()->willReturn(0); $dimensionContent2 = $this->prophesize(DimensionContentInterface::class); $dimensionContent2->getLocale()->willReturn('de'); $dimensionContent2->getStage()->willReturn('draft'); + $dimensionContent2->getVersion()->willReturn(0); $attributes = ['locale' => 'de']; @@ -102,9 +108,11 @@ public function testGetDimensionContentClass(): void $dimensionContent1 = $this->prophesize(DimensionContentInterface::class); $dimensionContent1->getLocale()->willReturn(null); $dimensionContent1->getStage()->willReturn('draft'); + $dimensionContent1->getVersion()->willReturn(0); $dimensionContent2 = $this->prophesize(DimensionContentInterface::class); $dimensionContent2->getLocale()->willReturn('de'); $dimensionContent2->getStage()->willReturn('draft'); + $dimensionContent2->getVersion()->willReturn(0); $attributes = ['locale' => 'de']; @@ -124,9 +132,11 @@ public function testGetDimensionAttributes(): void $dimensionContent1 = $this->prophesize(DimensionContentInterface::class); $dimensionContent1->getLocale()->willReturn(null); $dimensionContent1->getStage()->willReturn('draft'); + $dimensionContent1->getVersion()->willReturn(0); $dimensionContent2 = $this->prophesize(DimensionContentInterface::class); $dimensionContent2->getLocale()->willReturn('de'); $dimensionContent2->getStage()->willReturn('draft'); + $dimensionContent2->getVersion()->willReturn(0); $attributes = [ 'locale' => 'de', @@ -141,6 +151,7 @@ public function testGetDimensionAttributes(): void [ 'locale' => 'de', 'stage' => 'draft', + 'version' => 0, ], $dimensionContentCollection->getDimensionAttributes() ); @@ -151,9 +162,11 @@ public function testGetDimensionContent(): void $dimensionContent1 = $this->prophesize(DimensionContentInterface::class); $dimensionContent1->getLocale()->willReturn(null); $dimensionContent1->getStage()->willReturn('draft'); + $dimensionContent1->getVersion()->willReturn(0); $dimensionContent2 = $this->prophesize(DimensionContentInterface::class); $dimensionContent2->getLocale()->willReturn('de'); $dimensionContent2->getStage()->willReturn('draft'); + $dimensionContent2->getVersion()->willReturn(0); $attributes = ['locale' => 'de']; @@ -173,9 +186,11 @@ public function testGetDimensionContentNotExist(): void $dimensionContent1 = $this->prophesize(DimensionContentInterface::class); $dimensionContent1->getLocale()->willReturn(null); $dimensionContent1->getStage()->willReturn('draft'); + $dimensionContent1->getVersion()->willReturn(0); $dimensionContent2 = $this->prophesize(DimensionContentInterface::class); $dimensionContent2->getLocale()->willReturn('de'); $dimensionContent2->getStage()->willReturn('draft'); + $dimensionContent2->getVersion()->willReturn(0); $attributes = ['locale' => 'de']; diff --git a/Tests/Unit/Content/Domain/Model/DimensionContentTraitTest.php b/Tests/Unit/Content/Domain/Model/DimensionContentTraitTest.php index 68fcc934..f7cd9201 100644 --- a/Tests/Unit/Content/Domain/Model/DimensionContentTraitTest.php +++ b/Tests/Unit/Content/Domain/Model/DimensionContentTraitTest.php @@ -59,6 +59,7 @@ public function testGetDefaultAttributes(): void $this->assertSame([ 'locale' => null, 'stage' => 'draft', + 'version' => 0, ], $model::getDefaultDimensionAttributes()); } diff --git a/Tests/Unit/Content/Infrastructure/Doctrine/MetadataLoaderTest.php b/Tests/Unit/Content/Infrastructure/Doctrine/MetadataLoaderTest.php index 74dfe4a8..e40baa1e 100644 --- a/Tests/Unit/Content/Infrastructure/Doctrine/MetadataLoaderTest.php +++ b/Tests/Unit/Content/Infrastructure/Doctrine/MetadataLoaderTest.php @@ -133,6 +133,7 @@ public function dataProvider(): \Generator [ 'locale' => false, 'stage' => false, + 'version' => false, ], [], [ @@ -146,6 +147,7 @@ public function dataProvider(): \Generator [ 'locale' => true, 'stage' => true, + 'version' => true, ], [], [ diff --git a/Tests/Unit/Content/Infrastructure/Sulu/Preview/PreviewDimensionContentCollectionTest.php b/Tests/Unit/Content/Infrastructure/Sulu/Preview/PreviewDimensionContentCollectionTest.php index d9c4d5be..4e274611 100644 --- a/Tests/Unit/Content/Infrastructure/Sulu/Preview/PreviewDimensionContentCollectionTest.php +++ b/Tests/Unit/Content/Infrastructure/Sulu/Preview/PreviewDimensionContentCollectionTest.php @@ -75,7 +75,7 @@ public function testGetDimensionAttributes(): void ); $this->assertSame( - ['locale' => 'es', 'stage' => 'draft'], + ['locale' => 'es', 'stage' => 'draft', 'version' => 0], $previewDimensionContentCollection->getDimensionAttributes() ); } diff --git a/Tests/Unit/Mocks/DimensionContentMockWrapperTrait.php b/Tests/Unit/Mocks/DimensionContentMockWrapperTrait.php index 25e4b8dd..6ba2e46d 100644 --- a/Tests/Unit/Mocks/DimensionContentMockWrapperTrait.php +++ b/Tests/Unit/Mocks/DimensionContentMockWrapperTrait.php @@ -42,6 +42,16 @@ public function getStage(): string return $this->instance->getStage(); } + public function setVersion(int $version): void + { + $this->instance->setVersion($version); + } + + public function getVersion(): int + { + return $this->instance->getVersion(); + } + public function setStage(?string $stage): void { $this->instance->setStage($stage);