1 <?php namespace Tests\Uploads;
4 use BookStack\Entities\Page;
5 use Illuminate\Http\UploadedFile;
10 * Get the path to our basic test image.
13 protected function getTestImageFilePath()
15 return base_path('tests/test-data/test-image.png');
19 * Get a test image that can be uploaded
21 * @return UploadedFile
23 protected function getTestImage($fileName)
25 return new UploadedFile($this->getTestImageFilePath(), $fileName, 'image/png', 5238, null, true);
29 * Get the raw file data for the test image.
30 * @return false|string
32 protected function getTestImageContent()
34 return file_get_contents($this->getTestImageFilePath());
38 * Get the path for a test image.
43 protected function getTestImagePath($type, $fileName)
45 return '/uploads/images/' . $type . '/' . Date('Y-m') . '/' . $fileName;
49 * Uploads an image with the given name.
51 * @param int $uploadedTo
52 * @param string $contentType
53 * @return \Illuminate\Foundation\Testing\TestResponse
55 protected function uploadImage($name, $uploadedTo = 0, $contentType = 'image/png')
57 $file = $this->getTestImage($name);
58 return $this->withHeader('Content-Type', $contentType)
59 ->call('POST', '/images/gallery', ['uploaded_to' => $uploadedTo], [], ['file' => $file], []);
63 * Upload a new gallery image.
64 * Returns the image name.
65 * Can provide a page to relate the image to.
66 * @param Page|null $page
69 protected function uploadGalleryImage(Page $page = null)
72 $page = Page::query()->first();
75 $imageName = 'first-image.png';
76 $relPath = $this->getTestImagePath('gallery', $imageName);
77 $this->deleteImage($relPath);
79 $upload = $this->uploadImage($imageName, $page->id);
80 $upload->assertStatus(200);
89 * Delete an uploaded image.
92 protected function deleteImage($relPath)
94 $path = public_path($relPath);
95 if (file_exists($path)) {