Completed
Push — locale-in-url ( b918e2...821ef5 )
by Kamil
48:02 queued 26:12
created

OrderShowMenuBuilderSpec   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 108
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 8

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 8
dl 0
loc 108
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A let() 0 7 1
A it_is_initializable() 0 4 1
A it_creates_an_order_show_menu() 0 47 1
B it_creates_an_order_show_menu_when_cancel_transition_is_impossible() 0 34 1
A it_returns_an_empty_order_show_menu_when_there_is_no_order_in_options() 0 9 1
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace spec\Sylius\Bundle\AdminBundle\Menu;
13
14
use Knp\Menu\FactoryInterface;
15
use Knp\Menu\ItemInterface;
16
use PhpSpec\ObjectBehavior;
17
use Prophecy\Argument;
18
use SM\Factory\FactoryInterface as StateMachineFactoryInterface;
19
use SM\StateMachine\StateMachineInterface;
20
use Sylius\Bundle\AdminBundle\Menu\OrderShowMenuBuilder;
21
use Sylius\Bundle\UiBundle\Menu\Event\MenuBuilderEvent;
22
use Sylius\Component\Core\Model\OrderInterface;
23
use Sylius\Component\Order\OrderTransitions;
24
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
25
26
/**
27
 * @author Grzegorz Sadowski <[email protected]>
28
 */
29
final class OrderShowMenuBuilderSpec extends ObjectBehavior
30
{
31
    function let(
32
        FactoryInterface $factory,
33
        EventDispatcherInterface $eventDispatcher,
34
        StateMachineFactoryInterface $stateMachineFactory
35
    ) {
36
        $this->beConstructedWith($factory, $eventDispatcher, $stateMachineFactory);
37
    }
38
39
    function it_is_initializable()
40
    {
41
        $this->shouldHaveType(OrderShowMenuBuilder::class);
42
    }
43
44
    function it_creates_an_order_show_menu(
45
        FactoryInterface $factory,
46
        EventDispatcherInterface $eventDispatcher,
47
        StateMachineFactoryInterface $stateMachineFactory,
48
        ItemInterface $menu,
49
        StateMachineInterface $stateMachine,
50
        OrderInterface $order
51
    ) {
52
        $factory->createItem('root')->willReturn($menu);
53
54
        $order->getId()->willReturn(7);
55
56
        $menu
57
            ->addChild('order_history', [
58
                'route' => 'sylius_admin_order_history',
59
                'routeParameters' => ['id' => 7]
60
            ])
61
            ->shouldBeCalled()
62
            ->willReturn($menu)
63
        ;
64
        $menu->setAttribute('type', 'link')->shouldBeCalled()->willReturn($menu);
65
        $menu->setLabel('sylius.ui.history')->shouldBeCalled()->willReturn($menu);
66
        $menu->setLabelAttribute('icon', 'history')->shouldBeCalled()->willReturn($menu);
67
68
        $stateMachineFactory->get($order, OrderTransitions::GRAPH)->willReturn($stateMachine);
69
        $stateMachine->can(OrderTransitions::TRANSITION_CANCEL)->willReturn(true);
70
71
        $menu
72
            ->addChild('cancel', [
73
                'route' => 'sylius_admin_order_cancel',
74
                'routeParameters' => ['id' => 7]
75
            ])
76
            ->shouldBeCalled()
77
            ->willReturn($menu)
78
        ;
79
        $menu->setAttribute('type', 'transition')->shouldBeCalled()->willReturn($menu);
80
        $menu->setLabel('sylius.ui.cancel')->shouldBeCalled()->willReturn($menu);
81
        $menu->setLabelAttribute('icon', 'ban')->shouldBeCalled()->willReturn($menu);
82
        $menu->setLabelAttribute('color', 'yellow')->shouldBeCalled()->willReturn($menu);
83
84
        $eventDispatcher
85
            ->dispatch('sylius.menu.admin.order.show', Argument::type(MenuBuilderEvent::class))
86
            ->shouldBeCalled()
87
        ;
88
89
        $this->createMenu(['order' => $order])->shouldReturn($menu);
90
    }
91
92
    function it_creates_an_order_show_menu_when_cancel_transition_is_impossible(
93
        FactoryInterface $factory,
94
        EventDispatcherInterface $eventDispatcher,
95
        StateMachineFactoryInterface $stateMachineFactory,
96
        ItemInterface $menu,
97
        StateMachineInterface $stateMachine,
98
        OrderInterface $order
99
    ) {
100
        $factory->createItem('root')->willReturn($menu);
101
102
        $order->getId()->willReturn(7);
103
104
        $menu
105
            ->addChild('order_history', [
106
                'route' => 'sylius_admin_order_history',
107
                'routeParameters' => ['id' => 7]
108
            ])
109
            ->shouldBeCalled()
110
            ->willReturn($menu)
111
        ;
112
        $menu->setAttribute('type', 'link')->shouldBeCalled()->willReturn($menu);
113
        $menu->setLabel('sylius.ui.history')->shouldBeCalled()->willReturn($menu);
114
        $menu->setLabelAttribute('icon', 'history')->shouldBeCalled()->willReturn($menu);
115
116
        $stateMachineFactory->get($order, OrderTransitions::GRAPH)->willReturn($stateMachine);
117
        $stateMachine->can(OrderTransitions::TRANSITION_CANCEL)->willReturn(false);
118
119
        $eventDispatcher
120
            ->dispatch('sylius.menu.admin.order.show', Argument::type(MenuBuilderEvent::class))
121
            ->shouldBeCalled()
122
        ;
123
124
        $this->createMenu(['order' => $order])->shouldReturn($menu);
125
    }
126
127
    function it_returns_an_empty_order_show_menu_when_there_is_no_order_in_options(
128
        FactoryInterface $factory,
129
        ItemInterface $menu
130
    ) {
131
132
        $factory->createItem('root')->willReturn($menu);
133
134
        $this->createMenu([])->shouldReturn($menu);
135
    }
136
}
137