X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/03ee3d21bab5ef1b8fc09de27f3aa8115d947dd1..refs/pull/837/head:/tests/ImageTest.php diff --git a/tests/ImageTest.php b/tests/ImageTest.php index 8c96ae925..fd1aa010e 100644 --- a/tests/ImageTest.php +++ b/tests/ImageTest.php @@ -106,6 +106,29 @@ class ImageTest extends TestCase } } + public function test_secure_images_included_in_exports() + { + config()->set('filesystems.default', 'local_secure'); + $this->asEditor(); + $galleryFile = $this->getTestImage('my-secure-test-upload'); + $page = Page::first(); + $expectedPath = storage_path('uploads/images/gallery/' . Date('Y-m-M') . '/my-secure-test-upload'); + + $upload = $this->call('POST', '/images/gallery/upload', ['uploaded_to' => $page->id], [], ['file' => $galleryFile], []); + $imageUrl = json_decode($upload->getContent(), true)['url']; + $page->html .= ""; + $page->save(); + $upload->assertStatus(200); + + $encodedImageContent = base64_encode(file_get_contents($expectedPath)); + $export = $this->get($page->getUrl('/export/html')); + $this->assertTrue(str_contains($export->getContent(), $encodedImageContent), 'Uploaded image in export content'); + + if (file_exists($expectedPath)) { + unlink($expectedPath); + } + } + public function test_system_images_remain_public() { config()->set('filesystems.default', 'local_secure'); @@ -187,7 +210,7 @@ class ImageTest extends TestCase $this->assertTrue($testImageData === $uploadedImageData, "Uploaded image file data does not match our test image as expected"); } - public function test_drawing_replacing() + public function test_drawing_updating() { $page = Page::first(); $editor = $this->getEditor(); @@ -212,6 +235,15 @@ class ImageTest extends TestCase 'updated_by' => $editor->id, ]); + // Check a revision has been created + $this->assertDatabaseHas('image_revisions', [ + 'image_id' => $image->id, + 'revision' => 2, + 'created_by' => $editor->id, + ]); + + $image = Image::find($image->id); + $this->assertTrue(file_exists(public_path($image->path)), 'Uploaded image not found at path: '. public_path($image->path)); $testImageData = file_get_contents($this->getTestImageFilePath());