]> BookStack Code Mirror - bookstack/blobdiff - tests/Api/AttachmentsApiTest.php
Opensearch: Fixed XML declaration when php short tags enabled
[bookstack] / tests / Api / AttachmentsApiTest.php
index 4d1d3b340b153c3c588ebdcb7103453d5f98d4be..b234658792482b76bcd89717d1e250f51ba6fb68 100644 (file)
@@ -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,