diff --git a/tests/Controller/FormFieldHelpControllerTest.php b/tests/Controller/FormFieldHelpControllerTest.php index 3c2e279782..ffcdf781a3 100644 --- a/tests/Controller/FormFieldHelpControllerTest.php +++ b/tests/Controller/FormFieldHelpControllerTest.php @@ -34,16 +34,35 @@ public function testFieldsHelpMessages() { $crawler = $this->client->request('GET', $this->generateNewFormUrl()); + // fields with no help defined + static::assertSelectorNotExists('#tab-tab-1 .tab-help', 'The Tab 1 does not define a help message.'); + static::assertSelectorNotExists('.form-column.column-1 .form-column-help', 'The Column 1 does not define a help message.'); + static::assertSelectorNotExists('.form-fieldset-title:contains("Fieldset 1") .form-fieldset-help', 'The Fieldset 1 does not define a help message.'); static::assertSelectorNotExists('.form-group #BlogPost_id + .form-help', 'The ID field does not define a help message.'); - static::assertSelectorNotExists('.form-group #BlogPost_title + .form-help', 'The title field defines an empty string as a help message, so it does not render an HTML element for that help message.'); - static::assertSelectorTextContains('.form-group #BlogPost_slug + .form-help', 'Lorem Ipsum 1', 'The slug field defines a text help message.'); + // fields with help defined as simple text strings + static::assertSelectorTextContains('#tab-tab-2 .tab-help', 'Tab 2 Lorem Ipsum', 'The Tab 2 field defines a text help message.'); + static::assertSelectorTextContains('.form-column.column-2 .form-column-help', 'Column 2 Lorem Ipsum', 'The Column 2 field defines a text help message.'); + static::assertSelectorTextContains('.form-fieldset-title:contains("Fieldset 2") .form-fieldset-help', 'Fieldset 2 Lorem Ipsum', 'The Fieldset 2 field defines a text help message.'); + static::assertSelectorTextContains('.form-group #BlogPost_slug + .form-help', 'Slug Lorem Ipsum', 'The slug field defines a text help message.'); - static::assertSame('Lorem Ipsum 2', $crawler->filter('.form-group #BlogPost_content + .form-help')->html(), 'The content field defines an help message with HTML contents, which must be rendered instead of escaped.'); + // fields with help defined as text strings with HTML contents + static::assertSame('Tab 3 Lorem Ipsum', trim($crawler->filter('#tab-tab-3 .tab-help')->html()), 'The Tab 3 field defines a help message with HTML contents, which must be rendered instead of escaped.'); + static::assertSame('Column 3 Lorem Ipsum', trim($crawler->filter('.form-column.column-3 .form-column-help')->html()), 'The Column 3 field defines a help message with HTML contents, which must be rendered instead of escaped.'); + static::assertSame('Fieldset 3 Lorem Ipsum', trim($crawler->filter('.form-fieldset-title:contains("Fieldset 3") .form-fieldset-help')->html()), 'The Fieldset 3 field defines a help message with HTML contents, which must be rendered instead of escaped.'); + static::assertSame('Content Lorem Ipsum', $crawler->filter('.form-group #BlogPost_content + .form-help')->html(), 'The content field defines an help message with HTML contents, which must be rendered instead of escaped.'); - static::assertSelectorTextContains('.form-group:contains("Created At") .form-help', 'Lorem Ipsum 3', 'The createdAt field defines a translatable text help message.'); + // fields with help defined as Translatable objects using simple text strings + static::assertSelectorTextContains('#tab-tab-4 .tab-help', 'Tab 4 Lorem Ipsum', 'The Tab 4 field defines a translatable text help message.'); + static::assertSelectorTextContains('.form-column.column-4 .form-column-help', 'Column 4 Lorem Ipsum', 'The Column 4 field defines a translatable text help message.'); + static::assertSelectorTextContains('.form-fieldset-title:contains("Fieldset 4") .form-fieldset-help', 'Fieldset 4 Lorem Ipsum', 'The Fieldset 4 field defines a translatable text help message.'); + static::assertSelectorTextContains('.form-group:contains("Created At") .form-help', 'CreatedAt Lorem Ipsum', 'The createdAt field defines a translatable text help message.'); - static::assertSame('Lorem Ipsum 4', $crawler->filter('.form-group:contains("Published At") .form-help')->html(), 'The publishedAt field defines a translatable help message with HTML contents, which must be rendered instead of escaped.'); + // fields with help defined as Translatable objects using text strings with HTML contents + static::assertSelectorTextContains('#tab-tab-5 .tab-help', 'Tab 5 Lorem Ipsum', 'The Tab 5 field defines a translatable help message with HTML contents, which must be rendered instead of escaped.'); + static::assertSelectorTextContains('.form-column.column-5 .form-column-help', 'Column 5 Lorem Ipsum', 'The Column 5 field defines a translatable help message with HTML contents, which must be rendered instead of escaped..'); + static::assertSelectorTextContains('.form-fieldset-title:contains("Fieldset 5") .form-fieldset-help', 'Fieldset 5 Lorem Ipsum', 'The Fieldset 5 field defines a translatable help message with HTML contents, which must be rendered instead of escaped..'); + static::assertSame('PublishedAt Lorem Ipsum', $crawler->filter('.form-group:contains("Published At") .form-help')->html(), 'The publishedAt field defines a translatable help message with HTML contents, which must be rendered instead of escaped.'); } } diff --git a/tests/TestApplication/src/Controller/FormFieldHelpController.php b/tests/TestApplication/src/Controller/FormFieldHelpController.php index a04cc7ad34..c22440389e 100644 --- a/tests/TestApplication/src/Controller/FormFieldHelpController.php +++ b/tests/TestApplication/src/Controller/FormFieldHelpController.php @@ -4,6 +4,7 @@ use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController; use EasyCorp\Bundle\EasyAdminBundle\Field\DateTimeField; +use EasyCorp\Bundle\EasyAdminBundle\Field\FormField; use EasyCorp\Bundle\EasyAdminBundle\Field\IdField; use EasyCorp\Bundle\EasyAdminBundle\Field\TextField; use EasyCorp\Bundle\EasyAdminBundle\Tests\TestApplication\Entity\BlogPost; @@ -23,12 +24,36 @@ public static function getEntityFqcn(): string public function configureFields(string $pageName): iterable { return [ - IdField::new('id'), // this field doesn't define a help message on purpose + // fields with no help defined + FormField::addTab('Tab 1'), + FormField::addColumn()->addCssClass('column-1'), + FormField::addFieldset('Fieldset 1'), + IdField::new('id'), TextField::new('title')->setHelp(''), - TextField::new('slug')->setHelp('Lorem Ipsum 1'), - TextField::new('content')->setHelp('Lorem Ipsum 2'), - DateTimeField::new('createdAt')->setHelp(t('Lorem Ipsum 3')), - DateTimeField::new('publishedAt')->setHelp(t('Lorem Ipsum 4')), + + // fields with help defined as simple text strings + FormField::addTab('Tab 2')->setHelp('Tab 2 Lorem Ipsum'), + FormField::addColumn()->addCssClass('column-2')->setHelp('Column 2 Lorem Ipsum'), + FormField::addFieldset('Fieldset 2')->setHelp('Fieldset 2 Lorem Ipsum'), + TextField::new('slug')->setHelp('Slug Lorem Ipsum'), + + // fields with help defined as text strings with HTML contents + FormField::addTab('Tab 3')->setHelp('Tab 3 Lorem Ipsum'), + FormField::addColumn()->addCssClass('column-3')->setHelp('Column 3 Lorem Ipsum'), + FormField::addFieldset('Fieldset 3')->setHelp('Fieldset 3 Lorem Ipsum'), + TextField::new('content')->setHelp('Content Lorem Ipsum'), + + // fields with help defined as Translatable objects using simple text strings + FormField::addTab('Tab 4')->setHelp(t('Tab 4 Lorem Ipsum')), + FormField::addColumn()->addCssClass('column-4')->setHelp(t('Column 4 Lorem Ipsum')), + FormField::addFieldset('Fieldset 4')->setHelp(t('Fieldset 4 Lorem Ipsum')), + DateTimeField::new('createdAt')->setHelp(t('CreatedAt Lorem Ipsum')), + + // fields with help defined as Translatable objects using text strings with HTML contents + FormField::addTab('Tab 5')->setHelp(t('Tab 5 Lorem Ipsum')), + FormField::addColumn()->addCssClass('column-5')->setHelp(t('Column 5 Lorem Ipsum')), + FormField::addFieldset('Fieldset 5')->setHelp(t('Fieldset 5 Lorem Ipsum')), + DateTimeField::new('publishedAt')->setHelp(t('PublishedAt Lorem Ipsum')), ]; } }