From 82e74faf1ba3a7227af7483649b364712b07e22e Mon Sep 17 00:00:00 2001 From: Dragos Protung Date: Wed, 22 May 2024 19:04:12 +0200 Subject: [PATCH] Re-enable batch delete if delete is re-enabled and re-enable delete if batch delete is re-enabled --- src/Config/Actions.php | 7 ++++++ tests/Config/ActionsTest.php | 43 ++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 tests/Config/ActionsTest.php diff --git a/src/Config/Actions.php b/src/Config/Actions.php index 1e929ae0c1..86cf5bbb0e 100644 --- a/src/Config/Actions.php +++ b/src/Config/Actions.php @@ -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; diff --git a/tests/Config/ActionsTest.php b/tests/Config/ActionsTest.php new file mode 100644 index 0000000000..f581a197cf --- /dev/null +++ b/tests/Config/ActionsTest.php @@ -0,0 +1,43 @@ +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()); + } +}