2015-12-13 12:42:28 +08:00
|
|
|
<?php
|
|
|
|
|
2017-02-14 14:53:02 +08:00
|
|
|
namespace Tests\Feature;
|
|
|
|
|
2015-12-13 12:42:28 +08:00
|
|
|
use App\Models\Setting;
|
2024-01-04 22:51:32 +01:00
|
|
|
use App\Services\MediaScanner;
|
|
|
|
use App\Values\ScanResultCollection;
|
2022-04-22 00:20:21 +02:00
|
|
|
use Mockery\MockInterface;
|
2024-01-09 19:34:40 +01:00
|
|
|
use Tests\TestCase;
|
2015-12-13 12:42:28 +08:00
|
|
|
|
2024-01-11 13:41:33 +01:00
|
|
|
use function Tests\create_admin;
|
|
|
|
|
2017-08-05 17:56:11 +01:00
|
|
|
class SettingTest extends TestCase
|
2015-12-13 12:42:28 +08:00
|
|
|
{
|
2024-01-09 19:34:40 +01:00
|
|
|
private MediaScanner|MockInterface $mediaScanner;
|
2018-08-19 17:26:34 +02:00
|
|
|
|
2019-07-22 09:03:23 +02:00
|
|
|
public function setUp(): void
|
2018-08-19 17:26:34 +02:00
|
|
|
{
|
|
|
|
parent::setUp();
|
2020-11-14 17:57:25 +01:00
|
|
|
|
2024-01-09 19:34:40 +01:00
|
|
|
$this->mediaScanner = self::mock(MediaScanner::class);
|
2018-08-19 17:26:34 +02:00
|
|
|
}
|
|
|
|
|
2019-07-22 09:03:23 +02:00
|
|
|
public function testSaveSettings(): void
|
2016-05-27 17:07:52 +08:00
|
|
|
{
|
2024-01-09 19:34:40 +01:00
|
|
|
$this->mediaScanner->shouldReceive('scan')->once()
|
2024-01-04 22:51:32 +01:00
|
|
|
->andReturn(ScanResultCollection::create());
|
2016-05-27 17:07:52 +08:00
|
|
|
|
2024-01-11 13:41:33 +01:00
|
|
|
$this->putAs('/api/settings', ['media_path' => __DIR__], create_admin())
|
2022-07-07 12:59:56 +02:00
|
|
|
->assertSuccessful();
|
2016-05-27 17:07:52 +08:00
|
|
|
|
2022-10-07 22:25:44 +08:00
|
|
|
self::assertSame(__DIR__, Setting::get('media_path'));
|
2016-05-27 17:07:52 +08:00
|
|
|
}
|
2022-07-07 12:59:56 +02:00
|
|
|
|
|
|
|
public function testNonAdminCannotSaveSettings(): void
|
|
|
|
{
|
2022-07-27 17:32:36 +02:00
|
|
|
$this->putAs('/api/settings', ['media_path' => __DIR__])
|
2022-07-07 12:59:56 +02:00
|
|
|
->assertForbidden();
|
|
|
|
}
|
2024-02-23 16:32:54 +07:00
|
|
|
|
|
|
|
public function testMediaPathCannotBeSetForCloudStorage(): void
|
|
|
|
{
|
|
|
|
config(['koel.storage_driver' => 's3']);
|
|
|
|
|
|
|
|
$this->putAs('/api/settings', ['media_path' => __DIR__], create_admin())
|
|
|
|
->assertUnprocessable();
|
|
|
|
|
|
|
|
config(['koel.storage_driver' => 'local']);
|
|
|
|
}
|
2015-12-13 12:42:28 +08:00
|
|
|
}
|