From 08148e098977be7cc261d0072ab77ab2e897c7ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Fr=C3=A9mont?= Date: Tue, 6 Jun 2023 15:29:59 +0200 Subject: [PATCH] [GridBuilder] Apply transition action --- .../Builder/Action/ApplyTransitionAction.php | 34 +++++++++ .../Action/ApplyTransitionActionSpec.php | 72 +++++++++++++++++++ 2 files changed, 106 insertions(+) create mode 100644 src/Bundle/Builder/Action/ApplyTransitionAction.php create mode 100644 src/Bundle/spec/Builder/Action/ApplyTransitionActionSpec.php diff --git a/src/Bundle/Builder/Action/ApplyTransitionAction.php b/src/Bundle/Builder/Action/ApplyTransitionAction.php new file mode 100644 index 00000000..e6600411 --- /dev/null +++ b/src/Bundle/Builder/Action/ApplyTransitionAction.php @@ -0,0 +1,34 @@ + [ + 'route' => $route, + 'parameters' => $routeParameters, + ], + 'transition' => $name, + ], $options); + + $action->setOptions($options); + + return $action; + } +} diff --git a/src/Bundle/spec/Builder/Action/ApplyTransitionActionSpec.php b/src/Bundle/spec/Builder/Action/ApplyTransitionActionSpec.php new file mode 100644 index 00000000..69ace56d --- /dev/null +++ b/src/Bundle/spec/Builder/Action/ApplyTransitionActionSpec.php @@ -0,0 +1,72 @@ +shouldHaveType(ApplyTransitionAction::class); + } + + function it_builds_apply_transition_actions(): void + { + $action = $this::create('publish', 'app_book_publish', ['id' => 'resource.id']); + + $action->shouldHaveType(ActionInterface::class); + $action->toArray()->shouldReturn([ + 'type' => 'apply_transition', + 'options' => [ + 'link' => [ + 'route' => 'app_book_publish', + 'parameters' => ['id' => 'resource.id'], + ], + 'transition' => 'publish', + ], + ]); + } + + function it_builds_apply_transition_with_options(): void + { + $action = $this::create( + 'publish', + 'app_book_publish', + [ + 'id' => 'resource.id', + ], + [ + 'class' => 'green', + 'graph' => 'sylius_book_publishing', + ], + ); + + $action->shouldHaveType(ActionInterface::class); + $action->toArray()->shouldReturn([ + 'type' => 'apply_transition', + 'options' => [ + 'link' => [ + 'route' => 'app_book_publish', + 'parameters' => ['id' => 'resource.id'], + ], + 'transition' => 'publish', + 'class' => 'green', + 'graph' => 'sylius_book_publishing', + ], + ]); + } +}