|
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
|
|
|
declare(strict_types=1); |
|
13
|
|
|
|
|
14
|
|
|
namespace spec\Sylius\Bundle\AdminBundle\Menu; |
|
15
|
|
|
|
|
16
|
|
|
use Knp\Menu\FactoryInterface; |
|
17
|
|
|
use Knp\Menu\ItemInterface; |
|
18
|
|
|
use PhpSpec\ObjectBehavior; |
|
19
|
|
|
use Prophecy\Argument; |
|
20
|
|
|
use Sylius\Bundle\AdminBundle\Event\CustomerShowMenuBuilderEvent; |
|
21
|
|
|
use Sylius\Component\Core\Model\CustomerInterface; |
|
22
|
|
|
use Sylius\Component\User\Model\UserInterface; |
|
23
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
|
24
|
|
|
|
|
25
|
|
|
final class CustomerShowMenuBuilderSpec extends ObjectBehavior |
|
26
|
|
|
{ |
|
27
|
|
|
function let( |
|
28
|
|
|
FactoryInterface $factory, |
|
29
|
|
|
EventDispatcherInterface $eventDispatcher |
|
30
|
|
|
): void { |
|
31
|
|
|
$this->beConstructedWith($factory, $eventDispatcher); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
function it_creates_a_customer_show_menu_for_customer_with_user( |
|
35
|
|
|
FactoryInterface $factory, |
|
36
|
|
|
EventDispatcherInterface $eventDispatcher, |
|
37
|
|
|
ItemInterface $menu, |
|
38
|
|
|
CustomerInterface $customer, |
|
39
|
|
|
UserInterface $user |
|
40
|
|
|
): void { |
|
41
|
|
|
$factory->createItem('root')->willReturn($menu); |
|
42
|
|
|
|
|
43
|
|
|
$customer->getId()->willReturn(7); |
|
44
|
|
|
$customer->getUser()->willReturn($user); |
|
45
|
|
|
$user->getId()->willReturn(4); |
|
46
|
|
|
|
|
47
|
|
|
$menu->setExtra('column_id', 'actions')->shouldBeCalled()->willReturn($menu); |
|
48
|
|
|
|
|
49
|
|
|
$menu |
|
50
|
|
|
->addChild('update', [ |
|
51
|
|
|
'route' => 'sylius_admin_customer_update', |
|
52
|
|
|
'routeParameters' => ['id' => 7], |
|
53
|
|
|
]) |
|
54
|
|
|
->shouldBeCalled() |
|
55
|
|
|
->willReturn($menu) |
|
56
|
|
|
; |
|
57
|
|
|
$menu->setAttribute('type', 'edit')->shouldBeCalled()->willReturn($menu); |
|
58
|
|
|
$menu->setLabel('sylius.ui.edit')->shouldBeCalled()->willReturn($menu); |
|
59
|
|
|
|
|
60
|
|
|
$menu |
|
61
|
|
|
->addChild('order_index', [ |
|
62
|
|
|
'route' => 'sylius_admin_customer_order_index', |
|
63
|
|
|
'routeParameters' => ['id' => 7], |
|
64
|
|
|
]) |
|
65
|
|
|
->shouldBeCalled() |
|
66
|
|
|
->willReturn($menu) |
|
67
|
|
|
; |
|
68
|
|
|
$menu->setAttribute('type', 'show')->shouldBeCalled()->willReturn($menu); |
|
69
|
|
|
$menu->setLabel('sylius.ui.show_orders')->shouldBeCalled()->willReturn($menu); |
|
70
|
|
|
|
|
71
|
|
|
$menu |
|
72
|
|
|
->addChild('user_delete', [ |
|
73
|
|
|
'route' => 'sylius_admin_shop_user_delete', |
|
74
|
|
|
'routeParameters' => ['id' => 4], |
|
75
|
|
|
]) |
|
76
|
|
|
->shouldBeCalled() |
|
77
|
|
|
->willReturn($menu) |
|
78
|
|
|
; |
|
79
|
|
|
$menu->setAttribute('type', 'delete')->shouldBeCalled()->willReturn($menu); |
|
80
|
|
|
$menu->setAttribute('resource_id', 7)->shouldBeCalled()->willReturn($menu); |
|
81
|
|
|
$menu->setLabel('sylius.ui.delete')->shouldBeCalled()->willReturn($menu); |
|
82
|
|
|
|
|
83
|
|
|
$eventDispatcher |
|
84
|
|
|
->dispatch('sylius.menu.admin.customer.show', Argument::type(CustomerShowMenuBuilderEvent::class)) |
|
85
|
|
|
->shouldBeCalled() |
|
86
|
|
|
; |
|
87
|
|
|
|
|
88
|
|
|
$this->createMenu(['customer' => $customer])->shouldReturn($menu); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
function it_creates_a_customer_show_menu_for_customer_without_user( |
|
92
|
|
|
FactoryInterface $factory, |
|
93
|
|
|
EventDispatcherInterface $eventDispatcher, |
|
94
|
|
|
ItemInterface $menu, |
|
95
|
|
|
CustomerInterface $customer |
|
96
|
|
|
): void { |
|
97
|
|
|
$factory->createItem('root')->willReturn($menu); |
|
98
|
|
|
|
|
99
|
|
|
$customer->getId()->willReturn(7); |
|
100
|
|
|
$customer->getUser()->willReturn(null); |
|
101
|
|
|
|
|
102
|
|
|
$menu->setExtra('column_id', 'no-account')->shouldBeCalled()->willReturn($menu); |
|
103
|
|
|
|
|
104
|
|
|
$menu |
|
105
|
|
|
->addChild('order_index', [ |
|
106
|
|
|
'route' => 'sylius_admin_customer_order_index', |
|
107
|
|
|
'routeParameters' => ['id' => 7], |
|
108
|
|
|
]) |
|
109
|
|
|
->shouldBeCalled() |
|
110
|
|
|
->willReturn($menu) |
|
111
|
|
|
; |
|
112
|
|
|
$menu->setAttribute('type', 'show')->shouldBeCalled()->willReturn($menu); |
|
113
|
|
|
$menu->setLabel('sylius.ui.show_orders')->shouldBeCalled()->willReturn($menu); |
|
114
|
|
|
|
|
115
|
|
|
$eventDispatcher |
|
116
|
|
|
->dispatch('sylius.menu.admin.customer.show', Argument::type(CustomerShowMenuBuilderEvent::class)) |
|
117
|
|
|
->shouldBeCalled() |
|
118
|
|
|
; |
|
119
|
|
|
|
|
120
|
|
|
$this->createMenu(['customer' => $customer])->shouldReturn($menu); |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
function it_returns_an_empty_customer_show_menu_when_there_is_no_customer_in_options( |
|
124
|
|
|
FactoryInterface $factory, |
|
125
|
|
|
ItemInterface $menu |
|
126
|
|
|
): void { |
|
127
|
|
|
$factory->createItem('root')->willReturn($menu); |
|
128
|
|
|
|
|
129
|
|
|
$this->createMenu([])->shouldReturn($menu); |
|
130
|
|
|
} |
|
131
|
|
|
} |
|
132
|
|
|
|