koel/tests/Feature/AlbumCoverTest.php

58 lines
1.5 KiB
PHP
Raw Normal View History

<?php
namespace Tests\Feature;
use App\Events\LibraryChanged;
use App\Models\Album;
use App\Models\User;
use App\Services\MediaMetadataService;
use Mockery;
class AlbumCoverTest extends TestCase
{
private $mediaMetadataService;
public function setUp(): void
{
parent::setUp();
2020-12-22 20:11:22 +00:00
2020-12-22 23:01:49 +00:00
$this->mediaMetadataService = self::mock(MediaMetadataService::class);
}
public function testUpdate(): void
{
$this->expectsEvents(LibraryChanged::class);
2020-09-06 18:21:39 +00:00
/** @var Album $album */
$album = Album::factory()->create(['id' => 9999]);
$this->mediaMetadataService
->shouldReceive('writeAlbumCover')
->once()
->with(Mockery::on(static function (Album $album): bool {
return $album->id === 9999;
}), 'Foo', 'jpeg');
2020-12-22 20:11:22 +00:00
$response = $this->putAsUser('api/album/' . $album->id . '/cover', [
2020-09-06 18:21:39 +00:00
'cover' => 'data:image/jpeg;base64,Rm9v',
], User::factory()->admin()->create());
2020-09-06 18:21:39 +00:00
$response->assertStatus(200);
}
public function testUpdateNotAllowedForNormalUsers(): void
{
2020-09-06 18:21:39 +00:00
/** @var Album $album */
$album = Album::factory()->create();
$this->mediaMetadataService
->shouldReceive('writeAlbumCover')
->never();
2020-12-22 20:11:22 +00:00
$this->putAsUser('api/album/' . $album->id . '/cover', [
2020-09-06 18:21:39 +00:00
'cover' => 'data:image/jpeg;base64,Rm9v',
], User::factory()->create())
2020-09-06 18:21:39 +00:00
->assertStatus(403);
}
}