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