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 Sylius\Bundle\UiBundle\Tests\DependencyInjection; |
15
|
|
|
|
16
|
|
|
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractExtensionTestCase; |
17
|
|
|
use Sylius\Bundle\UiBundle\DependencyInjection\SyliusUiExtension; |
18
|
|
|
|
19
|
|
|
final class SyliusUiExtensionTest extends AbstractExtensionTestCase |
20
|
|
|
{ |
21
|
|
|
/** @test */ |
22
|
|
|
public function it_configures_the_multiple_event_block_listener_service_with_events_and_blocks_data(): void |
23
|
|
|
{ |
24
|
|
|
$this->load(['events' => [ |
25
|
|
|
'first_event' => ['blocks' => [ |
26
|
|
|
'first_block' => ['template' => 'first.html.twig', 'enabled' => true, 'priority' => 0], |
27
|
|
|
'second_block' => ['template' => 'second.html.twig', 'enabled' => true, 'priority' => 0], |
28
|
|
|
]], |
29
|
|
|
'second_event' => ['blocks' => [ |
30
|
|
|
'another_block' => ['template' => 'another.html.twig', 'enabled' => true, 'priority' => 0], |
31
|
|
|
]], |
32
|
|
|
]]); |
33
|
|
|
|
34
|
|
|
$this->assertContainerBuilderHasServiceDefinitionWithArgument( |
35
|
|
|
'sylius.ui.sonata_multiple_block_event_listener', |
36
|
|
|
0, |
37
|
|
|
[ |
38
|
|
|
'first_event' => [ |
39
|
|
|
['template' => 'first.html.twig', 'name' => 'first_block'], |
40
|
|
|
['template' => 'second.html.twig', 'name' => 'second_block'], |
41
|
|
|
], |
42
|
|
|
'second_event' => [ |
43
|
|
|
['template' => 'another.html.twig', 'name' => 'another_block'], |
44
|
|
|
], |
45
|
|
|
] |
46
|
|
|
); |
47
|
|
|
|
48
|
|
|
$this->assertContainerBuilderHasServiceDefinitionWithTag( |
49
|
|
|
'sylius.ui.sonata_multiple_block_event_listener', |
50
|
|
|
'kernel.event_listener', |
51
|
|
|
['event' => 'sonata.block.event.first_event', 'method' => '__invoke'] |
52
|
|
|
); |
53
|
|
|
|
54
|
|
|
$this->assertContainerBuilderHasServiceDefinitionWithTag( |
55
|
|
|
'sylius.ui.sonata_multiple_block_event_listener', |
56
|
|
|
'kernel.event_listener', |
57
|
|
|
['event' => 'sonata.block.event.second_event', 'method' => '__invoke'] |
58
|
|
|
); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** @test */ |
62
|
|
|
public function it_does_not_register_disabled_blocks(): void |
63
|
|
|
{ |
64
|
|
|
$this->load(['events' => [ |
65
|
|
|
'event_name' => ['blocks' => [ |
66
|
|
|
'first_block' => ['template' => 'first.html.twig', 'enabled' => false, 'priority' => 0], |
67
|
|
|
'second_block' => ['template' => 'second.html.twig', 'enabled' => true, 'priority' => 0], |
68
|
|
|
]], |
69
|
|
|
]]); |
70
|
|
|
|
71
|
|
|
$this->assertContainerBuilderHasServiceDefinitionWithArgument( |
72
|
|
|
'sylius.ui.sonata_multiple_block_event_listener', |
73
|
|
|
0, |
74
|
|
|
['event_name' => [ |
75
|
|
|
['template' => 'second.html.twig', 'name' => 'second_block'], |
76
|
|
|
]] |
77
|
|
|
); |
78
|
|
|
|
79
|
|
|
$this->assertContainerBuilderHasServiceDefinitionWithTag( |
80
|
|
|
'sylius.ui.sonata_multiple_block_event_listener', |
81
|
|
|
'kernel.event_listener', |
82
|
|
|
['event' => 'sonata.block.event.event_name', 'method' => '__invoke'] |
83
|
|
|
); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** @test */ |
87
|
|
|
public function it_sorts_blocks_by_their_priority(): void |
88
|
|
|
{ |
89
|
|
|
$this->load(['events' => [ |
90
|
|
|
'event_name' => ['blocks' => [ |
91
|
|
|
'third_block' => ['template' => 'third.html.twig', 'enabled' => true, 'priority' => -5], |
92
|
|
|
'fourth_block' => ['template' => 'fourth.html.twig', 'enabled' => true, 'priority' => -10], |
93
|
|
|
'second_block' => ['template' => 'second.html.twig', 'enabled' => true, 'priority' => 0], |
94
|
|
|
'first_block' => ['template' => 'first.html.twig', 'enabled' => true, 'priority' => 5], |
95
|
|
|
]], |
96
|
|
|
]]); |
97
|
|
|
|
98
|
|
|
$this->assertContainerBuilderHasServiceDefinitionWithArgument( |
99
|
|
|
'sylius.ui.sonata_multiple_block_event_listener', |
100
|
|
|
0, |
101
|
|
|
['event_name' => [ |
102
|
|
|
['template' => 'first.html.twig', 'name' => 'first_block'], |
103
|
|
|
['template' => 'second.html.twig', 'name' => 'second_block'], |
104
|
|
|
['template' => 'third.html.twig', 'name' => 'third_block'], |
105
|
|
|
['template' => 'fourth.html.twig', 'name' => 'fourth_block'], |
106
|
|
|
]] |
107
|
|
|
); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** @test */ |
111
|
|
|
public function it_sorts_blocks_by_their_priority_and_uses_fifo_ordering(): void |
112
|
|
|
{ |
113
|
|
|
$this->load(['events' => [ |
114
|
|
|
'event_name' => ['blocks' => [ |
115
|
|
|
'fourth_block' => ['template' => 'fourth.html.twig', 'enabled' => true, 'priority' => -5], |
116
|
|
|
'second_block' => ['template' => 'second.html.twig', 'enabled' => true, 'priority' => 0], |
117
|
|
|
'third_block' => ['template' => 'third.html.twig', 'enabled' => true, 'priority' => 0], |
118
|
|
|
'first_block' => ['template' => 'first.html.twig', 'enabled' => true, 'priority' => 5], |
119
|
|
|
]], |
120
|
|
|
]]); |
121
|
|
|
|
122
|
|
|
$this->assertContainerBuilderHasServiceDefinitionWithArgument( |
123
|
|
|
'sylius.ui.sonata_multiple_block_event_listener', |
124
|
|
|
0, |
125
|
|
|
['event_name' => [ |
126
|
|
|
['template' => 'first.html.twig', 'name' => 'first_block'], |
127
|
|
|
['template' => 'second.html.twig', 'name' => 'second_block'], |
128
|
|
|
['template' => 'third.html.twig', 'name' => 'third_block'], |
129
|
|
|
['template' => 'fourth.html.twig', 'name' => 'fourth_block'], |
130
|
|
|
]] |
131
|
|
|
); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** @test */ |
135
|
|
|
public function it_does_not_register_listener_for_event_that_has_all_blocks_disabled(): void |
136
|
|
|
{ |
137
|
|
|
$this->load(['events' => [ |
138
|
|
|
'event_name' => ['blocks' => [ |
139
|
|
|
'first_block' => ['template' => 'first.html.twig', 'enabled' => false, 'priority' => 0], |
140
|
|
|
'second_block' => ['template' => 'second.html.twig', 'enabled' => false, 'priority' => 0], |
141
|
|
|
]], |
142
|
|
|
]]); |
143
|
|
|
|
144
|
|
|
$this->assertContainerBuilderHasServiceDefinitionWithArgument('sylius.ui.sonata_multiple_block_event_listener', 0, []); |
145
|
|
|
|
146
|
|
|
$listenerDefinition = $this->container->findDefinition('sylius.ui.sonata_multiple_block_event_listener'); |
147
|
|
|
$this->assertEmpty($listenerDefinition->getTags()); |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
protected function getContainerExtensions(): array |
151
|
|
|
{ |
152
|
|
|
return [new SyliusUiExtension()]; |
153
|
|
|
} |
154
|
|
|
} |
155
|
|
|
|