+ 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->assertJson([
+ 'id' => $image->id,
+ 'name' => $newName,
+ 'type' => 'gallery',
+ ]);
+
+ $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();
+
+ $emptyJson = ['images' => [], 'has_more' => false];
+ $resultJson = [
+ 'images' => [
+ [
+ 'id' => $image->id,
+ 'name' => $imgDetails['name'],
+ ]
+ ],
+ 'has_more' => false,
+ ];
+
+ $pageId = $imgDetails['page']->id;
+ $firstPageRequest = $this->get("/images/gallery?page=1&uploaded_to={$pageId}");
+ $firstPageRequest->assertSuccessful()->assertJson($resultJson);
+
+ $secondPageRequest = $this->get("/images/gallery?page=2&uploaded_to={$pageId}");
+ $secondPageRequest->assertSuccessful()->assertExactJson($emptyJson);
+
+ $namePartial = substr($imgDetails['name'], 0, 3);
+ $searchHitRequest = $this->get("/images/gallery?page=1&uploaded_to={$pageId}&search={$namePartial}");
+ $searchHitRequest->assertSuccessful()->assertJson($resultJson);
+
+ $namePartial = Str::random(16);
+ $searchHitRequest = $this->get("/images/gallery?page=1&uploaded_to={$pageId}&search={$namePartial}");
+ $searchHitRequest->assertSuccessful()->assertExactJson($emptyJson);
+ }
+
+ 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/usage/' . $image->id);
+ $usage->assertSuccessful();
+ $usage->assertJson([
+ [
+ 'id' => $page->id,
+ 'name' => $page->name
+ ]
+ ]);
+
+ $this->deleteImage($imgDetails['path']);
+ }
+