|
3 | 3 | namespace EasyCorp\Bundle\EasyAdminBundle\Tests\Functional\Fields\Media; |
4 | 4 |
|
5 | 5 | use EasyCorp\Bundle\EasyAdminBundle\Tests\Functional\AbstractFieldFunctionalTest; |
| 6 | +use EasyCorp\Bundle\EasyAdminBundle\Tests\Functional\Apps\DefaultApp\Controller\Synthetic\ImageFieldNoPreviewCrudController; |
6 | 7 |
|
7 | 8 | class ImageFieldTest extends AbstractFieldFunctionalTest |
8 | 9 | { |
@@ -113,6 +114,37 @@ public function testImageFieldNewFormHasEmptyPreviewContainer(): void |
113 | 114 | static::assertCount(0, $previewImages, 'No image thumbnails should exist in new form preview'); |
114 | 115 | } |
115 | 116 |
|
| 117 | + public function testImageFieldShowPreviewFalseHidesPreview(): void |
| 118 | + { |
| 119 | + $noPreviewController = ImageFieldNoPreviewCrudController::class; |
| 120 | + |
| 121 | + $crawler = $this->client->request('GET', $this->generateNewFormUrl(controllerFqcn: $noPreviewController)); |
| 122 | + |
| 123 | + $imageUploadContainer = $crawler->filter('.ea-imageupload'); |
| 124 | + static::assertGreaterThan(0, $imageUploadContainer->count(), 'Image upload container should still exist'); |
| 125 | + |
| 126 | + $previewContainer = $crawler->filter('[data-ea-imageupload-preview]'); |
| 127 | + static::assertCount(0, $previewContainer, 'Preview container should not exist when showPreview(false)'); |
| 128 | + } |
| 129 | + |
| 130 | + public function testImageFieldShowPreviewFalseHidesPreviewOnEdit(): void |
| 131 | + { |
| 132 | + $noPreviewController = ImageFieldNoPreviewCrudController::class; |
| 133 | + |
| 134 | + $entity = $this->createFieldTestEntity([ |
| 135 | + 'imageField' => 'hidden-preview.jpg', |
| 136 | + ]); |
| 137 | + |
| 138 | + $crawler = $this->client->request('GET', $this->generateEditFormUrl($entity->getId(), controllerFqcn: $noPreviewController)); |
| 139 | + |
| 140 | + $previewContainer = $crawler->filter('[data-ea-imageupload-preview]'); |
| 141 | + static::assertCount(0, $previewContainer, 'Preview container should not exist on edit when showPreview(false)'); |
| 142 | + |
| 143 | + // the file input should still work |
| 144 | + $fileInput = $crawler->filter('.ea-imageupload input[type="file"]'); |
| 145 | + static::assertGreaterThan(0, $fileInput->count(), 'File input should still exist when preview is disabled'); |
| 146 | + } |
| 147 | + |
116 | 148 | public function testImageFieldWithDifferentExtensions(): void |
117 | 149 | { |
118 | 150 | $extensions = ['jpg', 'png', 'gif', 'webp']; |
|
0 commit comments