koel/tests/Integration/Services/MediaMetadataServiceTest.php

51 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
{
copy(__DIR__ . '/../../blobs/cover.png', $this->coverPath . '/album-cover-for-thumbnail-test.jpg');
$album = factory(Album::class)->create(['cover' => 'album-cover-for-thumbnail-test.jpg']);
self::assertSame(
app()->staticUrl('public/img/covers/album-cover-for-thumbnail-test_thumb.jpg'),
app()->get(MediaMetadataService::class)->getAlbumThumbnailUrl($album)
);
self::assertFileExists($this->coverPath . '/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
{
$album = factory(Album::class)->create(['cover' => null]);
self::assertNull(app()->get(MediaMetadataService::class)->getAlbumThumbnailUrl($album));
}
2018-08-19 09:05:33 +00:00
private function cleanUp(): void
{
@unlink($this->coverPath . '/album-cover-for-thumbnail-test.jpg');
@unlink($this->coverPath . '/album-cover-for-thumbnail-test_thumb.jpg');
self::assertFileNotExists($this->coverPath . '/album-cover-for-thumbnail-test.jpg');
self::assertFileNotExists($this->coverPath . '/album-cover-for-thumbnail-test_thumb.jpg');
}
2018-08-19 09:05:33 +00:00
protected function tearDown(): void
{
$this->cleanUp();
parent::tearDown();
2018-08-19 09:05:33 +00:00
}
}