public function test_file_deletion() { $page = \BookStack\Page::first(); $this->asAdmin(); $fileName = 'deletion_test.txt'; $this->uploadFile($fileName, $page->id); $filePath = base_path('storage/' . $this->getUploadPath($fileName)); $this->assertTrue(file_exists($filePath), 'File at path ' . $filePath . ' does not exist'); $attachmentId = \BookStack\Attachment::first()->id; $this->call('DELETE', 'attachments/' . $attachmentId); $this->dontSeeInDatabase('attachments', ['name' => $fileName]); $this->assertFalse(file_exists($filePath), 'File at path ' . $filePath . ' was not deleted as expected'); $this->deleteUploads(); }
/** * Delete a File from the database and storage. * @param Attachment $attachment */ public function deleteFile(Attachment $attachment) { if ($attachment->external) { $attachment->delete(); return; } $this->deleteFileInStorage($attachment); $attachment->delete(); }