2018-08-19 09:05:33 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Integration\Services;
|
|
|
|
|
|
|
|
use App\Models\Album;
|
|
|
|
use App\Models\Artist;
|
2020-04-27 20:32:24 +00:00
|
|
|
use App\Services\ImageWriter;
|
2018-08-19 09:05:33 +00:00
|
|
|
use App\Services\MediaMetadataService;
|
2018-08-31 13:47:15 +00:00
|
|
|
use Illuminate\Log\Logger;
|
2020-04-27 20:32:24 +00:00
|
|
|
use Mockery;
|
|
|
|
use Mockery\MockInterface;
|
2018-08-19 09:05:33 +00:00
|
|
|
use Tests\TestCase;
|
|
|
|
|
|
|
|
class MediaMetadataServiceTest extends TestCase
|
|
|
|
{
|
|
|
|
/** @var MediaMetadataService */
|
|
|
|
private $mediaMetadataService;
|
|
|
|
|
2020-04-27 20:32:24 +00:00
|
|
|
/** @var ImageWriter|MockInterface */
|
|
|
|
private $imageWriter;
|
|
|
|
|
2019-07-22 07:03:23 +00:00
|
|
|
public function setUp(): void
|
2018-08-19 09:05:33 +00:00
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
2020-04-27 20:32:24 +00:00
|
|
|
$this->imageWriter = Mockery::mock(ImageWriter::class);
|
|
|
|
$this->mediaMetadataService = new MediaMetadataService($this->imageWriter, app(Logger::class));
|
2018-08-19 09:05:33 +00:00
|
|
|
}
|
|
|
|
|
2018-08-31 13:47:15 +00:00
|
|
|
public function testWriteAlbumCover(): void
|
2018-08-19 09:05:33 +00:00
|
|
|
{
|
|
|
|
/** @var Album $album */
|
|
|
|
$album = factory(Album::class)->create();
|
|
|
|
$coverContent = 'dummy';
|
2020-04-27 20:32:24 +00:00
|
|
|
$coverPath = '/koel/public/images/album/foo.jpg';
|
2018-08-19 09:05:33 +00:00
|
|
|
|
2020-04-27 20:32:24 +00:00
|
|
|
$this->imageWriter
|
|
|
|
->shouldReceive('writeFromBinaryData')
|
|
|
|
->once()
|
|
|
|
->with('/koel/public/images/album/foo.jpg', 'dummy');
|
2018-08-19 09:05:33 +00:00
|
|
|
|
2020-04-27 20:32:24 +00:00
|
|
|
$this->mediaMetadataService->writeAlbumCover($album, $coverContent, 'jpg', $coverPath);
|
2018-08-19 09:05:33 +00:00
|
|
|
$this->assertEquals('http://localhost/public/img/covers/foo.jpg', Album::find($album->id)->cover);
|
|
|
|
}
|
|
|
|
|
2018-08-31 13:47:15 +00:00
|
|
|
public function testWriteArtistImage(): void
|
2018-08-19 09:05:33 +00:00
|
|
|
{
|
|
|
|
$artist = factory(Artist::class)->create();
|
|
|
|
$imageContent = 'dummy';
|
2020-04-27 20:32:24 +00:00
|
|
|
$imagePath = '/koel/public/images/artist/foo.jpg';
|
2018-08-19 09:05:33 +00:00
|
|
|
|
2020-04-27 20:32:24 +00:00
|
|
|
$this->imageWriter
|
|
|
|
->shouldReceive('writeFromBinaryData')
|
|
|
|
->once()
|
|
|
|
->with('/koel/public/images/artist/foo.jpg', 'dummy');
|
2018-08-19 09:05:33 +00:00
|
|
|
|
2020-04-27 20:32:24 +00:00
|
|
|
$this->mediaMetadataService->writeArtistImage($artist, $imageContent, 'jpg', $imagePath);
|
2018-08-19 09:05:33 +00:00
|
|
|
$this->assertEquals('http://localhost/public/img/artists/foo.jpg', Artist::find($artist->id)->image);
|
|
|
|
}
|
|
|
|
}
|