X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/22a91c955d8258c73dd5dbcf7f46cc302d31c4bd..refs/pull/5689/head:/tests/Api/AttachmentsApiTest.php diff --git a/tests/Api/AttachmentsApiTest.php b/tests/Api/AttachmentsApiTest.php index 4d1d3b340..b23465879 100644 --- a/tests/Api/AttachmentsApiTest.php +++ b/tests/Api/AttachmentsApiTest.php @@ -12,7 +12,7 @@ class AttachmentsApiTest extends TestCase { use TestsApi; - protected $baseEndpoint = '/api/attachments'; + protected string $baseEndpoint = '/api/attachments'; public function test_index_endpoint_returns_expected_book() { @@ -50,7 +50,7 @@ class AttachmentsApiTest extends TestCase ], ]]); - $this->entities->setPermissions($page, [], []); + $this->permissions->setEntityPermissions($page, [], []); $resp = $this->getJson($this->baseEndpoint . '?count=1&sort=+id'); $resp->assertJsonMissing(['data' => [ @@ -246,13 +246,13 @@ class AttachmentsApiTest extends TestCase public function test_attachment_not_visible_on_other_users_draft() { $this->actingAsApiAdmin(); - $editor = $this->getEditor(); + $editor = $this->users->editor(); $page = $this->entities->page(); $page->draft = true; $page->owned_by = $editor->id; $page->save(); - $this->entities->regenPermissions($page); + $this->permissions->regenerateForEntity($page); $attachment = $this->createAttachmentForPage($page, [ 'name' => 'my attachment', @@ -302,6 +302,23 @@ class AttachmentsApiTest extends TestCase } public function test_update_file_attachment_to_link() + { + $this->actingAsApiAdmin(); + $page = $this->entities->page(); + $attachment = $this->createAttachmentForPage($page); + + $resp = $this->putJson("{$this->baseEndpoint}/{$attachment->id}", [ + 'link' => 'https://example.com/donkey', + ]); + + $resp->assertStatus(200); + $this->assertDatabaseHas('attachments', [ + 'id' => $attachment->id, + 'path' => 'https://example.com/donkey', + ]); + } + + public function test_update_does_not_require_name() { $this->actingAsApiAdmin(); $page = $this->entities->page(); @@ -342,7 +359,7 @@ class AttachmentsApiTest extends TestCase protected function createAttachmentForPage(Page $page, $attributes = []): Attachment { - $admin = $this->getAdmin(); + $admin = $this->users->admin(); /** @var Attachment $attachment */ $attachment = $page->attachments()->forceCreate(array_merge([ 'uploaded_to' => $page->id,