2018-08-19 09:05:33 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Integration\Services;
|
|
|
|
|
|
|
|
use App\Models\Album;
|
|
|
|
use App\Services\MediaMetadataService;
|
|
|
|
use Tests\TestCase;
|
2020-06-13 12:19:24 +00:00
|
|
|
use function App\Helpers\album_cover_path;
|
|
|
|
use function App\Helpers\album_cover_url;
|
2018-08-19 09:05:33 +00:00
|
|
|
|
|
|
|
class MediaMetadataServiceTest extends TestCase
|
|
|
|
{
|
2019-07-22 07:03:23 +00:00
|
|
|
public function setUp(): void
|
2018-08-19 09:05:33 +00:00
|
|
|
{
|
|
|
|
parent::setUp();
|
2020-06-12 13:55:45 +00:00
|
|
|
$this->cleanUp();
|
2018-08-19 09:05:33 +00:00
|
|
|
}
|
|
|
|
|
2020-06-12 13:55:45 +00:00
|
|
|
public function testGetAlbumThumbnailUrl(): void
|
2018-08-19 09:05:33 +00:00
|
|
|
{
|
2020-06-13 12:19:24 +00:00
|
|
|
copy(__DIR__ . '/../../blobs/cover.png', album_cover_path('album-cover-for-thumbnail-test.jpg'));
|
2020-06-12 13:55:45 +00:00
|
|
|
|
|
|
|
$album = factory(Album::class)->create(['cover' => 'album-cover-for-thumbnail-test.jpg']);
|
|
|
|
|
|
|
|
self::assertSame(
|
2020-06-13 12:19:24 +00:00
|
|
|
album_cover_url('album-cover-for-thumbnail-test_thumb.jpg'),
|
2020-09-06 18:21:39 +00:00
|
|
|
app(MediaMetadataService::class)->getAlbumThumbnailUrl($album)
|
2020-06-12 13:55:45 +00:00
|
|
|
);
|
|
|
|
|
2020-06-13 12:19:24 +00:00
|
|
|
self::assertFileExists(album_cover_path('album-cover-for-thumbnail-test_thumb.jpg'));
|
2018-08-19 09:05:33 +00:00
|
|
|
}
|
|
|
|
|
2020-06-12 13:55:45 +00:00
|
|
|
public function testGetAlbumThumbnailUrlWithNoCover(): void
|
2018-08-19 09:05:33 +00:00
|
|
|
{
|
2020-06-12 13:55:45 +00:00
|
|
|
$album = factory(Album::class)->create(['cover' => null]);
|
2020-09-06 18:21:39 +00:00
|
|
|
self::assertNull(app(MediaMetadataService::class)->getAlbumThumbnailUrl($album));
|
2020-06-12 13:55:45 +00:00
|
|
|
}
|
2018-08-19 09:05:33 +00:00
|
|
|
|
2020-06-12 13:55:45 +00:00
|
|
|
private function cleanUp(): void
|
|
|
|
{
|
2020-06-13 12:19:24 +00:00
|
|
|
@unlink(album_cover_path('album-cover-for-thumbnail-test.jpg'));
|
|
|
|
@unlink(album_cover_path('album-cover-for-thumbnail-test_thumb.jpg'));
|
|
|
|
self::assertFileNotExists(album_cover_path('album-cover-for-thumbnail-test.jpg'));
|
|
|
|
self::assertFileNotExists(album_cover_path('album-cover-for-thumbnail-test_thumb.jpg'));
|
2020-06-12 13:55:45 +00:00
|
|
|
}
|
2018-08-19 09:05:33 +00:00
|
|
|
|
2020-06-12 13:55:45 +00:00
|
|
|
protected function tearDown(): void
|
|
|
|
{
|
|
|
|
$this->cleanUp();
|
|
|
|
parent::tearDown();
|
2018-08-19 09:05:33 +00:00
|
|
|
}
|
|
|
|
}
|