koel/tests/Feature/SettingTest.php

42 lines
1 KiB
PHP
Raw Normal View History

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;
2016-05-30 01:52:02 -04:00
use App\Models\User;
2018-08-19 17:26:34 +02:00
use App\Services\MediaSyncService;
2022-07-29 13:08:24 +02:00
use App\Values\SyncResultCollection;
2022-04-22 00:20:21 +02:00
use Mockery\MockInterface;
2015-12-13 12:42:28 +08:00
2017-08-05 17:56:11 +01:00
class SettingTest extends TestCase
2015-12-13 12:42:28 +08:00
{
2022-07-27 17:32:36 +02:00
private MediaSyncService|MockInterface $mediaSyncService;
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-12-23 00:01:49 +01:00
$this->mediaSyncService = self::mock(MediaSyncService::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
{
2022-07-27 17:32:36 +02:00
/** @var User $admin */
$admin = User::factory()->admin()->create();
2022-07-29 13:08:24 +02:00
$this->mediaSyncService->shouldReceive('sync')->once()
->andReturn(SyncResultCollection::create());
2016-05-27 17:07:52 +08:00
2022-07-27 17:32:36 +02:00
$this->putAs('/api/settings', ['media_path' => __DIR__], $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();
}
2015-12-13 12:42:28 +08:00
}