diff --git a/src/Support/FileRemover/DefaultFileRemover.php b/src/Support/FileRemover/DefaultFileRemover.php index 4c06e4b34..b743cfd94 100644 --- a/src/Support/FileRemover/DefaultFileRemover.php +++ b/src/Support/FileRemover/DefaultFileRemover.php @@ -16,14 +16,14 @@ public function removeAllFiles(Media $media): void { if ($media->conversions_disk && $media->disk !== $media->conversions_disk) { - $this->removeFromMediaDirectory($media, $media->conversions_disk); $this->removeFromConversionsDirectory($media, $media->conversions_disk); $this->removeFromResponsiveImagesDirectory($media, $media->conversions_disk); + $this->removeFromMediaDirectory($media, $media->conversions_disk); } - $this->removeFromMediaDirectory($media, $media->disk); $this->removeFromConversionsDirectory($media, $media->disk); $this->removeFromResponsiveImagesDirectory($media, $media->disk); + $this->removeFromMediaDirectory($media, $media->disk); } public function removeFromMediaDirectory(Media $media, string $disk): void diff --git a/tests/Feature/FileAdder/MediaConversions/DeleteMediaFolderTest.php b/tests/Feature/FileAdder/MediaConversions/DeleteMediaFolderTest.php new file mode 100644 index 000000000..fd62d7fc1 --- /dev/null +++ b/tests/Feature/FileAdder/MediaConversions/DeleteMediaFolderTest.php @@ -0,0 +1,107 @@ +testModelWithoutMediaConversions + ->addMedia($this->getTestJpg()) + ->preservingOriginal() + ->toMediaCollection(); + + $this->testModelWithMultipleConversions + ->addMedia($this->getTestJpg()) + ->preservingOriginal() + ->toMediaCollection(); + + $this->testModelWithResponsiveImages + ->addMedia($this->getTestJpg()) + ->preservingOriginal() + ->toMediaCollection(); + } +}); + +it('will remove the media folder when deleting a media model without conversions', function () { + $ids = $this->testModelWithoutMediaConversions->getMedia()->pluck('id'); + + $ids->map(function ($id) { + expect(File::isDirectory($this->getMediaDirectory($id)))->toBeTrue(); + }); + + $this->testModelWithoutMediaConversions->clearMediaCollection(); + + $ids->map(function ($id) { + expect(File::isDirectory($this->getMediaDirectory($id)))->toBeFalse(); + }); +}); + +it('will remove the media folder when deleting a subject without media conversions', function () { + $ids = $this->testModelWithoutMediaConversions->getMedia()->pluck('id'); + + $ids->map(function ($id) { + expect(File::isDirectory($this->getMediaDirectory($id)))->toBeTrue(); + }); + + $this->testModelWithoutMediaConversions->delete(); + + $ids->map(function ($id) { + expect(File::isDirectory($this->getMediaDirectory($id)))->toBeFalse(); + }); +}); + +it('will remove the media folder when deleting a media model with conversions', function () { + $ids = $this->testModelWithMultipleConversions->getMedia()->pluck('id'); + + $ids->map(function ($id) { + expect(File::isDirectory($this->getMediaDirectory($id)))->toBeTrue(); + }); + + $this->testModelWithMultipleConversions->clearMediaCollection(); + + $ids->map(function ($id) { + expect(File::isDirectory($this->getMediaDirectory($id)))->toBeFalse(); + }); +}); + +it('will remove the media folder when deleting a subject with media conversions', function () { + $ids = $this->testModelWithMultipleConversions->getMedia()->pluck('id'); + + $ids->map(function ($id) { + expect(File::isDirectory($this->getMediaDirectory($id)))->toBeTrue(); + }); + + $this->testModelWithMultipleConversions->delete(); + + $ids->map(function ($id) { + expect(File::isDirectory($this->getMediaDirectory($id)))->toBeFalse(); + }); +}); + +it('will remove the media folder when deleting a media model with conversions and responsive images', function () { + $ids = $this->testModelWithResponsiveImages->getMedia()->pluck('id'); + + $ids->map(function ($id) { + expect(File::isDirectory($this->getMediaDirectory($id)))->toBeTrue(); + }); + + $this->testModelWithResponsiveImages->clearMediaCollection(); + + $ids->map(function ($id) { + expect(File::isDirectory($this->getMediaDirectory($id)))->toBeFalse(); + }); +}); + +it('will remove the media folder when deleting a subject with media conversions and responsive images', function () { + $ids = $this->testModelWithResponsiveImages->getMedia()->pluck('id'); + + $ids->map(function ($id) { + expect(File::isDirectory($this->getMediaDirectory($id)))->toBeTrue(); + }); + + $this->testModelWithResponsiveImages->delete(); + + $ids->map(function ($id) { + expect(File::isDirectory($this->getMediaDirectory($id)))->toBeFalse(); + }); +}); + diff --git a/tests/TestCase.php b/tests/TestCase.php index 35057a6f9..902fdcb50 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -30,7 +30,7 @@ abstract class TestCase extends Orchestra protected TestModelWithConversion $testModelWithConversion; - protected TestModelWithMultipleConversion $testModelWithMultipleConversion; + protected TestModelWithMultipleConversions $testModelWithMultipleConversions; protected TestModelWithPreviewConversion $testModelWithPreviewConversion;