diff --git a/demos/_unit-test/useraction-no-id-arg.php b/demos/_unit-test/useraction-no-id-arg.php new file mode 100644 index 0000000000..cb829eaf09 --- /dev/null +++ b/demos/_unit-test/useraction-no-id-arg.php @@ -0,0 +1,22 @@ +db); +DemoActionsUtil::setupDemoActions($country); + +$buttons = View::addTo($app, ['ui' => 'vertical basic buttons']); + +foreach ($country->getUserActions() as $action) { + $b = Button::addTo($buttons, [$action->getCaption()]); + $b->on('click', $action); // action is intentionally not bound to entity nor ID arg is passed to executor +} diff --git a/src/UserAction/ConfirmationExecutor.php b/src/UserAction/ConfirmationExecutor.php index 393f46f3de..db42c138e7 100644 --- a/src/UserAction/ConfirmationExecutor.php +++ b/src/UserAction/ConfirmationExecutor.php @@ -117,6 +117,8 @@ public function executeModelAction(): void $this->action = $this->executeModelActionLoad($this->action); $this->loader->set(function (Loader $p) { + $this->action->validateBeforeExecute(); + if ($this->step === 'execute') { $this->doFinal($p); } else { diff --git a/src/UserAction/StepExecutorTrait.php b/src/UserAction/StepExecutorTrait.php index 7f184cdeb9..5d3642ad3d 100644 --- a/src/UserAction/StepExecutorTrait.php +++ b/src/UserAction/StepExecutorTrait.php @@ -101,6 +101,8 @@ protected function setFormField(Form $form, array $fields, string $step): Form protected function runSteps(): void { $this->loader->set(function (Loader $p) { + $this->action->validateBeforeExecute(); + switch ($this->step) { case 'args': $this->doArgs($p); diff --git a/tests-behat/useraction.feature b/tests-behat/useraction.feature index 07ee7d158c..a6a76d7257 100644 --- a/tests-behat/useraction.feature +++ b/tests-behat/useraction.feature @@ -79,3 +79,34 @@ Feature: UserAction executor and UserConfirmation modal Then No toast should be displayed When I click using selector "//tr[td[text()='Argentina']]//div.ui.dropdown[div[text()='Actions...']]//div.menu/div[text()='Callback']" Then Toast display should contain text "Success: callback execute using country Argentina" + + Scenario: validate user action earlier than before execute, exception is displayed + Given I am on "_unit-test/useraction-no-id-arg.php" + When I press button "Disabled" + Then Modal is open with text "Atk4\Data\Exception: User action is disabled" + Then I hide js modal + When I press button "Add" + Then Modal is open with text "Add Country" + Then I hide js modal + When I press button "Edit" + Then Modal is open with text "Atk4\Data\Exception: User action can be executed on loaded entity only" + Then I hide js modal + When I press button "Delete" + Then I press Modal button "Ok" + Then Modal is open with text "Atk4\Data\Exception: User action can be executed on loaded entity only" + Then I hide js modal + When I press button "Callback" + Then Modal is open with text "Atk4\Data\Exception: User action can be executed on loaded entity only" + Then I hide js modal + When I press button "Preview" + Then Modal is open with text "Atk4\Data\Exception: User action can be executed on loaded entity only" + Then I hide js modal + When I press button "Argument" + Then Modal is open with text "Atk4\Data\Exception: User action can be executed on loaded entity only" + Then I hide js modal + When I press button "User Confirmation" + Then Modal is open with text "Atk4\Data\Exception: User action can be executed on loaded entity only" + Then I hide js modal + When I press button "Multi Step" + Then Modal is open with text "Atk4\Data\Exception: User action can be executed on loaded entity only" + Then I hide js modal