+ 'name' => $imgDetails['name'],
+ ]);
+ }
+
+ 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();
+ $this->actingAs($editor);
+
+ $imgDetails = $this->uploadGalleryImage();
+ $image = Image::query()->first();
+
+ $newName = Str::random();
+ $update = $this->put('/images/' . $image->id, ['name' => $newName]);
+ $update->assertSuccessful();
+ $update->assertSee($newName);
+
+ $this->deleteImage($imgDetails['path']);
+
+ $this->assertDatabaseHas('images', [
+ 'type' => 'gallery',
+ 'name' => $newName
+ ]);
+ }
+
+ public function test_gallery_get_list_format()
+ {
+ $this->asEditor();
+
+ $imgDetails = $this->uploadGalleryImage();
+ $image = Image::query()->first();
+
+ $pageId = $imgDetails['page']->id;
+ $firstPageRequest = $this->get("/images/gallery?page=1&uploaded_to={$pageId}");
+ $firstPageRequest->assertSuccessful()->assertElementExists('div');
+ $firstPageRequest->assertSuccessful()->assertSeeText($image->name);
+
+ $secondPageRequest = $this->get("/images/gallery?page=2&uploaded_to={$pageId}");
+ $secondPageRequest->assertSuccessful()->assertElementNotExists('div');
+
+ $namePartial = substr($imgDetails['name'], 0, 3);
+ $searchHitRequest = $this->get("/images/gallery?page=1&uploaded_to={$pageId}&search={$namePartial}");
+ $searchHitRequest->assertSuccessful()->assertSee($imgDetails['name']);
+
+ $namePartial = Str::random(16);
+ $searchFailRequest = $this->get("/images/gallery?page=1&uploaded_to={$pageId}&search={$namePartial}");
+ $searchFailRequest->assertSuccessful()->assertDontSee($imgDetails['name']);
+ $searchFailRequest->assertSuccessful()->assertElementNotExists('div');
+ }
+
+ public function test_image_usage()
+ {
+ $page = Page::first();
+ $editor = $this->getEditor();
+ $this->actingAs($editor);
+
+ $imgDetails = $this->uploadGalleryImage($page);
+
+ $image = Image::query()->first();
+ $page->html = '<img src="'.$image->url.'">';
+ $page->save();
+
+ $usage = $this->get('/images/edit/' . $image->id . '?delete=true');
+ $usage->assertSuccessful();
+ $usage->assertSeeText($page->name);
+ $usage->assertSee($page->getUrl());
+
+ $this->deleteImage($imgDetails['path']);
+ }
+
+ public function test_php_files_cannot_be_uploaded()
+ {
+ $page = Page::first();
+ $admin = $this->getAdmin();
+ $this->actingAs($admin);
+
+ $fileName = 'bad.php';
+ $relPath = $this->getTestImagePath('gallery', $fileName);
+ $this->deleteImage($relPath);
+
+ $file = $this->getTestImage($fileName);
+ $upload = $this->withHeader('Content-Type', 'image/jpeg')->call('POST', '/images/gallery', ['uploaded_to' => $page->id], [], ['file' => $file], []);
+ $upload->assertStatus(302);
+
+ $this->assertFalse(file_exists(public_path($relPath)), 'Uploaded php file was uploaded but should have been stopped');
+
+ $this->assertDatabaseMissing('images', [
+ 'type' => 'gallery',
+ 'name' => $fileName