|
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\Collection; |
|
15
|
|
|
use PhpSpec\ObjectBehavior; |
|
16
|
|
|
use Sylius\Component\Channel\Model\ChannelInterface; |
|
17
|
|
|
use Sylius\Component\Core\Model\AddressInterface; |
|
18
|
|
|
use Sylius\Component\Core\Model\AdjustmentInterface; |
|
19
|
|
|
use Sylius\Component\Core\Model\OrderItemInterface; |
|
20
|
|
|
use Sylius\Component\Core\Model\OrderShippingStates; |
|
21
|
|
|
use Sylius\Component\Core\Model\PaymentInterface; |
|
22
|
|
|
use Sylius\Component\Core\Model\PromotionInterface; |
|
23
|
|
|
use Sylius\Component\Core\Model\ShipmentInterface; |
|
24
|
|
|
use Sylius\Component\Core\OrderCheckoutStates; |
|
25
|
|
|
use Sylius\Component\Inventory\Model\InventoryUnitInterface; |
|
26
|
|
|
use Sylius\Component\Order\Model\Order; |
|
27
|
|
|
use Sylius\Component\Order\Model\OrderInterface; |
|
28
|
|
|
use Sylius\Component\Promotion\Model\CouponInterface; |
|
29
|
|
|
use Sylius\Component\User\Model\CustomerInterface; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @author Paweł Jędrzejewski <[email protected]> |
|
33
|
|
|
*/ |
|
34
|
|
|
class OrderSpec extends ObjectBehavior |
|
35
|
|
|
{ |
|
36
|
|
|
function it_is_initializable() |
|
37
|
|
|
{ |
|
38
|
|
|
$this->shouldHaveType('Sylius\Component\Core\Model\Order'); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
function it_should_implement_Sylius_order_interface() |
|
42
|
|
|
{ |
|
43
|
|
|
$this->shouldImplement(OrderInterface::class); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
function it_should_extend_Sylius_order_mapped_superclass() |
|
47
|
|
|
{ |
|
48
|
|
|
$this->shouldHaveType(Order::class); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
function it_should_not_have_customer_defined_by_default() |
|
52
|
|
|
{ |
|
53
|
|
|
$this->getCustomer()->shouldReturn(null); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
function it_should_allow_defining_customer(CustomerInterface $customer) |
|
57
|
|
|
{ |
|
58
|
|
|
$this->setCustomer($customer); |
|
59
|
|
|
$this->getCustomer()->shouldReturn($customer); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
function its_channel_is_mutable(ChannelInterface $channel) |
|
63
|
|
|
{ |
|
64
|
|
|
$this->setChannel($channel); |
|
65
|
|
|
$this->getChannel()->shouldReturn($channel); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
function it_should_not_have_shipping_address_by_default() |
|
69
|
|
|
{ |
|
70
|
|
|
$this->getShippingAddress()->shouldReturn(null); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
function it_should_allow_defining_shipping_address(AddressInterface $address) |
|
74
|
|
|
{ |
|
75
|
|
|
$this->setShippingAddress($address); |
|
76
|
|
|
$this->getShippingAddress()->shouldReturn($address); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
function it_should_not_have_billing_address_by_default() |
|
80
|
|
|
{ |
|
81
|
|
|
$this->getBillingAddress()->shouldReturn(null); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
function it_should_allow_defining_billing_address(AddressInterface $address) |
|
85
|
|
|
{ |
|
86
|
|
|
$this->setBillingAddress($address); |
|
87
|
|
|
$this->getBillingAddress()->shouldReturn($address); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
function its_checkout_state_is_mutable() |
|
91
|
|
|
{ |
|
92
|
|
|
$this->setCheckoutState(OrderCheckoutStates::STATE_CART); |
|
93
|
|
|
$this->getCheckoutState()->shouldReturn(OrderCheckoutStates::STATE_CART); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
function its_payment_state_is_mutable() |
|
97
|
|
|
{ |
|
98
|
|
|
$this->setPaymentState(PaymentInterface::STATE_COMPLETED); |
|
99
|
|
|
$this->getPaymentState()->shouldReturn(PaymentInterface::STATE_COMPLETED); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
function it_should_initialize_item_units_collection_by_default() |
|
103
|
|
|
{ |
|
104
|
|
|
$this->getItemUnits()->shouldHaveType(Collection::class); |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
function it_should_initialize_shipments_collection_by_default() |
|
108
|
|
|
{ |
|
109
|
|
|
$this->getShipments()->shouldHaveType(Collection::class); |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
function it_should_add_shipment_properly(ShipmentInterface $shipment) |
|
113
|
|
|
{ |
|
114
|
|
|
$this->shouldNotHaveShipment($shipment); |
|
115
|
|
|
|
|
116
|
|
|
$shipment->setOrder($this)->shouldBeCalled(); |
|
117
|
|
|
$this->addShipment($shipment); |
|
118
|
|
|
|
|
119
|
|
|
$this->shouldHaveShipment($shipment); |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
function it_should_remove_shipment_properly(ShipmentInterface $shipment) |
|
123
|
|
|
{ |
|
124
|
|
|
$shipment->setOrder($this)->shouldBeCalled(); |
|
125
|
|
|
$this->addShipment($shipment); |
|
126
|
|
|
|
|
127
|
|
|
$this->shouldHaveShipment($shipment); |
|
128
|
|
|
|
|
129
|
|
|
$shipment->setOrder(null)->shouldBeCalled(); |
|
130
|
|
|
$this->removeShipment($shipment); |
|
131
|
|
|
|
|
132
|
|
|
$this->shouldNotHaveShipment($shipment); |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
function it_should_return_shipping_adjustments( |
|
136
|
|
|
AdjustmentInterface $shippingAdjustment, |
|
137
|
|
|
AdjustmentInterface $taxAdjustment |
|
138
|
|
|
) { |
|
139
|
|
|
$shippingAdjustment->getType()->willReturn(AdjustmentInterface::SHIPPING_ADJUSTMENT); |
|
140
|
|
|
$shippingAdjustment->setAdjustable($this)->shouldBeCalled(); |
|
141
|
|
|
$shippingAdjustment->isNeutral()->willReturn(true); |
|
142
|
|
|
|
|
143
|
|
|
$taxAdjustment->getType()->willReturn(AdjustmentInterface::TAX_ADJUSTMENT); |
|
144
|
|
|
$taxAdjustment->setAdjustable($this)->shouldBeCalled(); |
|
145
|
|
|
$taxAdjustment->isNeutral()->willReturn(true); |
|
146
|
|
|
|
|
147
|
|
|
$this->addAdjustment($shippingAdjustment); |
|
148
|
|
|
$this->addAdjustment($taxAdjustment); |
|
149
|
|
|
|
|
150
|
|
|
$this->getAdjustments()->count()->shouldReturn(2); //both adjustments have been added |
|
151
|
|
|
|
|
152
|
|
|
$shippingAdjustments = $this->getAdjustments(AdjustmentInterface::SHIPPING_ADJUSTMENT); |
|
153
|
|
|
$shippingAdjustments->count()->shouldReturn(1); //but here we only get shipping |
|
154
|
|
|
$shippingAdjustments->first()->shouldReturn($shippingAdjustment); |
|
155
|
|
|
} |
|
156
|
|
|
|
|
157
|
|
|
function it_should_remove_shipping_adjustments( |
|
158
|
|
|
AdjustmentInterface $shippingAdjustment, |
|
159
|
|
|
AdjustmentInterface $taxAdjustment |
|
160
|
|
|
) { |
|
161
|
|
|
$shippingAdjustment->getType()->willReturn(AdjustmentInterface::SHIPPING_ADJUSTMENT); |
|
162
|
|
|
$shippingAdjustment->setAdjustable($this)->shouldBeCalled(); |
|
163
|
|
|
$shippingAdjustment->isNeutral()->willReturn(true); |
|
164
|
|
|
|
|
165
|
|
|
$taxAdjustment->getType()->willReturn(AdjustmentInterface::TAX_ADJUSTMENT); |
|
166
|
|
|
$taxAdjustment->setAdjustable($this)->shouldBeCalled(); |
|
167
|
|
|
$taxAdjustment->isNeutral()->willReturn(true); |
|
168
|
|
|
|
|
169
|
|
|
$this->addAdjustment($shippingAdjustment); |
|
170
|
|
|
$this->addAdjustment($taxAdjustment); |
|
171
|
|
|
|
|
172
|
|
|
$this->getAdjustments()->count()->shouldReturn(2); //both adjustments have been added |
|
173
|
|
|
|
|
174
|
|
|
$shippingAdjustment->isLocked()->willReturn(false); |
|
175
|
|
|
$shippingAdjustment->setAdjustable(null)->shouldBeCalled(); |
|
176
|
|
|
$this->removeAdjustments(AdjustmentInterface::SHIPPING_ADJUSTMENT); |
|
177
|
|
|
|
|
178
|
|
|
$this->getAdjustments()->count()->shouldReturn(1); //one has been removed |
|
179
|
|
|
$this->getAdjustments(AdjustmentInterface::SHIPPING_ADJUSTMENT)->count()->shouldReturn(0); //shipping adjustment has been removed |
|
180
|
|
|
} |
|
181
|
|
|
|
|
182
|
|
|
function it_should_return_tax_adjustments( |
|
183
|
|
|
AdjustmentInterface $shippingAdjustment, |
|
184
|
|
|
AdjustmentInterface $taxAdjustment |
|
185
|
|
|
) { |
|
186
|
|
|
$shippingAdjustment->getType()->willReturn(AdjustmentInterface::SHIPPING_ADJUSTMENT); |
|
187
|
|
|
$shippingAdjustment->setAdjustable($this)->shouldBeCalled(); |
|
188
|
|
|
$shippingAdjustment->isNeutral()->willReturn(true); |
|
189
|
|
|
|
|
190
|
|
|
$taxAdjustment->getType()->willReturn(AdjustmentInterface::TAX_ADJUSTMENT); |
|
191
|
|
|
$taxAdjustment->setAdjustable($this)->shouldBeCalled(); |
|
192
|
|
|
$taxAdjustment->isNeutral()->willReturn(true); |
|
193
|
|
|
|
|
194
|
|
|
$this->addAdjustment($shippingAdjustment); |
|
195
|
|
|
$this->addAdjustment($taxAdjustment); |
|
196
|
|
|
|
|
197
|
|
|
$this->getAdjustments()->count()->shouldReturn(2); //both adjustments have been added |
|
198
|
|
|
|
|
199
|
|
|
$taxAdjustments = $this->getAdjustments(AdjustmentInterface::TAX_ADJUSTMENT); |
|
200
|
|
|
$taxAdjustments->count()->shouldReturn(1); //but here we only get tax |
|
201
|
|
|
$taxAdjustments->first()->shouldReturn($taxAdjustment); |
|
202
|
|
|
} |
|
203
|
|
|
|
|
204
|
|
|
function it_should_remove_tax_adjustments( |
|
205
|
|
|
AdjustmentInterface $shippingAdjustment, |
|
206
|
|
|
AdjustmentInterface $taxAdjustment |
|
207
|
|
|
) { |
|
208
|
|
|
$shippingAdjustment->getType()->willReturn(AdjustmentInterface::SHIPPING_ADJUSTMENT); |
|
209
|
|
|
$shippingAdjustment->setAdjustable($this)->shouldBeCalled(); |
|
210
|
|
|
$shippingAdjustment->isNeutral()->willReturn(true); |
|
211
|
|
|
|
|
212
|
|
|
$taxAdjustment->getType()->willReturn(AdjustmentInterface::TAX_ADJUSTMENT); |
|
213
|
|
|
$taxAdjustment->setAdjustable($this)->shouldBeCalled(); |
|
214
|
|
|
$taxAdjustment->isNeutral()->willReturn(true); |
|
215
|
|
|
|
|
216
|
|
|
$this->addAdjustment($shippingAdjustment); |
|
217
|
|
|
$this->addAdjustment($taxAdjustment); |
|
218
|
|
|
|
|
219
|
|
|
$this->getAdjustments()->count()->shouldReturn(2); //both adjustments have been added |
|
220
|
|
|
|
|
221
|
|
|
$taxAdjustment->isLocked()->willReturn(false); |
|
222
|
|
|
$taxAdjustment->setAdjustable(null)->shouldBeCalled(); |
|
223
|
|
|
$this->removeAdjustments(AdjustmentInterface::TAX_ADJUSTMENT); |
|
224
|
|
|
|
|
225
|
|
|
$this->getAdjustments()->count()->shouldReturn(1); //one has been removed |
|
226
|
|
|
$this->getAdjustments(AdjustmentInterface::TAX_ADJUSTMENT)->count()->shouldReturn(0); //tax adjustment has been removed |
|
227
|
|
|
} |
|
228
|
|
|
|
|
229
|
|
|
function it_should_not_have_currency_defined_by_default() |
|
230
|
|
|
{ |
|
231
|
|
|
$this->getCurrency()->shouldReturn(null); |
|
232
|
|
|
} |
|
233
|
|
|
|
|
234
|
|
|
function it_should_allow_defining_currency() |
|
235
|
|
|
{ |
|
236
|
|
|
$this->setCurrency('PLN'); |
|
237
|
|
|
$this->getCurrency()->shouldReturn('PLN'); |
|
238
|
|
|
} |
|
239
|
|
|
|
|
240
|
|
|
function it_has_default_exchange_rate_equal_to_1() |
|
241
|
|
|
{ |
|
242
|
|
|
$this->getExchangeRate()->shouldReturn(1.0); |
|
243
|
|
|
} |
|
244
|
|
|
|
|
245
|
|
|
function its_exchange_rate_is_mutable() |
|
246
|
|
|
{ |
|
247
|
|
|
$this->setExchangeRate(1.25); |
|
248
|
|
|
$this->getExchangeRate()->shouldReturn(1.25); |
|
249
|
|
|
} |
|
250
|
|
|
|
|
251
|
|
|
function it_has_checkout_shipping_state_by_default() |
|
252
|
|
|
{ |
|
253
|
|
|
$this->getShippingState()->shouldReturn(OrderShippingStates::CHECKOUT); |
|
254
|
|
|
} |
|
255
|
|
|
|
|
256
|
|
|
function its_shipping_state_is_mutable() |
|
257
|
|
|
{ |
|
258
|
|
|
$this->setShippingState(OrderShippingStates::SHIPPED); |
|
259
|
|
|
$this->getShippingState()->shouldReturn(OrderShippingStates::SHIPPED); |
|
260
|
|
|
} |
|
261
|
|
|
|
|
262
|
|
|
function it_is_a_backorder_if_contains_at_least_one_backordered_unit( |
|
263
|
|
|
InventoryUnitInterface $unit1, |
|
264
|
|
|
InventoryUnitInterface $unit2, |
|
265
|
|
|
OrderItemInterface $item |
|
266
|
|
|
) { |
|
267
|
|
|
$unit1->getInventoryState()->willReturn(InventoryUnitInterface::STATE_BACKORDERED); |
|
268
|
|
|
$unit2->getInventoryState()->willReturn(InventoryUnitInterface::STATE_SOLD); |
|
269
|
|
|
|
|
270
|
|
|
$item->getUnits()->willReturn([$unit1, $unit2]); |
|
271
|
|
|
$item->getTotal()->willReturn(4000); |
|
272
|
|
|
|
|
273
|
|
|
$item->setOrder($this)->shouldBeCalled(); |
|
274
|
|
|
$this->addItem($item); |
|
275
|
|
|
|
|
276
|
|
|
$this->shouldBeBackorder(); |
|
277
|
|
|
} |
|
278
|
|
|
|
|
279
|
|
|
function it_not_a_backorder_if_contains_no_backordered_units( |
|
280
|
|
|
InventoryUnitInterface $unit1, |
|
281
|
|
|
InventoryUnitInterface $unit2, |
|
282
|
|
|
OrderItemInterface $item |
|
283
|
|
|
) { |
|
284
|
|
|
$unit1->getInventoryState()->willReturn(InventoryUnitInterface::STATE_SOLD); |
|
285
|
|
|
$unit2->getInventoryState()->willReturn(InventoryUnitInterface::STATE_SOLD); |
|
286
|
|
|
|
|
287
|
|
|
$item->getUnits()->willReturn([$unit1, $unit2]); |
|
288
|
|
|
$item->getTotal()->willReturn(4000); |
|
289
|
|
|
|
|
290
|
|
|
$item->setOrder($this)->shouldBeCalled(); |
|
291
|
|
|
$this->addItem($item); |
|
292
|
|
|
|
|
293
|
|
|
$this->shouldNotBeBackorder(); |
|
294
|
|
|
} |
|
295
|
|
|
|
|
296
|
|
|
function it_adds_and_removes_payments(PaymentInterface $payment) |
|
297
|
|
|
{ |
|
298
|
|
|
$payment->getState()->willReturn(PaymentInterface::STATE_PENDING); |
|
299
|
|
|
$payment->setOrder($this)->shouldBeCalled(); |
|
300
|
|
|
|
|
301
|
|
|
$this->addPayment($payment); |
|
302
|
|
|
$this->shouldHavePayment($payment); |
|
303
|
|
|
|
|
304
|
|
|
$payment->setOrder(null)->shouldBeCalled(); |
|
305
|
|
|
|
|
306
|
|
|
$this->removePayment($payment); |
|
307
|
|
|
$this->shouldNotHavePayment($payment); |
|
308
|
|
|
} |
|
309
|
|
|
|
|
310
|
|
|
function it_returns_last_payment(PaymentInterface $payment1, PaymentInterface $payment2) |
|
311
|
|
|
{ |
|
312
|
|
|
$payment1->getState()->willReturn(PaymentInterface::STATE_NEW); |
|
313
|
|
|
$payment1->setOrder($this)->shouldBeCalled(); |
|
314
|
|
|
$payment2->getState()->willReturn(PaymentInterface::STATE_NEW); |
|
315
|
|
|
$payment2->setOrder($this)->shouldBeCalled(); |
|
316
|
|
|
|
|
317
|
|
|
$this->addPayment($payment1); |
|
318
|
|
|
$this->addPayment($payment2); |
|
319
|
|
|
|
|
320
|
|
|
$this->getLastPayment()->shouldReturn($payment2); |
|
321
|
|
|
} |
|
322
|
|
|
|
|
323
|
|
|
function it_adds_and_removes_shipments(ShipmentInterface $shipment) |
|
324
|
|
|
{ |
|
325
|
|
|
$shipment->setOrder($this)->shouldBeCalled(); |
|
326
|
|
|
|
|
327
|
|
|
$this->addShipment($shipment); |
|
328
|
|
|
$this->shouldHaveShipment($shipment); |
|
329
|
|
|
|
|
330
|
|
|
$shipment->setOrder(null)->shouldBeCalled(); |
|
331
|
|
|
|
|
332
|
|
|
$this->removeShipment($shipment); |
|
333
|
|
|
$this->shouldNotHaveShipment($shipment); |
|
334
|
|
|
} |
|
335
|
|
|
|
|
336
|
|
|
function it_has_promotion_coupon(CouponInterface $coupon) |
|
337
|
|
|
{ |
|
338
|
|
|
$this->setPromotionCoupon($coupon); |
|
339
|
|
|
$this->getPromotionCoupon()->shouldReturn($coupon); |
|
340
|
|
|
} |
|
341
|
|
|
|
|
342
|
|
|
function it_count_promotions_subjects(OrderItemInterface $item1, OrderItemInterface $item2) |
|
343
|
|
|
{ |
|
344
|
|
|
$this->addItem($item1); |
|
345
|
|
|
$this->addItem($item2); |
|
346
|
|
|
|
|
347
|
|
|
$this->getPromotionSubjectCount()->shouldReturn(2); |
|
348
|
|
|
} |
|
349
|
|
|
|
|
350
|
|
|
function it_adds_and_removes_promotions(PromotionInterface $promotion) |
|
351
|
|
|
{ |
|
352
|
|
|
$this->addPromotion($promotion); |
|
353
|
|
|
$this->shouldHavePromotion($promotion); |
|
354
|
|
|
|
|
355
|
|
|
$this->removePromotion($promotion); |
|
356
|
|
|
$this->shouldNotHavePromotion($promotion); |
|
357
|
|
|
} |
|
358
|
|
|
} |
|
359
|
|
|
|