use BookStack\Uploads\Image;
use BookStack\Entities\Page;
use BookStack\Uploads\ImageService;
+use Illuminate\Support\Str;
use Tests\TestCase;
class ImageTest extends TestCase
]);
}
+ public function test_image_display_thumbnail_generation_does_not_increase_image_size()
+ {
+ $page = Page::first();
+ $admin = $this->getAdmin();
+ $this->actingAs($admin);
+
+ $originalFile = $this->getTestImageFilePath('compressed.png');
+ $originalFileSize = filesize($originalFile);
+ $imgDetails = $this->uploadGalleryImage($page, 'compressed.png');
+ $relPath = $imgDetails['path'];
+
+ $this->assertTrue(file_exists(public_path($relPath)), 'Uploaded image found at path: '. public_path($relPath));
+ $displayImage = $imgDetails['response']->thumbs->display;
+
+ $displayImageRelPath = implode('/', array_slice(explode('/', $displayImage), 3));
+ $displayImagePath = public_path($displayImageRelPath);
+ $displayFileSize = filesize($displayImagePath);
+
+ $this->deleteImage($relPath);
+ $this->deleteImage($displayImageRelPath);
+
+ $this->assertEquals($originalFileSize, $displayFileSize, 'Display thumbnail generation should not increase image size');
+ }
+
public function test_image_edit()
{
$editor = $this->getEditor();
$imgDetails = $this->uploadGalleryImage();
$image = Image::query()->first();
- $newName = str_random();
+ $newName = Str::random();
$update = $this->put('/images/' . $image->id, ['name' => $newName]);
$update->assertSuccessful();
$update->assertJson([
$searchHitRequest = $this->get("/images/gallery?page=1&uploaded_to={$pageId}&search={$namePartial}");
$searchHitRequest->assertSuccessful()->assertJson($resultJson);
- $namePartial = str_random(16);
+ $namePartial = Str::random(16);
$searchHitRequest = $this->get("/images/gallery?page=1&uploaded_to={$pageId}&search={$namePartial}");
$searchHitRequest->assertSuccessful()->assertExactJson($emptyJson);
}
public function test_secure_images_uploads_to_correct_place()
{
- config()->set('filesystems.default', 'local_secure');
+ config()->set('filesystems.images', 'local_secure');
$this->asEditor();
$galleryFile = $this->getTestImage('my-secure-test-upload.png');
$page = Page::first();
public function test_secure_images_included_in_exports()
{
- config()->set('filesystems.default', 'local_secure');
+ config()->set('filesystems.images', 'local_secure');
$this->asEditor();
$galleryFile = $this->getTestImage('my-secure-test-upload.png');
$page = Page::first();
$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');
+ $this->assertTrue(strpos($export->getContent(), $encodedImageContent) !== false, 'Uploaded image in export content');
if (file_exists($expectedPath)) {
unlink($expectedPath);
public function test_system_images_remain_public()
{
- config()->set('filesystems.default', 'local_secure');
+ config()->set('filesystems.images', 'local_secure');
$this->asAdmin();
$galleryFile = $this->getTestImage('my-system-test-upload.png');
$expectedPath = public_path('uploads/images/system/' . Date('Y-m') . '/my-system-test-upload.png');
$image = Image::where('type', '=', 'gallery')->first();
$pageRepo = app(PageRepo::class);
- $pageRepo->updatePage($page, $page->book_id, [
+ $pageRepo->update($page, [
'name' => $page->name,
'html' => $page->html . "<img src=\"{$image->url}\">",
'summary' => ''
$this->assertCount(0, $toDelete);
// Save a revision of our page without the image;
- $pageRepo->updatePage($page, $page->book_id, [
+ $pageRepo->update($page, [
'name' => $page->name,
'html' => "<p>Hello</p>",
'summary' => ''