Completed
Push — master ( 0f478c...b73fd3 )
by Kamil
14:27 queued 08:29
created

_be_defined()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
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\SymfonyConfigTest\PhpUnit\ConfigurationTestCaseTrait;
17
use PHPUnit\Framework\TestCase;
18
use Sylius\Bundle\UiBundle\DependencyInjection\Configuration;
19
use Symfony\Component\Config\Definition\ConfigurationInterface;
20
21
final class ConfigurationTest extends TestCase
22
{
23
    use ConfigurationTestCaseTrait;
24
25
    /** @test */
26
    public function empty_configuration_triggers_no_errors(): void
27
    {
28
        $this->assertConfigurationIsValid([[]], 'events');
29
        $this->assertConfigurationIsValid([['events' => []]], 'events');
30
    }
31
32
    /** @test */
33
    public function empty_events_configuration_triggers_no_errors(): void
34
    {
35
        $this->assertConfigurationIsValid([['events' => ['event_name' => []]]], 'events');
36
        $this->assertConfigurationIsValid([['events' => ['event_name' => ['blocks' => []]]]], 'events');
37
    }
38
39
    /** @test */
40
    public function multiple_events_might_be_configured(): void
41
    {
42
        $this->assertConfigurationIsValid([['events' => ['first_event' => [], 'second_event' => []]]], 'events');
43
    }
44
45
    /** @test */
46
    public function consecutive_event_configuration_are_merged(): void
47
    {
48
        $this->assertProcessedConfigurationEquals(
49
            [
50
                ['events' => ['first_event' => []]],
51
                ['events' => ['second_event' => []]],
52
            ],
53
            ['events' => ['first_event' => ['blocks' => []], 'second_event' => ['blocks' => []]]],
54
            'events'
55
        );
56
    }
57
58
    /** @test */
59
    public function event_configuration_has_block_configuration(): void
60
    {
61
        $this->assertConfigurationIsValid(
62
            [['events' => ['event_name' => ['blocks' => ['block_name' => ['template' => 'block.html.twig']]]]]],
63
            'events'
64
        );
65
    }
66
67
    /** @test */
68
    public function multiple_blocks_can_be_configured_for_an_event(): void
69
    {
70
        $this->assertConfigurationIsValid(
71
            [['events' => ['event_name' => ['blocks' => [
72
                'first_block' => ['template' => 'block.html.twig'],
73
                'second_block' => ['template' => 'block.html.twig'],
74
            ]]]]],
75
            'events'
76
        );
77
    }
78
79
    /** @test */
80
    public function block_has_default_priority_set_to_zero(): void
81
    {
82
        $this->assertProcessedConfigurationEquals(
83
            [['events' => ['event_name' => ['blocks' => ['block_name' => []]]]]],
84
            ['events' => ['event_name' => ['blocks' => ['block_name' => ['priority' => 0]]]]],
85
            'events.*.blocks.*.priority'
86
        );
87
    }
88
89
    /** @test */
90
    public function block_priority_is_set_within_its_configuration(): void
91
    {
92
        $this->assertProcessedConfigurationEquals(
93
            [['events' => ['event_name' => ['blocks' => ['block_name' => ['priority' => 100]]]]]],
94
            ['events' => ['event_name' => ['blocks' => ['block_name' => ['priority' => 100]]]]],
95
            'events.*.blocks.*.priority'
96
        );
97
    }
98
99
    /** @test */
100
    public function block_is_null_by_default(): void
101
    {
102
        $this->assertProcessedConfigurationEquals(
103
            [['events' => ['event_name' => ['blocks' => ['block_name' => []]]]]],
104
            ['events' => ['event_name' => ['blocks' => ['block_name' => ['enabled' => null]]]]],
105
            'events.*.blocks.*.enabled'
106
        );
107
    }
108
109
    /** @test */
110
    public function block_can_be_disabled_within_its_configuration(): void
111
    {
112
        $this->assertProcessedConfigurationEquals(
113
            [['events' => ['event_name' => ['blocks' => ['block_name' => ['enabled' => false]]]]]],
114
            ['events' => ['event_name' => ['blocks' => ['block_name' => ['enabled' => false]]]]],
115
            'events.*.blocks.*.enabled'
116
        );
117
    }
118
119
    /** @test */
120
    public function block_configuration_can_be_shortened_to_template_string_only(): void
121
    {
122
        $this->assertProcessedConfigurationEquals(
123
            [['events' => ['event_name' => ['blocks' => ['block_name' => 'template.html.twig']]]]],
124
            ['events' => ['event_name' => ['blocks' => ['block_name' => ['template' => 'template.html.twig']]]]],
125
            'events.*.blocks.*.template'
126
        );
127
    }
128
129
    /** @test */
130
    public function consecutive_block_configurations_can_change_the_template(): void
131
    {
132
        $this->assertProcessedConfigurationEquals(
133
            [
134
                ['events' => ['event_name' => ['blocks' => ['block_name' => 'template.html.twig']]]],
135
                ['events' => ['event_name' => ['blocks' => ['block_name' => ['template' => 'another_template.html.twig']]]]],
136
            ],
137
            ['events' => ['event_name' => ['blocks' => ['block_name' => ['template' => 'another_template.html.twig']]]]],
138
            'events.*.blocks.*.template'
139
        );
140
    }
141
142
    /** @test */
143
    public function consecutive_block_configurations_can_change_the_priority(): void
144
    {
145
        $this->assertProcessedConfigurationEquals(
146
            [
147
                ['events' => ['event_name' => ['blocks' => ['block_name' => ['priority' => 42]]]]],
148
                ['events' => ['event_name' => ['blocks' => ['block_name' => ['priority' => 13]]]]],
149
            ],
150
            ['events' => ['event_name' => ['blocks' => ['block_name' => ['priority' => 13]]]]],
151
            'events.*.blocks.*.priority'
152
        );
153
    }
154
155
    /** @test */
156
    public function consecutive_block_configurations_can_disable_it(): void
157
    {
158
        $this->assertProcessedConfigurationEquals(
159
            [
160
                ['events' => ['event_name' => ['blocks' => ['block_name' => ['enabled' => true]]]]],
161
                ['events' => ['event_name' => ['blocks' => ['block_name' => ['enabled' => false]]]]],
162
            ],
163
            ['events' => ['event_name' => ['blocks' => ['block_name' => ['enabled' => false]]]]],
164
            'events.*.blocks.*.enabled'
165
        );
166
    }
167
168
    /** @test */
169
    public function consecutive_block_configurations_are_merged(): void
170
    {
171
        $this->assertProcessedConfigurationEquals(
172
            [
173
                ['events' => ['event_name' => ['blocks' => ['first_block' => 'first.html.twig']]]],
174
                ['events' => ['event_name' => ['blocks' => ['second_block' => 'second.html.twig']]]],
175
            ],
176
            ['events' => ['event_name' => ['blocks' => [
177
                'first_block' => ['template' => 'first.html.twig'],
178
                'second_block' => ['template' => 'second.html.twig'],
179
            ]]]],
180
            'events.*.blocks.*.template'
181
        );
182
    }
183
184
    /** @test */
185
    public function context_can_be_passed_to_the_block(): void
186
    {
187
        $this->assertProcessedConfigurationEquals(
188
            [['events' => ['event_name' => ['blocks' => ['block_name' => ['context' => ['foo' => 'bar']]]]]]],
189
            ['events' => ['event_name' => ['blocks' => ['block_name' => ['context' => ['foo' => 'bar']]]]]],
190
            'events.*.blocks.*.context'
191
        );
192
    }
193
194
    /** @test */
195
    public function consecutive_block_context_configuration_is_shallowly_merged(): void
196
    {
197
        $this->assertProcessedConfigurationEquals(
198
            [
199
                ['events' => ['event_name' => ['blocks' => ['block_name' => ['context' => ['foo' => 'bar']]]]]],
200
                ['events' => ['event_name' => ['blocks' => ['block_name' => ['context' => ['bar' => 'baz']]]]]],
201
            ],
202
            ['events' => ['event_name' => ['blocks' => ['block_name' => ['context' => ['foo' => 'bar', 'bar' => 'baz']]]]]],
203
            'events.*.blocks.*.context'
204
        );
205
206
        $this->assertProcessedConfigurationEquals(
207
            [
208
                ['events' => ['event_name' => ['blocks' => ['block_name' => ['context' => ['foo' => ['bar']]]]]]],
209
                ['events' => ['event_name' => ['blocks' => ['block_name' => ['context' => ['foo' => ['baz']]]]]]],
210
            ],
211
            ['events' => ['event_name' => ['blocks' => ['block_name' => ['context' => ['foo' => ['baz']]]]]]],
212
            'events.*.blocks.*.context'
213
        );
214
    }
215
216
    protected function getConfiguration(): ConfigurationInterface
217
    {
218
        return new Configuration();
219
    }
220
}
221