koel/tests/Integration/Services/MediaMetadataServiceTest.php

65 lines
2.1 KiB
PHP
Raw Normal View History

2018-08-19 09:05:33 +00:00
<?php
namespace Tests\Integration\Services;
use App\Models\Album;
use App\Models\Artist;
use App\Services\MediaMetadataService;
2018-08-31 13:47:15 +00:00
use Illuminate\Log\Logger;
2018-08-19 09:05:33 +00:00
use org\bovigo\vfs\vfsStream;
use Tests\TestCase;
class MediaMetadataServiceTest extends TestCase
{
/** @var MediaMetadataService */
private $mediaMetadataService;
2019-07-22 07:03:23 +00:00
public function setUp(): void
2018-08-19 09:05:33 +00:00
{
parent::setUp();
2018-08-31 13:47:15 +00:00
$this->mediaMetadataService = new MediaMetadataService(app(Logger::class));
2018-08-19 09:05:33 +00:00
}
2018-08-31 13:47:15 +00:00
public function testCopyAlbumCover(): void
2018-08-19 09:05:33 +00:00
{
/** @var Album $album */
$album = factory(Album::class)->create();
$root = vfsStream::setup('home');
$imageFile = vfsStream::newFile('foo.jpg')->at($root)->setContent('foo');
$coverPath = vfsStream::url('home/bar.jpg');
$this->mediaMetadataService->copyAlbumCover($album, $imageFile->url(), $coverPath);
$this->assertTrue($root->hasChild('bar.jpg'));
$this->assertEquals('http://localhost/public/img/covers/bar.jpg', Album::find($album->id)->cover);
}
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';
$root = vfsStream::setup('home');
$coverPath = vfsStream::url('home/foo.jpg');
$this->mediaMetadataService->writeAlbumCover($album, $coverContent, 'jpg', $coverPath);
$this->assertTrue($root->hasChild('foo.jpg'));
$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
{
/** @var Artist $artist */
$artist = factory(Artist::class)->create();
$imageContent = 'dummy';
$root = vfsStream::setup('home');
$imagePath = vfsStream::url('home/foo.jpg');
$this->mediaMetadataService->writeArtistImage($artist, $imageContent, 'jpg', $imagePath);
$this->assertTrue($root->hasChild('foo.jpg'));
$this->assertEquals('http://localhost/public/img/artists/foo.jpg', Artist::find($artist->id)->image);
}
}