2018-08-19 09:05:33 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Integration\Services;
|
|
|
|
|
|
|
|
use App\Models\Album;
|
|
|
|
use App\Services\MediaMetadataService;
|
2024-01-04 21:51:32 +00:00
|
|
|
use Illuminate\Support\Facades\File;
|
2024-10-24 10:45:45 +00:00
|
|
|
use PHPUnit\Framework\Attributes\Test;
|
2018-08-19 09:05:33 +00:00
|
|
|
use Tests\TestCase;
|
|
|
|
|
2024-01-11 12:41:33 +00:00
|
|
|
use function Tests\test_path;
|
|
|
|
|
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-11-14 16:57:25 +00:00
|
|
|
|
2020-06-12 13:55:45 +00:00
|
|
|
$this->cleanUp();
|
2018-08-19 09:05:33 +00:00
|
|
|
}
|
|
|
|
|
2024-10-24 10:45:45 +00:00
|
|
|
#[Test]
|
|
|
|
public function getAlbumThumbnailUrl(): void
|
2018-08-19 09:05:33 +00:00
|
|
|
{
|
2024-01-06 11:31:50 +00:00
|
|
|
File::copy(test_path('blobs/cover.png'), album_cover_path('album-cover-for-thumbnail-test.jpg'));
|
2020-06-12 13:55:45 +00:00
|
|
|
|
2021-07-26 21:21:36 +00:00
|
|
|
/** @var Album $album */
|
2020-11-14 16:57:25 +00:00
|
|
|
$album = Album::factory()->create(['cover' => 'album-cover-for-thumbnail-test.jpg']);
|
2020-06-12 13:55:45 +00:00
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2024-10-24 10:45:45 +00:00
|
|
|
#[Test]
|
|
|
|
public function getAlbumThumbnailUrlWithNoCover(): void
|
2018-08-19 09:05:33 +00:00
|
|
|
{
|
2021-07-26 21:21:36 +00:00
|
|
|
/** @var Album $album */
|
2022-07-07 10:45:57 +00:00
|
|
|
$album = Album::factory()->create(['cover' => '']);
|
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
|
|
|
|
{
|
2024-01-04 21:51:32 +00:00
|
|
|
File::delete(album_cover_path('album-cover-for-thumbnail-test.jpg'));
|
|
|
|
File::delete(album_cover_path('album-cover-for-thumbnail-test_thumb.jpg'));
|
2022-07-07 10:45:57 +00:00
|
|
|
|
2020-11-14 16:57:25 +00:00
|
|
|
self::assertFileDoesNotExist(album_cover_path('album-cover-for-thumbnail-test.jpg'));
|
|
|
|
self::assertFileDoesNotExist(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();
|
2020-12-22 20:11:22 +00:00
|
|
|
|
2020-06-12 13:55:45 +00:00
|
|
|
parent::tearDown();
|
2018-08-19 09:05:33 +00:00
|
|
|
}
|
|
|
|
}
|