koel/tests/Integration/Services/MediaMetadataServiceTest.php

55 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 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
{
2020-12-22 20:11:22 +00:00
copy(__DIR__ . '/../../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 */
$album = Album::factory()->create(['cover' => null]);
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
{
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::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
}
}