Skip to content

Commit

Permalink
Merge pull request #24 from FarhanShares/updated-media-directory
Browse files Browse the repository at this point in the history
Updated media directory
  • Loading branch information
FarhanShares authored Mar 17, 2021
2 parents ce3e06c + b9a329e commit cc852af
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/Models/Media.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public function getPath(string $conversion = '')
*/
public function getDirectory()
{
return $this->getKey();
return $this->getKey() . '-' . md5($this->getKey() . config('app.key'));
}

/**
Expand Down
25 changes: 22 additions & 3 deletions tests/MediaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,19 @@
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;

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()
{
Expand Down Expand Up @@ -61,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 */
Expand Down Expand Up @@ -107,7 +124,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 */
Expand All @@ -117,8 +135,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')
);
}
Expand Down

0 comments on commit cc852af

Please sign in to comment.