-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bug #5982 Fix the rendering of HTML contents in translated help messa…
…ges (javiereguiluz) This PR was squashed before being merged into the 4.x branch. Discussion ---------- Fix the rendering of HTML contents in translated help messages Fixes a minor issue introduced in #5973. Commits ------- 4b170b9 Fix the rendering of HTML contents in translated help messages
- Loading branch information
Showing
3 changed files
with
84 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
namespace EasyCorp\Bundle\EasyAdminBundle\Tests\Controller; | ||
|
||
use Doctrine\ORM\EntityRepository; | ||
use EasyCorp\Bundle\EasyAdminBundle\Test\AbstractCrudTestCase; | ||
use EasyCorp\Bundle\EasyAdminBundle\Tests\TestApplication\Controller\DashboardController; | ||
use EasyCorp\Bundle\EasyAdminBundle\Tests\TestApplication\Controller\FormFieldHelpController; | ||
use EasyCorp\Bundle\EasyAdminBundle\Tests\TestApplication\Entity\BlogPost; | ||
|
||
class FormFieldHelpControllerTest extends AbstractCrudTestCase | ||
{ | ||
protected EntityRepository $blogPosts; | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
$this->client->followRedirects(); | ||
|
||
$this->blogPosts = $this->entityManager->getRepository(BlogPost::class); | ||
} | ||
|
||
protected function getControllerFqcn(): string | ||
{ | ||
return FormFieldHelpController::class; | ||
} | ||
|
||
protected function getDashboardFqcn(): string | ||
{ | ||
return DashboardController::class; | ||
} | ||
|
||
public function testFieldsWithoutHelp() | ||
{ | ||
$crawler = $this->client->request('GET', $this->generateNewFormUrl()); | ||
|
||
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.'); | ||
|
||
static::assertSame('<b>Lorem</b> Ipsum <em class="foo">2</em>', $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.'); | ||
|
||
static::assertSame('Lorem <a href="https://example.com">Ipsum</a> <b>4</b>', $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.'); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
tests/TestApplication/src/Controller/FormFieldHelpController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
namespace EasyCorp\Bundle\EasyAdminBundle\Tests\TestApplication\Controller; | ||
|
||
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController; | ||
use EasyCorp\Bundle\EasyAdminBundle\Field\DateTimeField; | ||
use EasyCorp\Bundle\EasyAdminBundle\Field\IdField; | ||
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField; | ||
use EasyCorp\Bundle\EasyAdminBundle\Tests\TestApplication\Entity\BlogPost; | ||
use function Symfony\Component\Translation\t; | ||
|
||
/** | ||
* Used to test the ->setHelp() method of fields and how that | ||
* help message is rendered in the form. | ||
*/ | ||
class FormFieldHelpController extends AbstractCrudController | ||
{ | ||
public static function getEntityFqcn(): string | ||
{ | ||
return BlogPost::class; | ||
} | ||
|
||
public function configureFields(string $pageName): iterable | ||
{ | ||
return [ | ||
IdField::new('id'), // this field doesn't define a help message on purpose | ||
TextField::new('title')->setHelp(''), | ||
TextField::new('slug')->setHelp('Lorem Ipsum 1'), | ||
TextField::new('content')->setHelp('<b>Lorem</b> Ipsum <em class="foo">2</em>'), | ||
DateTimeField::new('createdAt')->setHelp(t('Lorem Ipsum 3')), | ||
DateTimeField::new('publishedAt')->setHelp(t('Lorem <a href="https://example.com">Ipsum</a> <b>4</b>')), | ||
]; | ||
} | ||
} |