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