2020-06-12 13:55:45 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Unit\Services;
|
|
|
|
|
|
|
|
use App\Models\Album;
|
|
|
|
use App\Models\Artist;
|
|
|
|
use App\Services\ImageWriter;
|
|
|
|
use App\Services\MediaMetadataService;
|
|
|
|
use Illuminate\Log\Logger;
|
|
|
|
use Mockery;
|
|
|
|
use Tests\TestCase;
|
|
|
|
|
|
|
|
class MediaMetadataServiceTest extends TestCase
|
|
|
|
{
|
|
|
|
private $mediaMetadataService;
|
|
|
|
private $imageWriter;
|
|
|
|
|
|
|
|
public function setUp(): void
|
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
$this->imageWriter = Mockery::mock(ImageWriter::class);
|
|
|
|
$this->mediaMetadataService = new MediaMetadataService($this->imageWriter, app(Logger::class));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testWriteAlbumCover(): void
|
|
|
|
{
|
|
|
|
/** @var Album $album */
|
2020-11-14 16:57:25 +00:00
|
|
|
$album = Album::factory()->create();
|
2020-06-12 13:55:45 +00:00
|
|
|
$coverContent = 'dummy';
|
2020-09-12 15:01:48 +00:00
|
|
|
$coverPath = '/koel/public/img/album/foo.jpg';
|
2020-06-12 13:55:45 +00:00
|
|
|
|
|
|
|
$this->imageWriter
|
|
|
|
->shouldReceive('writeFromBinaryData')
|
|
|
|
->once()
|
2020-09-12 15:01:48 +00:00
|
|
|
->with('/koel/public/img/album/foo.jpg', 'dummy');
|
2020-06-12 13:55:45 +00:00
|
|
|
|
|
|
|
$this->mediaMetadataService->writeAlbumCover($album, $coverContent, 'jpg', $coverPath);
|
2020-09-06 18:21:39 +00:00
|
|
|
self::assertEquals(album_cover_url('foo.jpg'), Album::find($album->id)->cover);
|
2020-06-12 13:55:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testWriteArtistImage(): void
|
|
|
|
{
|
2020-06-12 15:05:18 +00:00
|
|
|
/** @var Artist $artist */
|
2020-11-14 16:57:25 +00:00
|
|
|
$artist = Artist::factory()->create();
|
2020-06-12 13:55:45 +00:00
|
|
|
$imageContent = 'dummy';
|
2020-09-12 15:01:48 +00:00
|
|
|
$imagePath = '/koel/public/img/artist/foo.jpg';
|
2020-06-12 13:55:45 +00:00
|
|
|
|
|
|
|
$this->imageWriter
|
|
|
|
->shouldReceive('writeFromBinaryData')
|
|
|
|
->once()
|
2020-09-12 15:01:48 +00:00
|
|
|
->with('/koel/public/img/artist/foo.jpg', 'dummy');
|
2020-06-12 13:55:45 +00:00
|
|
|
|
|
|
|
$this->mediaMetadataService->writeArtistImage($artist, $imageContent, 'jpg', $imagePath);
|
2020-09-06 18:21:39 +00:00
|
|
|
self::assertEquals(artist_image_url('foo.jpg'), Artist::find($artist->id)->image);
|
2020-06-12 13:55:45 +00:00
|
|
|
}
|
|
|
|
}
|