-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
OXDEV-8733 Prepared event to clean up exported file
- Loading branch information
1 parent
01f276b
commit 58c0f16
Showing
7 changed files
with
200 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
/** | ||
* Copyright © OXID eSales AG. All rights reserved. | ||
* See LICENSE file for license details. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OxidEsales\GdprOptinModule\UserData\Event; | ||
|
||
use Symfony\Contracts\EventDispatcher\Event; | ||
|
||
class UserDataExportCleanupEvent extends Event | ||
{ | ||
public function __construct( | ||
private readonly string $filePath | ||
) { | ||
} | ||
|
||
public function getFilePath(): string | ||
{ | ||
return $this->filePath; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
/** | ||
* Copyright © OXID eSales AG. All rights reserved. | ||
* See LICENSE file for license details. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OxidEsales\GdprOptinModule\UserData\Event; | ||
|
||
use Symfony\Component\EventDispatcher\EventSubscriberInterface; | ||
|
||
class UserDataExportCleanupSubscriber implements EventSubscriberInterface | ||
{ | ||
/** | ||
* @inheritDoc | ||
*/ | ||
public static function getSubscribedEvents(): array | ||
{ | ||
return [ | ||
UserDataExportCleanupEvent::class => 'onUserDataExportCleanup', | ||
]; | ||
} | ||
|
||
public function onUserDataExportCleanup(UserDataExportCleanupEvent $event): void | ||
{ | ||
$filePath = $event->getFilePath(); | ||
|
||
if (file_exists($filePath)) { | ||
unlink($filePath); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
tests/Unit/UserData/Event/UserDataExportCleanupEventTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
/** | ||
* Copyright © OXID eSales AG. All rights reserved. | ||
* See LICENSE file for license details. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OxidEsales\GdprOptinModule\Tests\Unit\UserData\Event; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use OxidEsales\GdprOptinModule\UserData\Event\UserDataExportCleanupEvent; | ||
|
||
class UserDataExportCleanupEventTest extends TestCase | ||
{ | ||
public function testEventStoresFilePath(): void | ||
{ | ||
$testFilePath = 'test/' . uniqid() . '.zip'; | ||
|
||
$event = new UserDataExportCleanupEvent($testFilePath); | ||
|
||
$this->assertSame($testFilePath, $event->getFilePath()); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
tests/Unit/UserData/Event/UserDataExportCleanupSubscriberTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
/** | ||
* Copyright © OXID eSales AG. All rights reserved. | ||
* See LICENSE file for license details. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OxidEsales\GdprOptinModule\Tests\Unit\UserData\Event; | ||
|
||
use org\bovigo\vfs\vfsStream; | ||
use OxidEsales\GdprOptinModule\UserData\Event\UserDataExportCleanupSubscriber; | ||
use OxidEsales\GdprOptinModule\UserData\Event\UserDataExportCleanupEvent; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class UserDataExportCleanupSubscriberTest extends TestCase | ||
{ | ||
public function testOnUserDataExportCleanupUnlinkedFile(): void | ||
{ | ||
$fileName = uniqid() . '.zip'; | ||
|
||
|
||
$vfsRoot = vfsStream::setup('root'); | ||
$testFilePath = vfsStream::url('root/' . $fileName); | ||
|
||
$fileContents = uniqid(); | ||
vfsStream::newFile($fileName, 0755) | ||
->withContent($fileContents) | ||
->at($vfsRoot); | ||
|
||
$this->assertTrue(file_exists($testFilePath)); | ||
|
||
$userDataExportCleanupEventSpy = $this->createConfiguredMock(UserDataExportCleanupEvent::class, [ | ||
'getFilePath' => $testFilePath, | ||
]); | ||
|
||
$sut = new UserDataExportCleanupSubscriber(); | ||
$sut->onUserDataExportCleanup(event: $userDataExportCleanupEventSpy); | ||
} | ||
|
||
public function testSubscriberSubscribesToCorrectEvent(): void | ||
{ | ||
$this->assertArrayHasKey( | ||
UserDataExportCleanupEvent::class, | ||
UserDataExportCleanupSubscriber::getSubscribedEvents() | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters