|
| 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