2020-04-26 19:09:43 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Feature;
|
|
|
|
|
|
|
|
use App\Events\LibraryChanged;
|
|
|
|
use App\Models\Album;
|
|
|
|
use App\Models\User;
|
|
|
|
use App\Services\MediaMetadataService;
|
|
|
|
use Mockery;
|
2022-07-27 15:32:36 +00:00
|
|
|
use Mockery\MockInterface;
|
2020-04-26 19:09:43 +00:00
|
|
|
|
|
|
|
class AlbumCoverTest extends TestCase
|
|
|
|
{
|
2022-07-27 15:32:36 +00:00
|
|
|
private MediaMetadataService|MockInterface $mediaMetadataService;
|
2020-04-26 19:09:43 +00:00
|
|
|
|
|
|
|
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);
|
2020-04-26 19:09:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testUpdate(): void
|
|
|
|
{
|
|
|
|
$this->expectsEvents(LibraryChanged::class);
|
2020-09-06 18:21:39 +00:00
|
|
|
|
2022-07-27 15:32:36 +00:00
|
|
|
/** @var User $user */
|
|
|
|
$user = User::factory()->admin()->create();
|
|
|
|
|
2020-09-06 18:21:39 +00:00
|
|
|
/** @var Album $album */
|
2022-12-04 13:56:25 +00:00
|
|
|
$album = Album::factory()->create();
|
2020-04-26 19:09:43 +00:00
|
|
|
|
|
|
|
$this->mediaMetadataService
|
|
|
|
->shouldReceive('writeAlbumCover')
|
|
|
|
->once()
|
2022-12-04 13:56:25 +00:00
|
|
|
->with(Mockery::on(static fn (Album $target) => $target->is($album)), 'Foo', 'jpeg');
|
2020-09-06 18:21:39 +00:00
|
|
|
|
2022-07-27 15:32:36 +00:00
|
|
|
$this->putAs('api/album/' . $album->id . '/cover', ['cover' => 'data:image/jpeg;base64,Rm9v'], $user)
|
|
|
|
->assertOk();
|
2020-04-26 19:14:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testUpdateNotAllowedForNormalUsers(): void
|
|
|
|
{
|
2020-09-06 18:21:39 +00:00
|
|
|
/** @var Album $album */
|
2020-11-14 16:57:25 +00:00
|
|
|
$album = Album::factory()->create();
|
2020-04-26 19:14:23 +00:00
|
|
|
|
|
|
|
$this->mediaMetadataService
|
|
|
|
->shouldReceive('writeAlbumCover')
|
|
|
|
->never();
|
|
|
|
|
2022-07-27 15:32:36 +00:00
|
|
|
/** @var User $user */
|
|
|
|
$user = User::factory()->create();
|
|
|
|
|
|
|
|
$this->putAs('api/album/' . $album->id . '/cover', ['cover' => 'data:image/jpeg;base64,Rm9v'], $user)
|
|
|
|
->assertForbidden();
|
2020-04-26 19:09:43 +00:00
|
|
|
}
|
|
|
|
}
|