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 spec\Sylius\Component\Core\Model; |
13
|
|
|
|
14
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
15
|
|
|
use Doctrine\Common\Collections\Collection; |
16
|
|
|
use PhpSpec\ObjectBehavior; |
17
|
|
|
use Sylius\Component\Core\Model\Product; |
18
|
|
|
use Sylius\Component\Core\Model\ProductImagesAwareInterface; |
19
|
|
|
use Sylius\Component\Core\Model\ProductImageInterface; |
20
|
|
|
use Sylius\Component\Core\Model\ChannelInterface; |
21
|
|
|
use Sylius\Component\Core\Model\ChannelPricingInterface; |
22
|
|
|
use Sylius\Component\Core\Model\ProductVariant; |
23
|
|
|
use Sylius\Component\Core\Model\ProductVariantInterface; |
24
|
|
|
use Sylius\Component\Product\Model\ProductVariant as BaseProductVariant; |
25
|
|
|
use Sylius\Component\Resource\Model\VersionedInterface; |
26
|
|
|
use Sylius\Component\Shipping\Model\ShippableInterface; |
27
|
|
|
use Sylius\Component\Shipping\Model\ShippingCategoryInterface; |
28
|
|
|
use Sylius\Component\Taxation\Model\TaxableInterface; |
29
|
|
|
use Sylius\Component\Taxation\Model\TaxCategoryInterface; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @author Paweł Jędrzejewski <[email protected]> |
33
|
|
|
*/ |
34
|
|
|
final class ProductVariantSpec extends ObjectBehavior |
35
|
|
|
{ |
36
|
|
|
function it_is_initializable() |
37
|
|
|
{ |
38
|
|
|
$this->shouldHaveType(ProductVariant::class); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
function it_implements_a_product_variant_interface() |
42
|
|
|
{ |
43
|
|
|
$this->shouldImplement(ProductVariantInterface::class); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
function it_implements_a_taxable_interface() |
47
|
|
|
{ |
48
|
|
|
$this->shouldImplement(TaxableInterface::class); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
function it_extends_a_product_variant_model() |
52
|
|
|
{ |
53
|
|
|
$this->shouldHaveType(BaseProductVariant::class); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
function it_implements_a_shippable_interface() |
57
|
|
|
{ |
58
|
|
|
$this->shouldImplement(ShippableInterface::class); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
function it_implements_versioned_interface() |
62
|
|
|
{ |
63
|
|
|
$this->shouldImplement(VersionedInterface::class); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
function it_implements_a_product_image_aware_interface() |
67
|
|
|
{ |
68
|
|
|
$this->shouldImplement(ProductImagesAwareInterface::class); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
function it_has_version_1_by_default() |
72
|
|
|
{ |
73
|
|
|
$this->getVersion()->shouldReturn(1); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
function it_has_no_weight_by_default() |
77
|
|
|
{ |
78
|
|
|
$this->getWeight()->shouldReturn(null); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
function its_weight_is_mutable() |
82
|
|
|
{ |
83
|
|
|
$this->setWeight(120); |
84
|
|
|
$this->getWeight()->shouldReturn(120); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
function it_has_no_width_by_default() |
88
|
|
|
{ |
89
|
|
|
$this->getWidth()->shouldReturn(null); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
function its_width_is_mutable() |
93
|
|
|
{ |
94
|
|
|
$this->setWidth(15); |
95
|
|
|
$this->getWidth()->shouldReturn(15); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
function it_has_no_height_by_default() |
99
|
|
|
{ |
100
|
|
|
$this->getHeight()->shouldReturn(null); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
function its_height_is_mutable() |
104
|
|
|
{ |
105
|
|
|
$this->setHeight(40); |
106
|
|
|
$this->getHeight()->shouldReturn(40); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
function it_returns_correct_shipping_weight() |
110
|
|
|
{ |
111
|
|
|
$this->setWeight(140); |
112
|
|
|
$this->getShippingWeight()->shouldReturn(140); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
function it_returns_correct_shipping_volume() |
116
|
|
|
{ |
117
|
|
|
$this->setWidth(10); |
118
|
|
|
$this->setHeight(20); |
119
|
|
|
$this->setDepth(10); |
120
|
|
|
$this->getShippingVolume()->shouldReturn(2000); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
function it_returns_correct_shipping_width() |
124
|
|
|
{ |
125
|
|
|
$this->setWidth(100); |
126
|
|
|
$this->getShippingWidth()->shouldReturn(100); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
function it_returns_correct_shipping_height() |
130
|
|
|
{ |
131
|
|
|
$this->setHeight(110); |
132
|
|
|
$this->getShippingHeight()->shouldReturn(110); |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
function it_has_no_code_by_default() |
136
|
|
|
{ |
137
|
|
|
$this->getCode()->shouldReturn(null); |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
function its_code_is_mutable() |
141
|
|
|
{ |
142
|
|
|
$this->setCode('dummy-sku123'); |
143
|
|
|
$this->getCode()->shouldReturn('dummy-sku123'); |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
function it_does_not_have_tax_category_by_default() |
147
|
|
|
{ |
148
|
|
|
$this->getTaxCategory()->shouldReturn(null); |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
function it_allows_setting_the_tax_category(TaxCategoryInterface $taxCategory) |
152
|
|
|
{ |
153
|
|
|
$this->setTaxCategory($taxCategory); |
154
|
|
|
$this->getTaxCategory()->shouldReturn($taxCategory); |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
function it_allows_resetting_the_tax_category(TaxCategoryInterface $taxCategory) |
158
|
|
|
{ |
159
|
|
|
$this->setTaxCategory($taxCategory); |
160
|
|
|
$this->getTaxCategory()->shouldReturn($taxCategory); |
161
|
|
|
|
162
|
|
|
$this->setTaxCategory(null); |
163
|
|
|
$this->getTaxCategory()->shouldReturn(null); |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
function it_has_no_shipping_category_by_default() |
167
|
|
|
{ |
168
|
|
|
$this->getShippingCategory()->shouldReturn(null); |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
function its_shipping_category_is_mutable(ShippingCategoryInterface $shippingCategory) |
172
|
|
|
{ |
173
|
|
|
$this->setShippingCategory($shippingCategory); |
174
|
|
|
$this->getShippingCategory()->shouldReturn($shippingCategory); |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
function it_adds_and_removes_channel_pricings(ChannelPricingInterface $channelPricing) |
178
|
|
|
{ |
179
|
|
|
$channelPricing->getChannelCode()->willReturn('WEB'); |
180
|
|
|
|
181
|
|
|
$channelPricing->setProductVariant($this)->shouldBeCalled(); |
182
|
|
|
$this->addChannelPricing($channelPricing); |
183
|
|
|
$this->hasChannelPricing($channelPricing)->shouldReturn(true); |
184
|
|
|
|
185
|
|
|
$channelPricing->setProductVariant(null)->shouldBeCalled(); |
186
|
|
|
$this->removeChannelPricing($channelPricing); |
187
|
|
|
$this->hasChannelPricing($channelPricing)->shouldReturn(false); |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
function it_has_channel_pricings_collection( |
191
|
|
|
ChannelPricingInterface $firstChannelPricing, |
192
|
|
|
ChannelPricingInterface $secondChannelPricing |
193
|
|
|
) { |
194
|
|
|
$firstChannelPricing->getChannelCode()->willReturn('WEB'); |
195
|
|
|
$secondChannelPricing->getChannelCode()->willReturn('MOB'); |
196
|
|
|
|
197
|
|
|
$firstChannelPricing->setProductVariant($this)->shouldBeCalled(); |
198
|
|
|
$secondChannelPricing->setProductVariant($this)->shouldBeCalled(); |
199
|
|
|
|
200
|
|
|
$this->addChannelPricing($firstChannelPricing); |
201
|
|
|
$this->addChannelPricing($secondChannelPricing); |
202
|
|
|
|
203
|
|
|
$this->getChannelPricings()->shouldBeLike(new ArrayCollection([ |
204
|
|
|
'WEB' => $firstChannelPricing->getWrappedObject(), |
205
|
|
|
'MOB' => $secondChannelPricing->getWrappedObject(), |
206
|
|
|
])); |
207
|
|
|
} |
208
|
|
|
|
209
|
|
|
function it_checks_if_contains_channel_pricing_for_given_channel( |
210
|
|
|
ChannelInterface $firstChannel, |
211
|
|
|
ChannelInterface $secondChannel, |
212
|
|
|
ChannelPricingInterface $firstChannelPricing |
213
|
|
|
) { |
214
|
|
|
$firstChannelPricing->getChannelCode()->willReturn('WEB'); |
215
|
|
|
$firstChannel->getCode()->willReturn('WEB'); |
216
|
|
|
$secondChannel->getCode()->willReturn('MOB'); |
217
|
|
|
|
218
|
|
|
$firstChannelPricing->setProductVariant($this)->shouldBeCalled(); |
219
|
|
|
$this->addChannelPricing($firstChannelPricing); |
220
|
|
|
|
221
|
|
|
$firstChannelPricing->getChannelCode()->willReturn($firstChannel); |
222
|
|
|
|
223
|
|
|
$this->hasChannelPricingForChannel($firstChannel)->shouldReturn(true); |
224
|
|
|
$this->hasChannelPricingForChannel($secondChannel)->shouldReturn(false); |
225
|
|
|
} |
226
|
|
|
|
227
|
|
|
function it_returns_channel_pricing_for_given_channel( |
228
|
|
|
ChannelInterface $channel, |
229
|
|
|
ChannelPricingInterface $channelPricing |
230
|
|
|
) { |
231
|
|
|
$channelPricing->getChannelCode()->willReturn('WEB'); |
232
|
|
|
$channel->getCode()->willReturn('WEB'); |
233
|
|
|
|
234
|
|
|
$channelPricing->setProductVariant($this)->shouldBeCalled(); |
235
|
|
|
$this->addChannelPricing($channelPricing); |
236
|
|
|
|
237
|
|
|
$channelPricing->getChannelCode()->willReturn($channel); |
238
|
|
|
|
239
|
|
|
$this->getChannelPricingForChannel($channel)->shouldReturn($channelPricing); |
240
|
|
|
} |
241
|
|
|
|
242
|
|
|
function it_requires_shipping_by_default() |
243
|
|
|
{ |
244
|
|
|
$this->isShippingRequired()->shouldReturn(true); |
245
|
|
|
} |
246
|
|
|
|
247
|
|
|
function its_shipping_can_be_not_required() |
248
|
|
|
{ |
249
|
|
|
$this->setShippingRequired(false); |
250
|
|
|
$this->isShippingRequired()->shouldReturn(false); |
251
|
|
|
} |
252
|
|
|
|
253
|
|
|
function it_initializes_image_collection_by_default() |
254
|
|
|
{ |
255
|
|
|
$this->getImages()->shouldHaveType(Collection::class); |
256
|
|
|
} |
257
|
|
|
|
258
|
|
|
function it_adds_an_image(ProductImageInterface $image) |
259
|
|
|
{ |
260
|
|
|
$this->addImage($image); |
261
|
|
|
$this->hasImages()->shouldReturn(true); |
262
|
|
|
$this->hasImage($image)->shouldReturn(true); |
263
|
|
|
} |
264
|
|
|
|
265
|
|
|
function it_removes_an_image(ProductImageInterface $image) |
266
|
|
|
{ |
267
|
|
|
$this->addImage($image); |
268
|
|
|
$this->removeImage($image); |
269
|
|
|
$this->hasImage($image)->shouldReturn(false); |
270
|
|
|
} |
271
|
|
|
|
272
|
|
|
function it_returns_images_by_type(ProductImageInterface $image, Product $product) |
273
|
|
|
{ |
274
|
|
|
$image->getType()->willReturn('thumbnail'); |
275
|
|
|
|
276
|
|
|
$image->setOwner($product)->shouldBeCalled(); |
277
|
|
|
$image->addProductVariant($this)->shouldBeCalled(); |
278
|
|
|
|
279
|
|
|
$this->setProduct($product); |
280
|
|
|
$this->addImage($image); |
281
|
|
|
$this->getImagesByType('thumbnail')->shouldBeLike(new ArrayCollection([$image->getWrappedObject()])); |
282
|
|
|
} |
283
|
|
|
} |
284
|
|
|
|