Completed
Push — 1.0-version-dev ( 4a028d )
by Kamil
72:58 queued 44:55
created

ThemeConfigurationTest::it_requires_only_name()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
nc 1
cc 1
eloc 5
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\ThemeBundle\Tests\Configuration;
15
16
use Matthias\SymfonyConfigTest\PhpUnit\ConfigurationTestCaseTrait;
17
use Sylius\Bundle\ThemeBundle\Configuration\ThemeConfiguration;
18
use Symfony\Component\Config\Definition\ConfigurationInterface;
19
20
final class ThemeConfigurationTest extends \PHPUnit_Framework_TestCase
21
{
22
    use ConfigurationTestCaseTrait;
23
24
    /**
25
     * @test
26
     */
27
    public function it_requires_only_name(): void
28
    {
29
        $this->assertProcessedConfigurationEquals(
30
            [
31
                ['name' => 'example/sylius-theme'],
32
            ],
33
            ['name' => 'example/sylius-theme'],
34
            'name'
35
        );
36
    }
37
38
    /**
39
     * @test
40
     */
41
    public function its_name_is_required_and_cannot_be_empty(): void
42
    {
43
        $this->assertPartialConfigurationIsInvalid(
44
            [
45
                [/* no name defined */],
46
            ],
47
            'name'
48
        );
49
50
        $this->assertPartialConfigurationIsInvalid(
51
            [
52
                ['name' => ''],
53
            ],
54
            'name'
55
        );
56
    }
57
58
    /**
59
     * @test
60
     */
61
    public function its_title_is_optional_but_cannot_be_empty(): void
62
    {
63
        $this->assertPartialConfigurationIsInvalid(
64
            [
65
                ['title' => ''],
66
            ],
67
            'title'
68
        );
69
70
        $this->assertConfigurationIsValid(
71
            [
72
                ['title' => 'Lorem ipsum'],
73
            ],
74
            'title'
75
        );
76
    }
77
78
    /**
79
     * @test
80
     */
81
    public function its_description_is_optional_but_cannot_be_empty(): void
82
    {
83
        $this->assertPartialConfigurationIsInvalid(
84
            [
85
                ['description' => ''],
86
            ],
87
            'description'
88
        );
89
90
        $this->assertConfigurationIsValid(
91
            [
92
                ['description' => 'Lorem ipsum dolor sit amet'],
93
            ],
94
            'description'
95
        );
96
    }
97
98
    /**
99
     * @test
100
     */
101
    public function its_path_is_optional_but_cannot_be_empty(): void
102
    {
103
        $this->assertPartialConfigurationIsInvalid(
104
            [
105
                ['path' => ''],
106
            ],
107
            'path'
108
        );
109
110
        $this->assertConfigurationIsValid(
111
            [
112
                ['path' => '/theme/path'],
113
            ],
114
            'path'
115
        );
116
    }
117
118
    /**
119
     * @test
120
     */
121
    public function its_authors_are_optional(): void
122
    {
123
        $this->assertConfigurationIsValid(
124
            [
125
                [/* no authors defined */],
126
            ],
127
            'authors'
128
        );
129
    }
130
131
    /**
132
     * @test
133
     */
134
    public function its_author_can_have_only_name_email_homepage_and_role_properties(): void
135
    {
136
        $this->assertConfigurationIsValid(
137
            [
138
                ['authors' => [['name' => 'Kamil Kokot']]],
139
            ],
140
            'authors'
141
        );
142
143
        $this->assertConfigurationIsValid(
144
            [
145
                ['authors' => [['email' => '[email protected]']]],
146
            ],
147
            'authors'
148
        );
149
150
        $this->assertConfigurationIsValid(
151
            [
152
                ['authors' => [['homepage' => 'http://kamil.kokot.me']]],
153
            ],
154
            'authors'
155
        );
156
157
        $this->assertConfigurationIsValid(
158
            [
159
                ['authors' => [['role' => 'Developer']]],
160
            ],
161
            'authors'
162
        );
163
164
        $this->assertPartialConfigurationIsInvalid(
165
            [
166
                ['authors' => [['undefined' => '42']]],
167
            ],
168
            'authors'
169
        );
170
    }
171
172
    /**
173
     * @test
174
     */
175
    public function its_author_must_have_at_least_one_property(): void
176
    {
177
        $this->assertPartialConfigurationIsInvalid(
178
            [
179
                ['authors' => [[/* empty author */]]],
180
            ],
181
            'authors',
182
            'Author cannot be empty'
183
        );
184
    }
185
186
    /**
187
     * @test
188
     */
189
    public function its_authors_replaces_other_authors_defined_elsewhere(): void
190
    {
191
        $this->assertProcessedConfigurationEquals(
192
            [
193
                ['authors' => [['name' => 'Kamil Kokot']]],
194
                ['authors' => [['name' => 'Krzysztof Krawczyk']]],
195
            ],
196
            ['authors' => [['name' => 'Krzysztof Krawczyk']]],
197
            'authors'
198
        );
199
    }
200
201
    /**
202
     * @test
203
     */
204
    public function it_ignores_undefined_root_level_fields(): void
205
    {
206
        $this->assertConfigurationIsValid(
207
            [
208
                ['name' => 'example/sylius-theme', 'undefined_variable' => '42'],
209
            ]
210
        );
211
    }
212
213
    /**
214
     * @test
215
     */
216
    public function its_parents_are_optional_but_has_to_have_at_least_one_element(): void
217
    {
218
        $this->assertConfigurationIsValid(
219
            [
220
                [],
221
            ],
222
            'parents'
223
        );
224
225
        $this->assertPartialConfigurationIsInvalid(
226
            [
227
                ['parents' => [/* no elements */]],
228
            ],
229
            'parents'
230
        );
231
    }
232
233
    /**
234
     * @test
235
     */
236
    public function its_parent_is_strings(): void
237
    {
238
        $this->assertConfigurationIsValid(
239
            [
240
                ['parents' => ['example/parent-theme', 'example/parent-theme-2']],
241
            ],
242
            'parents'
243
        );
244
    }
245
246
    /**
247
     * @test
248
     */
249
    public function its_parent_cannot_be_empty(): void
250
    {
251
        $this->assertPartialConfigurationIsInvalid(
252
            [
253
                ['parents' => ['']],
254
            ],
255
            'parents'
256
        );
257
    }
258
259
    /**
260
     * @test
261
     */
262
    public function its_parents_replaces_other_parents_defined_elsewhere(): void
263
    {
264
        $this->assertProcessedConfigurationEquals(
265
            [
266
                ['parents' => ['example/first-theme']],
267
                ['parents' => ['example/second-theme']],
268
            ],
269
            ['parents' => ['example/second-theme']],
270
            'parents'
271
        );
272
    }
273
274
    /**
275
     * @test
276
     */
277
    public function its_screenshots_are_strings(): void
278
    {
279
        $this->assertConfigurationIsValid(
280
            [
281
                ['screenshots' => ['screenshot/krzysztof-krawczyk.jpg', 'screenshot/ryszard-rynkowski.jpg']],
282
            ],
283
            'screenshots'
284
        );
285
    }
286
287
    /**
288
     * @test
289
     */
290
    public function its_screenshots_are_optional(): void
291
    {
292
        $this->assertConfigurationIsValid(
293
            [
294
                [/* no screenshots defined */],
295
            ],
296
            'screenshots'
297
        );
298
    }
299
300
    /**
301
     * @test
302
     */
303
    public function its_screenshots_must_have_at_least_one_element(): void
304
    {
305
        $this->assertPartialConfigurationIsInvalid(
306
            [
307
                ['screenshots' => [/* no elements */]],
308
            ],
309
            'screenshots'
310
        );
311
    }
312
313
    /**
314
     * @test
315
     */
316
    public function its_screenshots_cannot_be_empty(): void
317
    {
318
        $this->assertPartialConfigurationIsInvalid(
319
            [
320
                ['screenshots' => ['']],
321
            ],
322
            'screenshots'
323
        );
324
    }
325
326
    /**
327
     * @test
328
     */
329
    public function its_screenshots_replaces_other_screenshots_defined_elsewhere(): void
330
    {
331
        $this->assertProcessedConfigurationEquals(
332
            [
333
                ['screenshots' => ['screenshot/zbigniew-holdys.jpg']],
334
                ['screenshots' => ['screenshot/maryla-rodowicz.jpg']],
335
            ],
336
            ['screenshots' => [['path' => 'screenshot/maryla-rodowicz.jpg']]],
337
            'screenshots'
338
        );
339
    }
340
341
    /**
342
     * @test
343
     */
344
    public function its_screenshots_are_an_array(): void
345
    {
346
        $this->assertConfigurationIsValid(
347
            [
348
                ['screenshots' => [['path' => 'screenshot/rick-astley.jpg']]],
349
            ],
350
            'screenshots'
351
        );
352
    }
353
354
    /**
355
     * @test
356
     */
357
    public function its_screenshots_must_have_a_path(): void
358
    {
359
        $this->assertPartialConfigurationIsInvalid(
360
            [
361
                ['screenshots' => [['title' => 'Candy shop']]],
362
            ],
363
            'screenshots'
364
        );
365
    }
366
367
    /**
368
     * @test
369
     */
370
    public function its_screenshots_have_optional_title_and_description(): void
371
    {
372
        $this->assertConfigurationIsValid(
373
            [
374
                ['screenshots' => [[
375
                    'path' => 'screenshot/rick-astley.jpg',
376
                    'title' => 'Rick Astley',
377
                    'description' => 'He\'ll never gonna give you up or let you down',
378
                ]]],
379
            ],
380
            'screenshots'
381
        );
382
    }
383
384
    /**
385
     * {@inheritdoc}
386
     */
387
    protected function getConfiguration(): ConfigurationInterface
388
    {
389
        return new ThemeConfiguration();
390
    }
391
}
392