-
-
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.
fix: setting html attribute to fields also adds them to the index page
- Loading branch information
1 parent
df81f10
commit c7b2d5e
Showing
5 changed files
with
117 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
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,41 @@ | ||
<?php | ||
|
||
namespace EasyCorp\Bundle\EasyAdminBundle\Tests\Controller; | ||
|
||
use Doctrine\ORM\EntityRepository; | ||
use EasyCorp\Bundle\EasyAdminBundle\Test\AbstractCrudTestCase; | ||
use EasyCorp\Bundle\EasyAdminBundle\Tests\TestApplication\Controller\CustomFieldAttributeCrudController; | ||
use EasyCorp\Bundle\EasyAdminBundle\Tests\TestApplication\Controller\SecureDashboardController; | ||
use EasyCorp\Bundle\EasyAdminBundle\Tests\TestApplication\Entity\Category; | ||
|
||
class CustomFieldAttributeControllerTest extends AbstractCrudTestCase | ||
{ | ||
protected EntityRepository $categories; | ||
|
||
protected function getControllerFqcn(): string | ||
{ | ||
return CustomFieldAttributeCrudController::class; | ||
} | ||
|
||
protected function getDashboardFqcn(): string | ||
{ | ||
return SecureDashboardController::class; | ||
} | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
$this->client->followRedirects(); | ||
$this->client->setServerParameters(['PHP_AUTH_USER' => 'admin', 'PHP_AUTH_PW' => '1234']); | ||
|
||
$this->categories = $this->entityManager->getRepository(Category::class); | ||
} | ||
|
||
public function testItAddsAttributesToTd(): void | ||
{ | ||
$crawler = $this->client->request('GET', $this->generateIndexUrl()); | ||
|
||
static::assertCount(20, $crawler->filter('td[multi-test-one="test1"]')); | ||
static::assertCount(20, $crawler->filter('td[multi-test-two="test2"]')); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
tests/TestApplication/src/Controller/CustomFieldAttributeCrudController.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,48 @@ | ||
<?php | ||
|
||
namespace EasyCorp\Bundle\EasyAdminBundle\Tests\TestApplication\Controller; | ||
|
||
use EasyCorp\Bundle\EasyAdminBundle\Config\Action; | ||
use EasyCorp\Bundle\EasyAdminBundle\Config\Actions; | ||
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud; | ||
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController; | ||
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField; | ||
use EasyCorp\Bundle\EasyAdminBundle\Tests\TestApplication\Entity\Category; | ||
|
||
/** | ||
* Tests the configureActions() method and the generated actions. | ||
*/ | ||
class CustomFieldAttributeCrudController extends AbstractCrudController | ||
{ | ||
public static function getEntityFqcn(): string | ||
{ | ||
return Category::class; | ||
} | ||
|
||
public function configureFields(string $pageName): iterable | ||
{ | ||
return [ | ||
TextField::new('name') | ||
->setHtmlAttribute('multi-test-one', 'test1') | ||
->setHtmlAttribute('multi-test-two', 'test2'), | ||
]; | ||
} | ||
|
||
public function configureActions(Actions $actions): Actions | ||
{ | ||
$action1 = Action::new('action1')->linkToCrudAction(''); | ||
$action2 = Action::new('action2')->linkToCrudAction('')->setCssClass('foo'); | ||
$action3 = Action::new('action3')->linkToCrudAction('')->addCssClass('bar'); | ||
$action4 = Action::new('action4')->linkToCrudAction('')->setCssClass('foo')->addCssClass('bar'); | ||
|
||
return $actions | ||
->add(Crud::PAGE_INDEX, $action1) | ||
->add(Crud::PAGE_INDEX, $action2) | ||
->add(Crud::PAGE_INDEX, $action3) | ||
->add(Crud::PAGE_INDEX, $action4) | ||
->update(Crud::PAGE_INDEX, Action::NEW, function (Action $action) { | ||
return $action->setIcon('fa fa-fw fa-plus')->setLabel(false); | ||
}) | ||
; | ||
} | ||
} |