-
-
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 #6028 Pass the original value to formatValue() method (javieregui…
…luz) This PR was squashed before being merged into the 4.x branch. Discussion ---------- Pass the original value to formatValue() method Fixes #5941. The `formatValue()` callable should always receive the original field value, not the formatted one. Commits ------- ec051b0 Pass the original value to formatValue() method
- Loading branch information
Showing
5 changed files
with
71 additions
and
3 deletions.
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
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,40 @@ | ||
<?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\FormFieldValueController; | ||
use EasyCorp\Bundle\EasyAdminBundle\Tests\TestApplication\Entity\BlogPost; | ||
|
||
class FormFieldValueControllerTest 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 FormFieldValueController::class; | ||
} | ||
|
||
protected function getDashboardFqcn(): string | ||
{ | ||
return DashboardController::class; | ||
} | ||
|
||
public function testFieldsFormatValue() | ||
{ | ||
$this->client->request('GET', $this->generateIndexUrl()); | ||
|
||
static::assertSelectorTextSame('td[data-column="title"]', 'Blog Post 0'); | ||
static::assertSelectorTextSame('td[data-column="createdAt"]', '20201101090000'); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
tests/TestApplication/src/Controller/FormFieldValueController.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,28 @@ | ||
<?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\TextField; | ||
use EasyCorp\Bundle\EasyAdminBundle\Tests\TestApplication\Entity\BlogPost; | ||
|
||
class FormFieldValueController extends AbstractCrudController | ||
{ | ||
public static function getEntityFqcn(): string | ||
{ | ||
return BlogPost::class; | ||
} | ||
|
||
public function configureFields(string $pageName): iterable | ||
{ | ||
// these fields format the original value with some options (e.g. max length) | ||
// and then use the formatValue() method to test that this method receives the | ||
// original field value, not the one modified with the other options | ||
return [ | ||
TextField::new('title')->setMaxLength(2)->formatValue(fn ($value, $entity) => $value), | ||
DateTimeField::new('createdAt')->setFormat('long', 'long') | ||
->formatValue(fn (/** @var \DateTimeInterface $value */ $value, $entity) => date('YmdHis', $value->getTimestamp())), | ||
]; | ||
} | ||
} |