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