Skip to content

Commit 9a0418e

Browse files
committed
Add more functional tests
1 parent 1580b96 commit 9a0418e

2 files changed

Lines changed: 62 additions & 0 deletions

File tree

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace EasyCorp\Bundle\EasyAdminBundle\Tests\Functional\Apps\DefaultApp\Controller\Synthetic;
4+
5+
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
6+
use EasyCorp\Bundle\EasyAdminBundle\Field\IdField;
7+
use EasyCorp\Bundle\EasyAdminBundle\Field\ImageField;
8+
use EasyCorp\Bundle\EasyAdminBundle\Tests\Functional\Apps\DefaultApp\Entity\Synthetic\FieldTestEntity;
9+
10+
/**
11+
* @extends AbstractCrudController<FieldTestEntity>
12+
*/
13+
class ImageFieldNoPreviewCrudController extends AbstractCrudController
14+
{
15+
public static function getEntityFqcn(): string
16+
{
17+
return FieldTestEntity::class;
18+
}
19+
20+
public function configureFields(string $pageName): iterable
21+
{
22+
yield IdField::new('id')->hideOnForm();
23+
yield ImageField::new('imageField')
24+
->setBasePath('uploads/')
25+
->setUploadDir('public/uploads/')
26+
->setUploadedFileNamePattern('[randomhash].[extension]')
27+
->setRequired(false)
28+
->showPreview(false);
29+
}
30+
}

tests/Functional/Fields/Media/ImageFieldTest.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace EasyCorp\Bundle\EasyAdminBundle\Tests\Functional\Fields\Media;
44

55
use EasyCorp\Bundle\EasyAdminBundle\Tests\Functional\AbstractFieldFunctionalTest;
6+
use EasyCorp\Bundle\EasyAdminBundle\Tests\Functional\Apps\DefaultApp\Controller\Synthetic\ImageFieldNoPreviewCrudController;
67

78
class ImageFieldTest extends AbstractFieldFunctionalTest
89
{
@@ -113,6 +114,37 @@ public function testImageFieldNewFormHasEmptyPreviewContainer(): void
113114
static::assertCount(0, $previewImages, 'No image thumbnails should exist in new form preview');
114115
}
115116

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+
116148
public function testImageFieldWithDifferentExtensions(): void
117149
{
118150
$extensions = ['jpg', 'png', 'gif', 'webp'];

0 commit comments

Comments
 (0)