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\Configuration; |
13
|
|
|
|
14
|
|
|
use Matthias\SymfonyConfigTest\PhpUnit\ConfigurationTestCaseTrait; |
15
|
|
|
use Sylius\Bundle\ThemeBundle\Configuration\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
|
|
|
'name' |
35
|
|
|
); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @test |
40
|
|
|
*/ |
41
|
|
|
public function its_name_is_required_and_cannot_be_empty() |
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() |
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() |
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() |
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() |
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() |
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() |
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() |
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() |
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() |
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
|
|
|
|