Skip to content

Commit

Permalink
Re-enable batch delete if delete is re-enabled and re-enable delete i…
Browse files Browse the repository at this point in the history
…f batch delete is re-enabled
  • Loading branch information
dragosprotung committed Nov 29, 2024
1 parent dd5fa35 commit 436d06f
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/Config/Actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,13 @@ public function disable(string ...$disabledActionNames): self

public function enable(string ...$enabledActionNames): self
{
// if 'delete' or 'batch delete' is enabled, both are enabled automatically.
// This is the most common case, but user can re-disable the action if needed manually
if (\in_array(Action::DELETE, $enabledActionNames, true) || \in_array(Action::BATCH_DELETE, $enabledActionNames, true)) {
$enabledActionNames[] = Action::DELETE;
$enabledActionNames[] = Action::BATCH_DELETE;
}

$this->dto->enableActions($enabledActionNames);

return $this;
Expand Down
43 changes: 43 additions & 0 deletions tests/Config/ActionsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace EasyCorp\Bundle\EasyAdminBundle\Tests\Config;

use EasyCorp\Bundle\EasyAdminBundle\Config\Action;
use EasyCorp\Bundle\EasyAdminBundle\Config\Actions;
use PHPUnit\Framework\TestCase;

class ActionsTest extends TestCase
{
public function testEnableDeleteAction(): void
{
$actions = Actions::new();
$actions->disable(Action::DELETE);

$this->assertSame(['delete', 'batchDelete'], $actions->getAsDto(null)->getDisabledActions());

$actions->enable(Action::DELETE);
$this->assertSame([], $actions->getAsDto(null)->getDisabledActions());
}

public function testEnableBatchDeleteAction(): void
{
$actions = Actions::new();
$actions->disable(Action::BATCH_DELETE);

$this->assertSame(['batchDelete'], $actions->getAsDto(null)->getDisabledActions());

$actions->enable(Action::BATCH_DELETE);
$this->assertSame([], $actions->getAsDto(null)->getDisabledActions());
}

public function testEnableBatchDeleteActionWillEnableDeleteAsWell(): void
{
$actions = Actions::new();
$actions->disable(Action::DELETE, Action::BATCH_DELETE);

$this->assertSame(['delete', 'batchDelete'], $actions->getAsDto(null)->getDisabledActions());

$actions->enable(Action::BATCH_DELETE);
$this->assertSame([], $actions->getAsDto(null)->getDisabledActions());
}
}

0 comments on commit 436d06f

Please sign in to comment.