Completed
Push — master ( 90ccc1...22512f )
by Kamil
35:43
created

ThemeConfigurationTest::it_requires_only_name()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 9
rs 9.6666
c 1
b 0
f 0
cc 1
eloc 4
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
namespace Sylius\Bundle\ThemeBundle\Tests\Loader;
13
14
use Matthias\SymfonyConfigTest\PhpUnit\ConfigurationTestCaseTrait;
15
use Sylius\Bundle\ThemeBundle\Loader\ThemeConfiguration;
16
17
/**
18
 * @author Kamil Kokot <[email protected]>
19
 */
20
class ThemeConfigurationTest extends \PHPUnit_Framework_TestCase
21
{
22
    use ConfigurationTestCaseTrait;
23
24
    /**
25
     * @test
26
     */
27
    public function it_requires_only_name()
28
    {
29
        $this->assertProcessedConfigurationEquals(
30
            [
31
                ['name' => 'example/sylius-theme'],
32
            ],
33
            ['name' => 'example/sylius-theme']
34
        );
35
    }
36
37
    /**
38
     * @test
39
     */
40
    public function its_name_is_required_and_cannot_be_empty()
41
    {
42
        $this->assertPartialConfigurationIsInvalid(
43
            [
44
                [/* no name defined */],
45
            ],
46
            'name'
47
        );
48
49
        $this->assertPartialConfigurationIsInvalid(
50
            [
51
                ['name' => ''],
52
            ],
53
            'name'
54
        );
55
    }
56
57
    /**
58
     * @test
59
     */
60
    public function its_title_is_optional_but_cannot_be_empty()
61
    {
62
        $this->assertPartialConfigurationIsInvalid(
63
            [
64
                ['title' => ''],
65
            ],
66
            'title'
67
        );
68
69
        $this->assertConfigurationIsValid(
70
            [
71
                ['title' => 'Lorem ipsum'],
72
            ],
73
            'title'
74
        );
75
    }
76
77
    /**
78
     * @test
79
     */
80
    public function its_description_is_optional_but_cannot_be_empty()
81
    {
82
        $this->assertPartialConfigurationIsInvalid(
83
            [
84
                ['description' => ''],
85
            ],
86
            'description'
87
        );
88
89
        $this->assertConfigurationIsValid(
90
            [
91
                ['description' => 'Lorem ipsum dolor sit amet'],
92
            ],
93
            'description'
94
        );
95
    }
96
97
    /**
98
     * @test
99
     */
100
    public function its_path_is_optional_but_cannot_be_empty()
101
    {
102
        $this->assertPartialConfigurationIsInvalid(
103
            [
104
                ['path' => ''],
105
            ],
106
            'path'
107
        );
108
109
        $this->assertConfigurationIsValid(
110
            [
111
                ['path' => '/theme/path'],
112
            ],
113
            'path'
114
        );
115
    }
116
117
    /**
118
     * @test
119
     */
120
    public function its_authors_are_optional()
121
    {
122
        $this->assertConfigurationIsValid(
123
            [
124
                [/* no authors defined */],
125
            ],
126
            'authors'
127
        );
128
    }
129
130
    /**
131
     * @test
132
     */
133
    public function its_author_can_have_only_name_email_homepage_and_role_properties()
134
    {
135
        $this->assertConfigurationIsValid(
136
            [
137
                ['authors' => [['name' => 'Kamil Kokot']]],
138
            ],
139
            'authors'
140
        );
141
142
        $this->assertConfigurationIsValid(
143
            [
144
                ['authors' => [['email' => '[email protected]']]],
145
            ],
146
            'authors'
147
        );
148
149
        $this->assertConfigurationIsValid(
150
            [
151
                ['authors' => [['homepage' => 'http://kamil.kokot.me']]],
152
            ],
153
            'authors'
154
        );
155
156
        $this->assertConfigurationIsValid(
157
            [
158
                ['authors' => [['role' => 'Developer']]],
159
            ],
160
            'authors'
161
        );
162
163
        $this->assertPartialConfigurationIsInvalid(
164
            [
165
                ['authors' => [['undefined' => '42']]],
166
            ],
167
            'authors'
168
        );
169
    }
170
171
    /**
172
     * @test
173
     */
174
    public function its_author_must_have_at_least_one_property()
175
    {
176
        $this->assertPartialConfigurationIsInvalid(
177
            [
178
                ['authors' => [[/* empty author */]]],
179
            ],
180
            'authors',
181
            'Author cannot be empty'
182
        );
183
    }
184
185
    /**
186
     * @test
187
     */
188
    public function its_authors_replaces_other_authors_defined_elsewhere()
189
    {
190
        $this->assertProcessedConfigurationEquals(
191
            [
192
                ['authors' => [['name' => 'Kamil Kokot']]],
193
                ['authors' => [['name' => 'Krzysztof Krawczyk']]],
194
            ],
195
            ['authors' => [['name' => 'Krzysztof Krawczyk']]],
196
            'authors'
197
        );
198
    }
199
200
    /**
201
     * @test
202
     */
203
    public function it_ignores_undefined_root_level_fields()
204
    {
205
        $this->assertProcessedConfigurationEquals(
206
            [
207
                ['name' => 'example/sylius-theme', 'undefined_variable' => '42'],
208
            ],
209
            ['name' => 'example/sylius-theme']
210
        );
211
    }
212
213
    /**
214
     * @test
215
     */
216
    public function its_parents_are_optional_but_has_to_have_at_least_one_element()
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()
237
    {
238
        $this->assertConfigurationIsValid(
239
            [
240
                ['parents' => ['example/parent-theme', 'exampe/parent-theme-2']],
241
            ],
242
            'parents'
243
        );
244
    }
245
246
    /**
247
     * @test
248
     */
249
    public function its_parent_cannot_be_empty()
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()
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
    protected function getConfiguration()
275
    {
276
        return new ThemeConfiguration();
277
    }
278
}
279