Skip to content

Commit

Permalink
[GridBuilder] Apply transition action
Browse files Browse the repository at this point in the history
  • Loading branch information
loic425 committed Jun 6, 2023
1 parent ca10eda commit 67f2ef8
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/Bundle/Builder/Action/ApplyTransitionAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Sylius\Bundle\GridBundle\Builder\Action;

final class ApplyTransitionAction
{
public static function create(string $name, string $route, array $routeParameters = [], array $options = []): ActionInterface
{
$action = Action::create($name, 'apply_transition');

$options = array_merge([
'link' => [
'route' => $route,
'parameters' => $routeParameters,
],
'transition' => $name,
], $options);

$action->setOptions($options);

return $action;
}
}
61 changes: 61 additions & 0 deletions src/Bundle/spec/Builder/Action/ApplyTransitionActionSpec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace spec\Sylius\Bundle\GridBundle\Builder\Action;

use PhpSpec\ObjectBehavior;
use Sylius\Bundle\GridBundle\Builder\Action\ActionInterface;
use Sylius\Bundle\GridBundle\Builder\Action\ApplyTransitionAction;

final class ApplyTransitionActionSpec extends ObjectBehavior
{
function it_is_initializable(): void
{
$this->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']);

$action->shouldHaveType(ActionInterface::class);
$action->toArray()->shouldReturn([
'type' => 'apply_transition',
'options' => [
'link' => [
'route' => 'app_book_publish',
'parameters' => ['id' => 'resource.id'],
],
'transition' => 'publish',
'class' => 'green',
],
]);
}
}

0 comments on commit 67f2ef8

Please sign in to comment.