diff --git a/src/UserData/Service/CollectionSerializerInterface.php b/src/UserData/Service/CollectionSerializerServiceInterface.php similarity index 90% rename from src/UserData/Service/CollectionSerializerInterface.php rename to src/UserData/Service/CollectionSerializerServiceInterface.php index f8a7927..b6bb116 100644 --- a/src/UserData/Service/CollectionSerializerInterface.php +++ b/src/UserData/Service/CollectionSerializerServiceInterface.php @@ -12,7 +12,7 @@ use OxidEsales\GdprOptinModule\UserData\DataType\ResultFileInterface; use OxidEsales\GdprOptinModule\UserData\DataType\TableCollectionInterface; -interface CollectionSerializerInterface +interface CollectionSerializerServiceInterface { public function serializeCollection(TableCollectionInterface $data): ResultFileInterface; } diff --git a/src/UserData/Service/JsonCollectionSerializerService.php b/src/UserData/Service/JsonCollectionSerializerService.php new file mode 100644 index 0000000..026fa5a --- /dev/null +++ b/src/UserData/Service/JsonCollectionSerializerService.php @@ -0,0 +1,22 @@ +getCollectionName(), json_encode($data->getCollection())); + } +} diff --git a/src/UserData/services.yaml b/src/UserData/services.yaml index ab70605..dcfec50 100644 --- a/src/UserData/services.yaml +++ b/src/UserData/services.yaml @@ -203,4 +203,7 @@ services: OxidEsales\GdprOptinModule\UserData\Service\CollectionAggregationServiceInterface: class: OxidEsales\GdprOptinModule\UserData\Service\CollectionAggregationService arguments: - $collectors: !tagged oe.gdpr.user_data \ No newline at end of file + $collectors: !tagged oe.gdpr.user_data + + OxidEsales\GdprOptinModule\UserData\Service\CollectionSerializerServiceInterface: + class: OxidEsales\GdprOptinModule\UserData\Service\JsonCollectionSerializerService \ No newline at end of file diff --git a/tests/Unit/UserData/Service/JsonCollectionSerializerServiceTest.php b/tests/Unit/UserData/Service/JsonCollectionSerializerServiceTest.php new file mode 100644 index 0000000..204bf95 --- /dev/null +++ b/tests/Unit/UserData/Service/JsonCollectionSerializerServiceTest.php @@ -0,0 +1,38 @@ + uniqid(), 'OXDELFNAME' => uniqid(), 'OXDELLNAME' => uniqid()], + ['OXID' => uniqid(), 'OXDELFNAME' => uniqid(), 'OXDELLNAME' => uniqid()] + ]; + + $tableCollectionMock = $this->createConfiguredMock(TableCollectionInterface::class, [ + 'getCollection' => $expectedCollection, + 'getCollectionName' => $expectedCollectionName, + ]); + + $sut = new JsonCollectionSerializerService(); + + $actualResult = $sut->serializeCollection($tableCollectionMock); + + $this->assertSame($expectedCollectionName, $actualResult->getFileName()); + $this->assertSame(json_encode($expectedCollection), $actualResult->getContent()); + } +}