Skip to content

Commit 9cd95ee

Browse files
committed
Add tests
1 parent 3f9a759 commit 9cd95ee

2 files changed

Lines changed: 81 additions & 0 deletions

File tree

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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\FormField;
7+
use EasyCorp\Bundle\EasyAdminBundle\Field\IdField;
8+
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
9+
use EasyCorp\Bundle\EasyAdminBundle\Tests\Functional\Apps\DefaultApp\Entity\Synthetic\FormTestEntity;
10+
11+
/**
12+
* @extends AbstractCrudController<FormTestEntity>
13+
*/
14+
class FormFieldsetHtmlAttributesCrudController extends AbstractCrudController
15+
{
16+
public static function getEntityFqcn(): string
17+
{
18+
return FormTestEntity::class;
19+
}
20+
21+
public function configureFields(string $pageName): iterable
22+
{
23+
yield IdField::new('id')->hideOnForm();
24+
25+
yield FormField::addFieldset('Fieldset With Html Attribute')
26+
->setHtmlAttribute('data-foo', 'bar')
27+
->setHtmlAttribute('class', 'custom-fieldset-class');
28+
yield TextField::new('name');
29+
30+
yield FormField::addFieldset('Fieldset With Form Type Options')
31+
->setFormTypeOptions(['attr' => ['data-baz' => 'qux']]);
32+
yield TextField::new('description');
33+
}
34+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
namespace EasyCorp\Bundle\EasyAdminBundle\Tests\Functional\FormLayout;
4+
5+
use EasyCorp\Bundle\EasyAdminBundle\Test\AbstractCrudTestCase;
6+
use EasyCorp\Bundle\EasyAdminBundle\Tests\Functional\Apps\DefaultApp\Controller\DashboardController;
7+
use EasyCorp\Bundle\EasyAdminBundle\Tests\Functional\Apps\DefaultApp\Controller\Synthetic\FormFieldsetHtmlAttributesCrudController;
8+
9+
/**
10+
* Regression test for #6285 / PR #7593: HTML attributes set via
11+
* setHtmlAttribute() or setFormTypeOptions(['attr' => ...]) on a fieldset
12+
* must reach the rendered .form-fieldset wrapper div.
13+
*/
14+
class FormFieldsetHtmlAttributesTest extends AbstractCrudTestCase
15+
{
16+
protected function getControllerFqcn(): string
17+
{
18+
return FormFieldsetHtmlAttributesCrudController::class;
19+
}
20+
21+
protected function getDashboardFqcn(): string
22+
{
23+
return DashboardController::class;
24+
}
25+
26+
public function testSetHtmlAttributeIsRenderedOnFieldsetWrapper(): void
27+
{
28+
$crawler = $this->client->request('GET', $this->generateNewFormUrl());
29+
30+
$fieldset = $crawler->filter('.form-fieldset[data-foo="bar"]');
31+
32+
static::assertCount(1, $fieldset, 'Custom data-* attribute set via setHtmlAttribute() should be rendered on the .form-fieldset wrapper');
33+
static::assertStringContainsString('custom-fieldset-class', $fieldset->attr('class'), 'Custom class set via setHtmlAttribute() should be merged into the wrapper class list');
34+
static::assertStringContainsString('form-fieldset', $fieldset->attr('class'), 'The default form-fieldset class must be preserved alongside the custom class');
35+
}
36+
37+
public function testSetFormTypeOptionsAttrIsRenderedOnFieldsetWrapper(): void
38+
{
39+
$crawler = $this->client->request('GET', $this->generateNewFormUrl());
40+
41+
static::assertCount(
42+
1,
43+
$crawler->filter('.form-fieldset[data-baz="qux"]'),
44+
'Custom attribute set via setFormTypeOptions([\'attr\' => ...]) should be rendered on the .form-fieldset wrapper'
45+
);
46+
}
47+
}

0 commit comments

Comments
 (0)