3 namespace Tests\Uploads;
5 use BookStack\Entities\Repos\PageRepo;
6 use BookStack\Uploads\Image;
7 use BookStack\Uploads\ImageService;
8 use Illuminate\Support\Str;
11 class ImageTest extends TestCase
13 public function test_image_upload()
15 $page = $this->entities->page();
16 $admin = $this->users->admin();
17 $this->actingAs($admin);
19 $imgDetails = $this->files->uploadGalleryImageToPage($this, $page);
20 $relPath = $imgDetails['path'];
22 $this->assertTrue(file_exists(public_path($relPath)), 'Uploaded image found at path: ' . public_path($relPath));
24 $this->files->deleteAtRelativePath($relPath);
26 $this->assertDatabaseHas('images', [
27 'url' => $this->baseUrl . $relPath,
29 'uploaded_to' => $page->id,
31 'created_by' => $admin->id,
32 'updated_by' => $admin->id,
33 'name' => $imgDetails['name'],
37 public function test_image_display_thumbnail_generation_does_not_increase_image_size()
39 $page = $this->entities->page();
40 $admin = $this->users->admin();
41 $this->actingAs($admin);
43 $originalFile = $this->files->testFilePath('compressed.png');
44 $originalFileSize = filesize($originalFile);
45 $imgDetails = $this->files->uploadGalleryImageToPage($this, $page, 'compressed.png');
46 $relPath = $imgDetails['path'];
48 $this->assertTrue(file_exists(public_path($relPath)), 'Uploaded image found at path: ' . public_path($relPath));
49 $displayImage = $imgDetails['response']->thumbs->display;
51 $displayImageRelPath = implode('/', array_slice(explode('/', $displayImage), 3));
52 $displayImagePath = public_path($displayImageRelPath);
53 $displayFileSize = filesize($displayImagePath);
55 $this->files->deleteAtRelativePath($relPath);
56 $this->files->deleteAtRelativePath($displayImageRelPath);
58 $this->assertEquals($originalFileSize, $displayFileSize, 'Display thumbnail generation should not increase image size');
61 public function test_image_display_thumbnail_generation_for_apng_images_uses_original_file()
63 $page = $this->entities->page();
64 $admin = $this->users->admin();
65 $this->actingAs($admin);
67 $imgDetails = $this->files->uploadGalleryImageToPage($this, $page, 'animated.png');
68 $this->files->deleteAtRelativePath($imgDetails['path']);
70 $this->assertStringContainsString('thumbs-', $imgDetails['response']->thumbs->gallery);
71 $this->assertStringNotContainsString('thumbs-', $imgDetails['response']->thumbs->display);
74 public function test_image_edit()
76 $editor = $this->users->editor();
77 $this->actingAs($editor);
79 $imgDetails = $this->files->uploadGalleryImageToPage($this, $this->entities->page());
80 $image = Image::query()->first();
82 $newName = Str::random();
83 $update = $this->put('/images/' . $image->id, ['name' => $newName]);
84 $update->assertSuccessful();
85 $update->assertSee($newName);
87 $this->files->deleteAtRelativePath($imgDetails['path']);
89 $this->assertDatabaseHas('images', [
95 public function test_image_file_update()
97 $page = $this->entities->page();
100 $imgDetails = $this->files->uploadGalleryImageToPage($this, $page);
101 $relPath = $imgDetails['path'];
103 $newUpload = $this->files->uploadedImage('updated-image.png', 'compressed.png');
104 $this->assertFileEquals($this->files->testFilePath('test-image.png'), public_path($relPath));
106 $imageId = $imgDetails['response']->id;
107 $image = Image::findOrFail($imageId);
108 $image->updated_at = now()->subMonth();
111 $this->call('PUT', "/images/{$imageId}/file", [], [], ['file' => $newUpload])
114 $this->assertFileEquals($this->files->testFilePath('compressed.png'), public_path($relPath));
117 $this->assertTrue($image->updated_at->gt(now()->subMinute()));
119 $this->files->deleteAtRelativePath($relPath);
122 public function test_image_file_update_does_not_allow_change_in_image_extension()
124 $page = $this->entities->page();
127 $imgDetails = $this->files->uploadGalleryImageToPage($this, $page);
128 $relPath = $imgDetails['path'];
129 $newUpload = $this->files->uploadedImage('updated-image.jpg', 'compressed.png');
131 $imageId = $imgDetails['response']->id;
132 $this->call('PUT', "/images/{$imageId}/file", [], [], ['file' => $newUpload])
134 "message" => "Image file replacements must be of the same type",
138 $this->files->deleteAtRelativePath($relPath);
141 public function test_gallery_get_list_format()
145 $imgDetails = $this->files->uploadGalleryImageToPage($this, $this->entities->page());
146 $image = Image::query()->first();
148 $pageId = $imgDetails['page']->id;
149 $firstPageRequest = $this->get("/images/gallery?page=1&uploaded_to={$pageId}");
150 $firstPageRequest->assertSuccessful();
151 $this->withHtml($firstPageRequest)->assertElementExists('div');
152 $firstPageRequest->assertSuccessful()->assertSeeText($image->name);
154 $secondPageRequest = $this->get("/images/gallery?page=2&uploaded_to={$pageId}");
155 $secondPageRequest->assertSuccessful();
156 $this->withHtml($secondPageRequest)->assertElementNotExists('div');
158 $namePartial = substr($imgDetails['name'], 0, 3);
159 $searchHitRequest = $this->get("/images/gallery?page=1&uploaded_to={$pageId}&search={$namePartial}");
160 $searchHitRequest->assertSuccessful()->assertSee($imgDetails['name']);
162 $namePartial = Str::random(16);
163 $searchFailRequest = $this->get("/images/gallery?page=1&uploaded_to={$pageId}&search={$namePartial}");
164 $searchFailRequest->assertSuccessful()->assertDontSee($imgDetails['name']);
165 $searchFailRequest->assertSuccessful();
166 $this->withHtml($searchFailRequest)->assertElementNotExists('div');
169 public function test_image_gallery_lists_for_draft_page()
171 $this->actingAs($this->users->editor());
172 $draft = $this->entities->newDraftPage();
173 $this->files->uploadGalleryImageToPage($this, $draft);
174 $image = Image::query()->where('uploaded_to', '=', $draft->id)->firstOrFail();
176 $resp = $this->get("/images/gallery?page=1&uploaded_to={$draft->id}");
177 $resp->assertSee($image->getThumb(150, 150));
180 public function test_image_usage()
182 $page = $this->entities->page();
183 $editor = $this->users->editor();
184 $this->actingAs($editor);
186 $imgDetails = $this->files->uploadGalleryImageToPage($this, $page);
188 $image = Image::query()->first();
189 $page->html = '<img src="' . $image->url . '">';
192 $usage = $this->get('/images/edit/' . $image->id . '?delete=true');
193 $usage->assertSuccessful();
194 $usage->assertSeeText($page->name);
195 $usage->assertSee($page->getUrl());
197 $this->files->deleteAtRelativePath($imgDetails['path']);
200 public function test_php_files_cannot_be_uploaded()
202 $page = $this->entities->page();
203 $admin = $this->users->admin();
204 $this->actingAs($admin);
206 $fileName = 'bad.php';
207 $relPath = $this->files->expectedImagePath('gallery', $fileName);
208 $this->files->deleteAtRelativePath($relPath);
210 $file = $this->files->imageFromBase64File('bad-php.base64', $fileName);
211 $upload = $this->withHeader('Content-Type', 'image/jpeg')->call('POST', '/images/gallery', ['uploaded_to' => $page->id], [], ['file' => $file], []);
212 $upload->assertStatus(500);
213 $this->assertStringContainsString('The file must have a valid & supported image extension', $upload->json('message'));
215 $this->assertFalse(file_exists(public_path($relPath)), 'Uploaded php file was uploaded but should have been stopped');
217 $this->assertDatabaseMissing('images', [
223 public function test_php_like_files_cannot_be_uploaded()
225 $page = $this->entities->page();
226 $admin = $this->users->admin();
227 $this->actingAs($admin);
229 $fileName = 'bad.phtml';
230 $relPath = $this->files->expectedImagePath('gallery', $fileName);
231 $this->files->deleteAtRelativePath($relPath);
233 $file = $this->files->imageFromBase64File('bad-phtml.base64', $fileName);
234 $upload = $this->withHeader('Content-Type', 'image/jpeg')->call('POST', '/images/gallery', ['uploaded_to' => $page->id], [], ['file' => $file], []);
235 $upload->assertStatus(500);
236 $this->assertStringContainsString('The file must have a valid & supported image extension', $upload->json('message'));
238 $this->assertFalse(file_exists(public_path($relPath)), 'Uploaded php file was uploaded but should have been stopped');
241 public function test_files_with_double_extensions_will_get_sanitized()
243 $page = $this->entities->page();
244 $admin = $this->users->admin();
245 $this->actingAs($admin);
247 $fileName = 'bad.phtml.png';
248 $relPath = $this->files->expectedImagePath('gallery', $fileName);
249 $expectedRelPath = dirname($relPath) . '/bad-phtml.png';
250 $this->files->deleteAtRelativePath($expectedRelPath);
252 $file = $this->files->imageFromBase64File('bad-phtml-png.base64', $fileName);
253 $upload = $this->withHeader('Content-Type', 'image/png')->call('POST', '/images/gallery', ['uploaded_to' => $page->id], [], ['file' => $file], []);
254 $upload->assertStatus(200);
256 $lastImage = Image::query()->latest('id')->first();
258 $this->assertEquals('bad.phtml.png', $lastImage->name);
259 $this->assertEquals('bad-phtml.png', basename($lastImage->path));
260 $this->assertFileDoesNotExist(public_path($relPath), 'Uploaded image file name was not stripped of dots');
261 $this->assertFileExists(public_path($expectedRelPath));
263 $this->files->deleteAtRelativePath($lastImage->path);
266 public function test_url_entities_removed_from_filenames()
270 'bad-char-#-image.png',
271 'bad-char-?-image.png',
276 foreach ($badNames as $name) {
277 $galleryFile = $this->files->uploadedImage($name);
278 $page = $this->entities->page();
279 $badPath = $this->files->expectedImagePath('gallery', $name);
280 $this->files->deleteAtRelativePath($badPath);
282 $upload = $this->call('POST', '/images/gallery', ['uploaded_to' => $page->id], [], ['file' => $galleryFile], []);
283 $upload->assertStatus(200);
285 $lastImage = Image::query()->latest('id')->first();
286 $newFileName = explode('.', basename($lastImage->path))[0];
288 $this->assertEquals($lastImage->name, $name);
289 $this->assertFalse(strpos($lastImage->path, $name), 'Path contains original image name');
290 $this->assertFalse(file_exists(public_path($badPath)), 'Uploaded image file name was not stripped of url entities');
292 $this->assertTrue(strlen($newFileName) > 0, 'File name was reduced to nothing');
294 $this->files->deleteAtRelativePath($lastImage->path);
298 public function test_secure_images_uploads_to_correct_place()
300 config()->set('filesystems.images', 'local_secure');
302 $galleryFile = $this->files->uploadedImage('my-secure-test-upload.png');
303 $page = $this->entities->page();
304 $expectedPath = storage_path('uploads/images/gallery/' . date('Y-m') . '/my-secure-test-upload.png');
306 $upload = $this->call('POST', '/images/gallery', ['uploaded_to' => $page->id], [], ['file' => $galleryFile], []);
307 $upload->assertStatus(200);
309 $this->assertTrue(file_exists($expectedPath), 'Uploaded image not found at path: ' . $expectedPath);
311 if (file_exists($expectedPath)) {
312 unlink($expectedPath);
316 public function test_secure_image_paths_traversal_causes_500()
318 config()->set('filesystems.images', 'local_secure');
321 $resp = $this->get('/uploads/images/../../logs/laravel.log');
322 $resp->assertStatus(500);
325 public function test_secure_image_paths_traversal_on_non_secure_images_causes_404()
327 config()->set('filesystems.images', 'local');
330 $resp = $this->get('/uploads/images/../../logs/laravel.log');
331 $resp->assertStatus(404);
334 public function test_secure_image_paths_dont_serve_non_images()
336 config()->set('filesystems.images', 'local_secure');
339 $testFilePath = storage_path('/uploads/images/testing.txt');
340 file_put_contents($testFilePath, 'hello from test_secure_image_paths_dont_serve_non_images');
342 $resp = $this->get('/uploads/images/testing.txt');
343 $resp->assertStatus(404);
346 public function test_secure_images_included_in_exports()
348 config()->set('filesystems.images', 'local_secure');
350 $galleryFile = $this->files->uploadedImage('my-secure-test-upload.png');
351 $page = $this->entities->page();
352 $expectedPath = storage_path('uploads/images/gallery/' . date('Y-m') . '/my-secure-test-upload.png');
354 $upload = $this->call('POST', '/images/gallery', ['uploaded_to' => $page->id], [], ['file' => $galleryFile], []);
355 $imageUrl = json_decode($upload->getContent(), true)['url'];
356 $page->html .= "<img src=\"{$imageUrl}\">";
358 $upload->assertStatus(200);
360 $encodedImageContent = base64_encode(file_get_contents($expectedPath));
361 $export = $this->get($page->getUrl('/export/html'));
362 $this->assertTrue(strpos($export->getContent(), $encodedImageContent) !== false, 'Uploaded image in export content');
364 if (file_exists($expectedPath)) {
365 unlink($expectedPath);
369 public function test_system_images_remain_public_with_local_secure()
371 config()->set('filesystems.images', 'local_secure');
373 $galleryFile = $this->files->uploadedImage('my-system-test-upload.png');
374 $expectedPath = public_path('uploads/images/system/' . date('Y-m') . '/my-system-test-upload.png');
376 $upload = $this->call('POST', '/settings/customization', [], [], ['app_logo' => $galleryFile], []);
377 $upload->assertRedirect('/settings/customization');
379 $this->assertTrue(file_exists($expectedPath), 'Uploaded image not found at path: ' . $expectedPath);
381 if (file_exists($expectedPath)) {
382 unlink($expectedPath);
386 public function test_secure_images_not_tracked_in_session_history()
388 config()->set('filesystems.images', 'local_secure');
390 $page = $this->entities->page();
391 $result = $this->files->uploadGalleryImageToPage($this, $page);
392 $expectedPath = storage_path($result['path']);
393 $this->assertFileExists($expectedPath);
395 $this->get('/books');
396 $this->assertEquals(url('/books'), session()->previousUrl());
398 $resp = $this->get($result['path']);
400 $resp->assertHeader('Content-Type', 'image/png');
402 $this->assertEquals(url('/books'), session()->previousUrl());
404 if (file_exists($expectedPath)) {
405 unlink($expectedPath);
409 public function test_system_images_remain_public_with_local_secure_restricted()
411 config()->set('filesystems.images', 'local_secure_restricted');
413 $galleryFile = $this->files->uploadedImage('my-system-test-restricted-upload.png');
414 $expectedPath = public_path('uploads/images/system/' . date('Y-m') . '/my-system-test-restricted-upload.png');
416 $upload = $this->call('POST', '/settings/customization', [], [], ['app_logo' => $galleryFile], []);
417 $upload->assertRedirect('/settings/customization');
419 $this->assertTrue(file_exists($expectedPath), 'Uploaded image not found at path: ' . $expectedPath);
421 if (file_exists($expectedPath)) {
422 unlink($expectedPath);
426 public function test_secure_restricted_images_inaccessible_without_relation_permission()
428 config()->set('filesystems.images', 'local_secure_restricted');
430 $galleryFile = $this->files->uploadedImage('my-secure-restricted-test-upload.png');
431 $page = $this->entities->page();
433 $upload = $this->call('POST', '/images/gallery', ['uploaded_to' => $page->id], [], ['file' => $galleryFile], []);
434 $upload->assertStatus(200);
435 $expectedUrl = url('uploads/images/gallery/' . date('Y-m') . '/my-secure-restricted-test-upload.png');
436 $expectedPath = storage_path('uploads/images/gallery/' . date('Y-m') . '/my-secure-restricted-test-upload.png');
438 $this->get($expectedUrl)->assertOk();
440 $this->permissions->setEntityPermissions($page, [], []);
442 $resp = $this->get($expectedUrl);
443 $resp->assertNotFound();
445 if (file_exists($expectedPath)) {
446 unlink($expectedPath);
450 public function test_thumbnail_path_handled_by_secure_restricted_images()
452 config()->set('filesystems.images', 'local_secure_restricted');
454 $galleryFile = $this->files->uploadedImage('my-secure-restricted-thumb-test-test.png');
455 $page = $this->entities->page();
457 $upload = $this->call('POST', '/images/gallery', ['uploaded_to' => $page->id], [], ['file' => $galleryFile], []);
458 $upload->assertStatus(200);
459 $expectedUrl = url('uploads/images/gallery/' . date('Y-m') . '/thumbs-150-150/my-secure-restricted-thumb-test-test.png');
460 $expectedPath = storage_path('uploads/images/gallery/' . date('Y-m') . '/my-secure-restricted-thumb-test-test.png');
462 $this->get($expectedUrl)->assertOk();
464 $this->permissions->setEntityPermissions($page, [], []);
466 $resp = $this->get($expectedUrl);
467 $resp->assertNotFound();
469 if (file_exists($expectedPath)) {
470 unlink($expectedPath);
474 public function test_secure_restricted_image_access_controlled_in_exports()
476 config()->set('filesystems.images', 'local_secure_restricted');
478 $galleryFile = $this->files->uploadedImage('my-secure-restricted-export-test.png');
480 $pageA = $this->entities->page();
481 $pageB = $this->entities->page();
482 $expectedPath = storage_path('uploads/images/gallery/' . date('Y-m') . '/my-secure-restricted-export-test.png');
484 $upload = $this->asEditor()->call('POST', '/images/gallery', ['uploaded_to' => $pageA->id], [], ['file' => $galleryFile], []);
487 $imageUrl = json_decode($upload->getContent(), true)['url'];
488 $pageB->html .= "<img src=\"{$imageUrl}\">";
491 $encodedImageContent = base64_encode(file_get_contents($expectedPath));
492 $export = $this->get($pageB->getUrl('/export/html'));
493 $this->assertStringContainsString($encodedImageContent, $export->getContent());
495 $this->permissions->setEntityPermissions($pageA, [], []);
497 $export = $this->get($pageB->getUrl('/export/html'));
498 $this->assertStringNotContainsString($encodedImageContent, $export->getContent());
500 if (file_exists($expectedPath)) {
501 unlink($expectedPath);
505 public function test_image_delete()
507 $page = $this->entities->page();
509 $imageName = 'first-image.png';
510 $relPath = $this->files->expectedImagePath('gallery', $imageName);
511 $this->files->deleteAtRelativePath($relPath);
513 $this->files->uploadGalleryImage($this, $imageName, $page->id);
514 $image = Image::first();
516 $delete = $this->delete('/images/' . $image->id);
517 $delete->assertStatus(200);
519 $this->assertDatabaseMissing('images', [
520 'url' => $this->baseUrl . $relPath,
524 $this->assertFalse(file_exists(public_path($relPath)), 'Uploaded image has not been deleted as expected');
527 public function test_image_delete_does_not_delete_similar_images()
529 $page = $this->entities->page();
531 $imageName = 'first-image.png';
533 $relPath = $this->files->expectedImagePath('gallery', $imageName);
534 $this->files->deleteAtRelativePath($relPath);
536 $this->files->uploadGalleryImage($this, $imageName, $page->id);
537 $this->files->uploadGalleryImage($this, $imageName, $page->id);
538 $this->files->uploadGalleryImage($this, $imageName, $page->id);
540 $image = Image::first();
541 $folder = public_path(dirname($relPath));
542 $imageCount = count(glob($folder . '/*'));
544 $delete = $this->delete('/images/' . $image->id);
545 $delete->assertStatus(200);
547 $newCount = count(glob($folder . '/*'));
548 $this->assertEquals($imageCount - 1, $newCount, 'More files than expected have been deleted');
549 $this->assertFalse(file_exists(public_path($relPath)), 'Uploaded image has not been deleted as expected');
552 public function test_image_manager_delete_button_only_shows_with_permission()
554 $page = $this->entities->page();
556 $imageName = 'first-image.png';
557 $relPath = $this->files->expectedImagePath('gallery', $imageName);
558 $this->files->deleteAtRelativePath($relPath);
559 $viewer = $this->users->viewer();
561 $this->files->uploadGalleryImage($this, $imageName, $page->id);
562 $image = Image::first();
564 $resp = $this->get("/images/edit/{$image->id}");
565 $this->withHtml($resp)->assertElementExists('button#image-manager-delete');
567 $resp = $this->actingAs($viewer)->get("/images/edit/{$image->id}");
568 $this->withHtml($resp)->assertElementNotExists('button#image-manager-delete');
570 $this->permissions->grantUserRolePermissions($viewer, ['image-delete-all']);
572 $resp = $this->actingAs($viewer)->get("/images/edit/{$image->id}");
573 $this->withHtml($resp)->assertElementExists('button#image-manager-delete');
575 $this->files->deleteAtRelativePath($relPath);
578 public function test_image_manager_regen_thumbnails()
581 $imageName = 'first-image.png';
582 $relPath = $this->files->expectedImagePath('gallery', $imageName);
583 $this->files->deleteAtRelativePath($relPath);
585 $this->files->uploadGalleryImage($this, $imageName, $this->entities->page()->id);
586 $image = Image::first();
588 $resp = $this->get("/images/edit/{$image->id}");
589 $this->withHtml($resp)->assertElementExists('button#image-manager-rebuild-thumbs');
591 $expectedThumbPath = dirname($relPath) . '/scaled-1680-/' . basename($relPath);
592 $this->files->deleteAtRelativePath($expectedThumbPath);
593 $this->assertFileDoesNotExist($this->files->relativeToFullPath($expectedThumbPath));
595 $resp = $this->put("/images/{$image->id}/rebuild-thumbnails");
598 $this->assertFileExists($this->files->relativeToFullPath($expectedThumbPath));
599 $this->files->deleteAtRelativePath($relPath);
602 protected function getTestProfileImage()
604 $imageName = 'profile.png';
605 $relPath = $this->files->expectedImagePath('user', $imageName);
606 $this->files->deleteAtRelativePath($relPath);
608 return $this->files->uploadedImage($imageName);
611 public function test_user_image_upload()
613 $editor = $this->users->editor();
614 $admin = $this->users->admin();
615 $this->actingAs($admin);
617 $file = $this->getTestProfileImage();
618 $this->call('PUT', '/settings/users/' . $editor->id, [], [], ['profile_image' => $file], []);
620 $this->assertDatabaseHas('images', [
622 'uploaded_to' => $editor->id,
623 'created_by' => $admin->id,
627 public function test_user_images_deleted_on_user_deletion()
629 $editor = $this->users->editor();
630 $this->actingAs($editor);
632 $file = $this->getTestProfileImage();
633 $this->call('PUT', '/my-account/profile', [], [], ['profile_image' => $file], []);
635 $profileImages = Image::where('type', '=', 'user')->where('created_by', '=', $editor->id)->get();
636 $this->assertTrue($profileImages->count() === 1, 'Found profile images does not match upload count');
638 $imagePath = public_path($profileImages->first()->path);
639 $this->assertTrue(file_exists($imagePath));
641 $userDelete = $this->asAdmin()->delete($editor->getEditUrl());
642 $userDelete->assertStatus(302);
644 $this->assertDatabaseMissing('images', [
646 'created_by' => $editor->id,
648 $this->assertDatabaseMissing('images', [
650 'uploaded_to' => $editor->id,
653 $this->assertFalse(file_exists($imagePath));
656 public function test_deleted_unused_images()
658 $page = $this->entities->page();
659 $admin = $this->users->admin();
660 $this->actingAs($admin);
662 $imageName = 'unused-image.png';
663 $relPath = $this->files->expectedImagePath('gallery', $imageName);
664 $this->files->deleteAtRelativePath($relPath);
666 $upload = $this->files->uploadGalleryImage($this, $imageName, $page->id);
667 $upload->assertStatus(200);
668 $image = Image::where('type', '=', 'gallery')->first();
670 $pageRepo = app(PageRepo::class);
671 $pageRepo->update($page, [
672 'name' => $page->name,
673 'html' => $page->html . "<img src=\"{$image->url}\">",
677 // Ensure no images are reported as deletable
678 $imageService = app(ImageService::class);
679 $toDelete = $imageService->deleteUnusedImages(true, true);
680 $this->assertCount(0, $toDelete);
682 // Save a revision of our page without the image;
683 $pageRepo->update($page, [
684 'name' => $page->name,
685 'html' => '<p>Hello</p>',
689 // Ensure revision images are picked up okay
690 $imageService = app(ImageService::class);
691 $toDelete = $imageService->deleteUnusedImages(true, true);
692 $this->assertCount(0, $toDelete);
693 $toDelete = $imageService->deleteUnusedImages(false, true);
694 $this->assertCount(1, $toDelete);
696 // Check image is found when revisions are destroyed
697 $page->revisions()->delete();
698 $toDelete = $imageService->deleteUnusedImages(true, true);
699 $this->assertCount(1, $toDelete);
701 // Check the image is deleted
702 $absPath = public_path($relPath);
703 $this->assertTrue(file_exists($absPath), "Existing uploaded file at path {$absPath} exists");
704 $toDelete = $imageService->deleteUnusedImages(true, false);
705 $this->assertCount(1, $toDelete);
706 $this->assertFalse(file_exists($absPath));
708 $this->files->deleteAtRelativePath($relPath);