-
-
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 #4196 Fixed the handling of label callables (javiereguiluz)
This PR was squashed before being merged into the 3.0.x-dev branch. Discussion ---------- Fixed the handling of label callables Fixes #4176. Commits ------- b66498b Fixed the handling of label callables
- Loading branch information
Showing
2 changed files
with
63 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
namespace EasyCorp\Bundle\EasyAdminBundle\Tests\Dto; | ||
|
||
use EasyCorp\Bundle\EasyAdminBundle\Dto\CrudDto; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class CrudDtoTest extends TestCase | ||
{ | ||
/** | ||
* @dataProvider provideLabels | ||
* | ||
* @param string|closure|null $setLabel | ||
*/ | ||
public function testGetEntityLabelInSingular($setLabel, ?string $expectedGetLabel) | ||
{ | ||
$crudDto = new CrudDto(); | ||
|
||
if (null !== $setLabel) { | ||
$crudDto->setEntityLabelInSingular($setLabel); | ||
$crudDto->setEntityLabelInPlural($setLabel); | ||
} | ||
|
||
$entityInstance = new class() { | ||
public function getPrimaryKeyValue() | ||
{ | ||
return '42'; | ||
} | ||
}; | ||
$this->assertSame($expectedGetLabel, $crudDto->getEntityLabelInSingular($entityInstance)); | ||
$this->assertSame($expectedGetLabel, $crudDto->getEntityLabelInPlural($entityInstance)); | ||
} | ||
|
||
public function provideLabels() | ||
{ | ||
yield [null, null]; | ||
yield ['', '']; | ||
yield ['foo', 'foo']; | ||
yield ['Foo Bar', 'Foo Bar']; | ||
// see https://github.com/EasyCorp/EasyAdminBundle/issues/4176 | ||
yield ['link', 'link']; | ||
yield [fn () => null, null]; | ||
yield [fn () => '', '']; | ||
yield [fn () => 'foo', 'foo']; | ||
yield [fn () => 'Foo Bar', 'Foo Bar']; | ||
yield [fn () => 'link', 'link']; | ||
yield [fn ($entityInstance) => 'Entity #'.$entityInstance->getPrimaryKeyValue(), 'Entity #42']; | ||
} | ||
} |