- /**
- * Get a test file that can be uploaded.
- */
- protected function getTestFile(string $fileName): UploadedFile
- {
- return new UploadedFile(base_path('tests/test-data/test-file.txt'), $fileName, 'text/plain', 55, null, true);
- }
-
- /**
- * Uploads a file with the given name.
- */
- protected function uploadFile(string $name, int $uploadedTo = 0): \Illuminate\Foundation\Testing\TestResponse
- {
- $file = $this->getTestFile($name);
-
- return $this->call('POST', '/attachments/upload', ['uploaded_to' => $uploadedTo], [], ['file' => $file], []);
- }
-
- /**
- * Create a new attachment.
- */
- protected function createAttachment(Page $page): Attachment
- {
- $this->post('attachments/link', [
- 'attachment_link_url' => 'https://example.com',
- 'attachment_link_name' => 'Example Attachment Link',
- 'attachment_link_uploaded_to' => $page->id,
- ]);
-
- return Attachment::query()->latest()->first();
- }
-
- /**
- * Create a new upload attachment from the given data.
- */
- protected function createUploadAttachment(Page $page, string $filename, string $content, string $mimeType): Attachment
- {
- $file = tmpfile();
- $filePath = stream_get_meta_data($file)['uri'];
- file_put_contents($filePath, $content);
- $upload = new UploadedFile($filePath, $filename, $mimeType, null, true);
-
- $this->call('POST', '/attachments/upload', ['uploaded_to' => $page->id], [], ['file' => $upload], []);
- return $page->attachments()->latest()->firstOrFail();
- }
-
- /**
- * Delete all uploaded files.
- * To assist with cleanup.
- */
- protected function deleteUploads()
- {
- $fileService = $this->app->make(AttachmentService::class);
- foreach (Attachment::all() as $file) {
- $fileService->deleteFile($file);
- }
- }
-