From 8a88c1bdbc358569d49db3d672f2e64a2783618c Mon Sep 17 00:00:00 2001 From: Niklas Natter Date: Mon, 18 May 2020 18:23:56 +0200 Subject: [PATCH] Add isMerged property to DimensionContentInterface --- .../Application/ContentMerger/ContentMerger.php | 2 +- .../Normalizer/DimensionContentNormalizer.php | 1 + .../Domain/Model/DimensionContentInterface.php | 4 ++++ Content/Domain/Model/DimensionContentTrait.php | 15 +++++++++++++++ .../ContentMerger/ContentMergerTest.php | 2 ++ .../Normalizer/DimensionContentNormalizerTest.php | 2 +- .../Domain/Model/DimensionContentTraitTest.php | 11 +++++++++++ .../Content/Domain/Model/RoutableTraitTest.php | 2 +- .../Mocks/DimensionContentMockWrapperTrait.php | 10 ++++++++++ Tests/Unit/SuluContentBundleTest.php | 4 ++-- 10 files changed, 48 insertions(+), 5 deletions(-) diff --git a/Content/Application/ContentMerger/ContentMerger.php b/Content/Application/ContentMerger/ContentMerger.php index a8790df7..bd6efb0c 100644 --- a/Content/Application/ContentMerger/ContentMerger.php +++ b/Content/Application/ContentMerger/ContentMerger.php @@ -53,8 +53,8 @@ public function mergeCollection(DimensionContentCollectionInterface $dimensionCo $mostSpecificDimension = $mostSpecificDimensionContent->getDimension(); $contentRichEntity = $mostSpecificDimensionContent->getContentRichEntity(); - // TODO: set isResolved flag of dimension content $mergedDimensionContent = $contentRichEntity->createDimensionContent($mostSpecificDimension); + $mergedDimensionContent->markAsMerged(); foreach ($dimensionContentCollection as $dimensionContent) { $this->merge($mergedDimensionContent, $dimensionContent); diff --git a/Content/Application/ContentNormalizer/Normalizer/DimensionContentNormalizer.php b/Content/Application/ContentNormalizer/Normalizer/DimensionContentNormalizer.php index 343825c8..32af5fb8 100644 --- a/Content/Application/ContentNormalizer/Normalizer/DimensionContentNormalizer.php +++ b/Content/Application/ContentNormalizer/Normalizer/DimensionContentNormalizer.php @@ -25,6 +25,7 @@ public function getIgnoredAttributes(object $object): array return [ 'id', + 'merged', 'dimension', 'contentRichEntity', ]; diff --git a/Content/Domain/Model/DimensionContentInterface.php b/Content/Domain/Model/DimensionContentInterface.php index 937e11f2..de0d32ae 100644 --- a/Content/Domain/Model/DimensionContentInterface.php +++ b/Content/Domain/Model/DimensionContentInterface.php @@ -18,4 +18,8 @@ interface DimensionContentInterface public function getDimension(): DimensionInterface; public function getContentRichEntity(): ContentRichEntityInterface; + + public function isMerged(): bool; + + public function markAsMerged(): void; } diff --git a/Content/Domain/Model/DimensionContentTrait.php b/Content/Domain/Model/DimensionContentTrait.php index c1db4560..9e417c59 100644 --- a/Content/Domain/Model/DimensionContentTrait.php +++ b/Content/Domain/Model/DimensionContentTrait.php @@ -20,8 +20,23 @@ trait DimensionContentTrait */ protected $dimension; + /** + * @var bool + */ + private $isMerged = false; + public function getDimension(): DimensionInterface { return $this->dimension; } + + public function isMerged(): bool + { + return $this->isMerged; + } + + public function markAsMerged(): void + { + $this->isMerged = true; + } } diff --git a/Tests/Unit/Content/Application/ContentMerger/ContentMergerTest.php b/Tests/Unit/Content/Application/ContentMerger/ContentMergerTest.php index b540cb26..af9245ae 100644 --- a/Tests/Unit/Content/Application/ContentMerger/ContentMergerTest.php +++ b/Tests/Unit/Content/Application/ContentMerger/ContentMergerTest.php @@ -86,6 +86,8 @@ public function testMergeCollection(): void $merger1->merge($mergedDimensionContent->reveal(), $dimensionContent3->reveal())->shouldBeCalled(); $merger2->merge($mergedDimensionContent->reveal(), $dimensionContent3->reveal())->shouldBeCalled(); + $mergedDimensionContent->markAsMerged()->shouldBeCalled(); + $dimensionContentCollection = new DimensionContentCollection([ $dimensionContent1->reveal(), $dimensionContent2->reveal(), diff --git a/Tests/Unit/Content/Application/ContentNormalizer/Normalizer/DimensionContentNormalizerTest.php b/Tests/Unit/Content/Application/ContentNormalizer/Normalizer/DimensionContentNormalizerTest.php index fc39b4fd..59202d97 100644 --- a/Tests/Unit/Content/Application/ContentNormalizer/Normalizer/DimensionContentNormalizerTest.php +++ b/Tests/Unit/Content/Application/ContentNormalizer/Normalizer/DimensionContentNormalizerTest.php @@ -43,7 +43,7 @@ public function testIgnoredAttributes(): void $object = $this->prophesize(DimensionContentInterface::class); $this->assertSame( - ['id', 'dimension', 'contentRichEntity'], + ['id', 'merged', 'dimension', 'contentRichEntity'], $normalizer->getIgnoredAttributes($object->reveal()) ); } diff --git a/Tests/Unit/Content/Domain/Model/DimensionContentTraitTest.php b/Tests/Unit/Content/Domain/Model/DimensionContentTraitTest.php index 8f1682a9..883f9416 100644 --- a/Tests/Unit/Content/Domain/Model/DimensionContentTraitTest.php +++ b/Tests/Unit/Content/Domain/Model/DimensionContentTraitTest.php @@ -46,4 +46,15 @@ public function testGetDimension(): void $model = $this->getDimensionContentInstance($dimension->reveal()); $this->assertSame($dimension->reveal(), $model->getDimension()); } + + public function testGetSetIsMerged(): void + { + $dimension = $this->prophesize(DimensionInterface::class); + + $model = $this->getDimensionContentInstance($dimension->reveal()); + $this->assertFalse($model->isMerged()); + + $model->markAsMerged(); + $this->assertTrue($model->isMerged()); + } } diff --git a/Tests/Unit/Content/Domain/Model/RoutableTraitTest.php b/Tests/Unit/Content/Domain/Model/RoutableTraitTest.php index 2a576732..5eda651c 100644 --- a/Tests/Unit/Content/Domain/Model/RoutableTraitTest.php +++ b/Tests/Unit/Content/Domain/Model/RoutableTraitTest.php @@ -71,7 +71,7 @@ public function testGetLocale(): void $this->assertSame('en', $model->getLocale()); } - public function getContentId(): void + public function testGetContentId(): void { $model = $this->getRoutableInstance(); $this->assertSame('content-id-123', $model->getContentId()); diff --git a/Tests/Unit/Mocks/DimensionContentMockWrapperTrait.php b/Tests/Unit/Mocks/DimensionContentMockWrapperTrait.php index a8478e48..b284dbef 100644 --- a/Tests/Unit/Mocks/DimensionContentMockWrapperTrait.php +++ b/Tests/Unit/Mocks/DimensionContentMockWrapperTrait.php @@ -32,4 +32,14 @@ public function getContentRichEntity(): ContentRichEntityInterface { return $this->instance->getContentRichEntity(); } + + public function isMerged(): bool + { + return $this->instance->isMerged(); + } + + public function markAsMerged(): void + { + $this->instance->markAsMerged(); + } } diff --git a/Tests/Unit/SuluContentBundleTest.php b/Tests/Unit/SuluContentBundleTest.php index 7f2c145b..a3b2ba8d 100644 --- a/Tests/Unit/SuluContentBundleTest.php +++ b/Tests/Unit/SuluContentBundleTest.php @@ -20,14 +20,14 @@ class SuluContentBundleTest extends TestCase { - protected function getBundle(): SuluContentBundle + protected function getContentBundle(): SuluContentBundle { return new SuluContentBundle(); } public function testPersistenceCompilerPass(): void { - $bundle = $this->getBundle(); + $bundle = $this->getContentBundle(); $containerBuilder = new ContainerBuilder(); $bundle->build($containerBuilder);