koel/tests/Integration/Services/MediaMetadataServiceTest.php

57 lines
1.6 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\Services\MediaMetadataService;
use Illuminate\Support\Facades\File;
2018-08-19 09:05:33 +00:00
use Tests\TestCase;
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();
$this->cleanUp();
2018-08-19 09:05:33 +00:00
}
public function testGetAlbumThumbnailUrl(): void
2018-08-19 09:05:33 +00:00
{
File::copy(test_path('blobs/cover.png'), album_cover_path('album-cover-for-thumbnail-test.jpg'));
2021-07-26 21:21:36 +00:00
/** @var Album $album */
$album = Album::factory()->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-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
}
public function testGetAlbumThumbnailUrlWithNoCover(): 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));
}
2018-08-19 09:05:33 +00:00
private function cleanUp(): void
{
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
self::assertFileDoesNotExist(album_cover_path('album-cover-for-thumbnail-test.jpg'));
self::assertFileDoesNotExist(album_cover_path('album-cover-for-thumbnail-test_thumb.jpg'));
}
2018-08-19 09:05:33 +00:00
protected function tearDown(): void
{
$this->cleanUp();
2020-12-22 20:11:22 +00:00
parent::tearDown();
2018-08-19 09:05:33 +00:00
}
}