From 109488d1e22c351ed438ec8cbe87a190bb739b99 Mon Sep 17 00:00:00 2001 From: Farhan Israq Date: Wed, 17 Mar 2021 22:56:42 +0600 Subject: [PATCH 1/3] update: media directory structure --- src/Models/Media.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Models/Media.php b/src/Models/Media.php index 0e3a300..43458ba 100644 --- a/src/Models/Media.php +++ b/src/Models/Media.php @@ -130,7 +130,7 @@ public function getPath(string $conversion = '') */ public function getDirectory() { - return $this->getKey(); + return $this->getKey() . '-' . md5($this->getKey() . config('app.key')); } /** From da30dc9df652bd04cee6c154bf75a38d0d02e6cc Mon Sep 17 00:00:00 2001 From: Farhan Israq Date: Wed, 17 Mar 2021 22:56:59 +0600 Subject: [PATCH 2/3] update: media directory structure tests --- tests/MediaTest.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/tests/MediaTest.php b/tests/MediaTest.php index 6b6f651..b2ab0ed 100644 --- a/tests/MediaTest.php +++ b/tests/MediaTest.php @@ -12,6 +12,12 @@ class MediaTest extends TestCase { + public function getMediaPath($mediaId): string + { + return $mediaId . '-' . md5($mediaId . config('app.key')); + } + + /** @test */ public function it_can_create_a_media_record_with_media_uploader() { @@ -107,7 +113,8 @@ public function it_can_get_the_path_on_disk_to_the_file() $media->id = 1; $media->file_name = 'image.jpg'; - $this->assertEquals('1/image.jpg', $media->getPath()); + $path = $this->getMediaPath($media->id); + $this->assertEquals($path . '/image.jpg', $media->getPath()); } /** @test */ @@ -117,8 +124,9 @@ public function it_can_get_the_path_on_disk_to_a_converted_image() $media->id = 1; $media->file_name = 'image.jpg'; + $path = $this->getMediaPath($media->id); $this->assertEquals( - '1/conversions/thumbnail/image.jpg', + $path . '/conversions/thumbnail/image.jpg', $media->getPath('thumbnail') ); } From b9a329e891550f57cd22f736dda19919f0cf72bd Mon Sep 17 00:00:00 2001 From: Farhan Israq Date: Wed, 17 Mar 2021 23:13:19 +0600 Subject: [PATCH 3/3] add: test for deleting a media --- tests/MediaTest.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/tests/MediaTest.php b/tests/MediaTest.php index b2ab0ed..040bd26 100644 --- a/tests/MediaTest.php +++ b/tests/MediaTest.php @@ -6,6 +6,7 @@ use Mockery; use Illuminate\Filesystem\Filesystem; use FarhanShares\MediaMan\Models\Media; +use Illuminate\Support\Facades\Storage; use FarhanShares\MediaMan\MediaUploader; use FarhanShares\MediaMan\Tests\TestCase; use Illuminate\Database\Eloquent\Collection as ElCollection; @@ -67,7 +68,17 @@ public function it_can_update_a_media_record() /** @test */ public function it_can_delete_a_media_record() { - // pivot should be deleted as well + $media = MediaUploader::source($this->fileOne) + ->useName('image') + ->useDisk('default') + ->upload(); + + $mediaId = $media->id; + $mediaFile = $media->file_name; + $media->delete(); + + $this->assertEquals(null, Media::find($mediaId)); + $this->assertEquals(false, Storage::disk('default')->exists($mediaFile)); } /** @test */