Skip to content

Commit

Permalink
!fixup OXDEV-8733 Prepared UserDataexportController and adopted UserD…
Browse files Browse the repository at this point in the history
…ataExportService
  • Loading branch information
RahatHameed committed Oct 2, 2024
1 parent 42f2909 commit cce11b7
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 30 deletions.
2 changes: 1 addition & 1 deletion src/UserData/Service/UserDataExportService.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function __construct(

public function exportUserData(string $userId): void
{
$outputZipFilePath = '../' . $this->userDataZipFilePath . '/' . $userId . '.zip';
$outputZipFilePath = $this->userDataZipFilePath . '/' . $userId . '.zip';
$serializedFiles = $this->userDataCollectionService->getUserDataAsFilesList(userId: $userId);
$this->zipCreatorService->createZip(files: $serializedFiles, outputFilePath: $outputZipFilePath);
$this->userDataFileDownloadService->downloadFile(filePath: $outputZipFilePath);
Expand Down
2 changes: 1 addition & 1 deletion src/UserData/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ services:
class: OxidEsales\GdprOptinModule\UserData\Service\UserDataExportService
public: true
arguments:
$userDataZipFilePath: 'tmp/UserData'
$userDataZipFilePath: '@=service("OxidEsales\\EshopCommunity\\Internal\\Transition\\Utility\\BasicContextInterface").getCacheDirectory()'

OxidEsales\GdprOptinModule\UserData\Service\ZipArchiveFactoryInterface:
class: OxidEsales\GdprOptinModule\UserData\Service\ZipArchiveFactory
Expand Down
36 changes: 8 additions & 28 deletions tests/Unit/UserData/Service/UserDataExportServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,13 @@

class UserDataExportServiceTest extends TestCase
{
private string $userId;
private string $tempDir;

protected function setUp(): void
{
$this->userId = uniqid();
$this->createTempDirectory();
}

public function testZipCreationServiceTriggeredWithCorrectlyProcessedData(): void
{
$expectedOutputFilePath = '../' . $this->tempDir . '/' . $this->userId . '.zip';
$userId = uniqid();

vfsStream::setup('outputDir');
$userDataZipFilePath = vfsStream::url('outputDir');
$expectedOutputFilePath = $userDataZipFilePath . '/' . $userId . '.zip';

$filesListExample = [
$this->createStub(ResultFileInterface::class),
Expand All @@ -40,7 +35,7 @@ public function testZipCreationServiceTriggeredWithCorrectlyProcessedData(): voi

$userDataCollectionServiceMock = $this->createMock(UserDataCollectionServiceInterface::class);
$userDataCollectionServiceMock->method('getUserDataAsFilesList')
->with($this->userId)
->with($userId)
->willReturn($filesListExample);

$zipCreatorServiceSpy = $this->createMock(ZipCreatorServiceInterface::class);
Expand All @@ -58,10 +53,10 @@ public function testZipCreationServiceTriggeredWithCorrectlyProcessedData(): voi
userDataCollectionService: $userDataCollectionServiceMock,
zipCreatorService: $zipCreatorServiceSpy,
userDataFileDownloadService: $fileDownloadServiceSpy,
userDataZipFilePath: $this->tempDir
userDataZipFilePath: $userDataZipFilePath
);

$sut->exportUserData(userId: $this->userId);
$sut->exportUserData(userId: $userId);
}

public function getSut(
Expand All @@ -82,19 +77,4 @@ public function getSut(
userDataZipFilePath: $userDataZipFilePath
);
}

private function createTempDirectory(): void
{
$this->tempDir = sys_get_temp_dir() . '/testDir';

mkdir($this->tempDir);
chmod($this->tempDir, 0777);
}

protected function tearDown(): void
{
if (file_exists($this->tempDir)) {
rmdir($this->tempDir);
}
}
}

0 comments on commit cce11b7

Please sign in to comment.