diff --git a/src/Config/Actions.php b/src/Config/Actions.php index a91ab961b8..1e929ae0c1 100644 --- a/src/Config/Actions.php +++ b/src/Config/Actions.php @@ -132,6 +132,13 @@ public function disable(string ...$disabledActionNames): self return $this; } + public function enable(string ...$enabledActionNames): self + { + $this->dto->enableActions($enabledActionNames); + + return $this; + } + public function getAsDto(?string $pageName): ActionConfigDto { $this->dto->setPageName($pageName); diff --git a/src/Dto/ActionConfigDto.php b/src/Dto/ActionConfigDto.php index e46325d09d..962e70f6b8 100644 --- a/src/Dto/ActionConfigDto.php +++ b/src/Dto/ActionConfigDto.php @@ -98,6 +98,11 @@ public function disableActions(array $actionNames): void } } + public function enableActions(array $actionNames): void + { + $this->disabledActions = array_values(array_diff($this->disabledActions, $actionNames)); + } + public function getActions(): ActionCollection|array { return null === $this->pageName ? $this->actions : ActionCollection::new($this->actions[$this->pageName]); diff --git a/tests/Dto/ActionConfigDtoTest.php b/tests/Dto/ActionConfigDtoTest.php new file mode 100644 index 0000000000..b32e27a49f --- /dev/null +++ b/tests/Dto/ActionConfigDtoTest.php @@ -0,0 +1,32 @@ + [[], ['foo', 'bar', 'baz', 'qux']]; + yield 'enable action not disabled' => [['not-disabled'], ['foo', 'bar', 'baz', 'qux']]; + yield 'enable 1 action' => [['bar'], ['foo', 'baz', 'qux']]; + yield 'enable multiple action' => [['foo', 'baz'], ['bar', 'qux']]; + yield 'enable all' => [['foo', 'bar', 'baz', 'qux'], []]; + } + + /** + * @dataProvider provideLabels + */ + public function testEnableActions(array $actionsToEnable, array $expectedDisabledActions): void + { + $actionConfigDto = new ActionConfigDto(); + $actionConfigDto->disableActions(['foo', 'bar', 'baz', 'qux']); + + $this->assertSame(['foo', 'bar', 'baz', 'qux'], $actionConfigDto->getDisabledActions()); + + $actionConfigDto->enableActions($actionsToEnable); + $this->assertSame($expectedDisabledActions, $actionConfigDto->getDisabledActions()); + } +}