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\Collection; |
17
|
|
|
use PhpSpec\ObjectBehavior; |
18
|
|
|
use Sylius\Component\Channel\Model\ChannelInterface; |
19
|
|
|
use Sylius\Component\Core\Model\AddressInterface; |
20
|
|
|
use Sylius\Component\Core\Model\AdjustmentInterface; |
21
|
|
|
use Sylius\Component\Core\Model\Order; |
22
|
|
|
use Sylius\Component\Core\Model\OrderItemInterface; |
23
|
|
|
use Sylius\Component\Core\Model\PaymentInterface; |
24
|
|
|
use Sylius\Component\Core\Model\PromotionInterface; |
25
|
|
|
use Sylius\Component\Core\Model\ShipmentInterface; |
26
|
|
|
use Sylius\Component\Core\OrderCheckoutStates; |
27
|
|
|
use Sylius\Component\Core\OrderShippingStates; |
28
|
|
|
use Sylius\Component\Order\Model\Order as BaseOrder; |
29
|
|
|
use Sylius\Component\Order\Model\OrderInterface; |
30
|
|
|
use Sylius\Component\Promotion\Model\PromotionCouponInterface; |
31
|
|
|
use Sylius\Component\Customer\Model\CustomerInterface; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @author Paweł Jędrzejewski <[email protected]> |
35
|
|
|
*/ |
36
|
|
|
final class OrderSpec extends ObjectBehavior |
37
|
|
|
{ |
38
|
|
|
function it_is_initializable() |
39
|
|
|
{ |
40
|
|
|
$this->shouldHaveType(Order::class); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
function it_implements_an_order_interface() |
44
|
|
|
{ |
45
|
|
|
$this->shouldImplement(OrderInterface::class); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
function it_extends_an_order() |
49
|
|
|
{ |
50
|
|
|
$this->shouldHaveType(BaseOrder::class); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
function it_does_not_have_a_customer_defined_by_default() |
54
|
|
|
{ |
55
|
|
|
$this->getCustomer()->shouldReturn(null); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
function its_allows_defining_customer(CustomerInterface $customer) |
59
|
|
|
{ |
60
|
|
|
$this->setCustomer($customer); |
61
|
|
|
$this->getCustomer()->shouldReturn($customer); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
function its_channel_is_mutable(ChannelInterface $channel) |
65
|
|
|
{ |
66
|
|
|
$this->setChannel($channel); |
67
|
|
|
$this->getChannel()->shouldReturn($channel); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
function it_does_not_have_shipping_address_by_default() |
71
|
|
|
{ |
72
|
|
|
$this->getShippingAddress()->shouldReturn(null); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
function it_allows_defining_shipping_address(AddressInterface $address) |
76
|
|
|
{ |
77
|
|
|
$this->setShippingAddress($address); |
78
|
|
|
$this->getShippingAddress()->shouldReturn($address); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
function it_does_not_have_billing_address_by_default() |
82
|
|
|
{ |
83
|
|
|
$this->getBillingAddress()->shouldReturn(null); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
function it_allows_defining_billing_address(AddressInterface $address) |
87
|
|
|
{ |
88
|
|
|
$this->setBillingAddress($address); |
89
|
|
|
$this->getBillingAddress()->shouldReturn($address); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
function its_checkout_state_is_mutable() |
93
|
|
|
{ |
94
|
|
|
$this->setCheckoutState(OrderCheckoutStates::STATE_CART); |
95
|
|
|
$this->getCheckoutState()->shouldReturn(OrderCheckoutStates::STATE_CART); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
function its_payment_state_is_mutable() |
99
|
|
|
{ |
100
|
|
|
$this->setPaymentState(PaymentInterface::STATE_COMPLETED); |
101
|
|
|
$this->getPaymentState()->shouldReturn(PaymentInterface::STATE_COMPLETED); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
function it_initializes_item_units_collection_by_default() |
105
|
|
|
{ |
106
|
|
|
$this->getItemUnits()->shouldHaveType(Collection::class); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
function it_initializes_shipments_collection_by_default() |
110
|
|
|
{ |
111
|
|
|
$this->getShipments()->shouldHaveType(Collection::class); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
function it_adds_shipment_properly(ShipmentInterface $shipment) |
115
|
|
|
{ |
116
|
|
|
$this->shouldNotHaveShipment($shipment); |
117
|
|
|
|
118
|
|
|
$shipment->setOrder($this)->shouldBeCalled(); |
119
|
|
|
$this->addShipment($shipment); |
120
|
|
|
|
121
|
|
|
$this->shouldHaveShipment($shipment); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
function it_removes_a_shipment_properly(ShipmentInterface $shipment) |
125
|
|
|
{ |
126
|
|
|
$shipment->setOrder($this)->shouldBeCalled(); |
127
|
|
|
$this->addShipment($shipment); |
128
|
|
|
|
129
|
|
|
$this->shouldHaveShipment($shipment); |
130
|
|
|
|
131
|
|
|
$shipment->setOrder(null)->shouldBeCalled(); |
132
|
|
|
$this->removeShipment($shipment); |
133
|
|
|
|
134
|
|
|
$this->shouldNotHaveShipment($shipment); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
function it_removes_shipments(ShipmentInterface $shipment) |
138
|
|
|
{ |
139
|
|
|
$this->addShipment($shipment); |
140
|
|
|
$this->hasShipment($shipment)->shouldReturn(true); |
141
|
|
|
|
142
|
|
|
$this->removeShipments(); |
143
|
|
|
|
144
|
|
|
$this->hasShipment($shipment)->shouldReturn(false); |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
function it_returns_shipping_adjustments( |
148
|
|
|
AdjustmentInterface $shippingAdjustment, |
149
|
|
|
AdjustmentInterface $taxAdjustment |
150
|
|
|
) { |
151
|
|
|
$shippingAdjustment->getType()->willReturn(AdjustmentInterface::SHIPPING_ADJUSTMENT); |
152
|
|
|
$shippingAdjustment->setAdjustable($this)->shouldBeCalled(); |
153
|
|
|
$shippingAdjustment->isNeutral()->willReturn(true); |
154
|
|
|
|
155
|
|
|
$taxAdjustment->getType()->willReturn(AdjustmentInterface::TAX_ADJUSTMENT); |
156
|
|
|
$taxAdjustment->setAdjustable($this)->shouldBeCalled(); |
157
|
|
|
$taxAdjustment->isNeutral()->willReturn(true); |
158
|
|
|
|
159
|
|
|
$this->addAdjustment($shippingAdjustment); |
160
|
|
|
$this->addAdjustment($taxAdjustment); |
161
|
|
|
|
162
|
|
|
$this->getAdjustments()->count()->shouldReturn(2); |
163
|
|
|
|
164
|
|
|
$shippingAdjustments = $this->getAdjustments(AdjustmentInterface::SHIPPING_ADJUSTMENT); |
165
|
|
|
$shippingAdjustments->count()->shouldReturn(1); |
166
|
|
|
$shippingAdjustments->first()->shouldReturn($shippingAdjustment); |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
function it_removes_shipping_adjustments( |
170
|
|
|
AdjustmentInterface $shippingAdjustment, |
171
|
|
|
AdjustmentInterface $taxAdjustment |
172
|
|
|
) { |
173
|
|
|
$shippingAdjustment->getType()->willReturn(AdjustmentInterface::SHIPPING_ADJUSTMENT); |
174
|
|
|
$shippingAdjustment->setAdjustable($this)->shouldBeCalled(); |
175
|
|
|
$shippingAdjustment->isNeutral()->willReturn(true); |
176
|
|
|
|
177
|
|
|
$taxAdjustment->getType()->willReturn(AdjustmentInterface::TAX_ADJUSTMENT); |
178
|
|
|
$taxAdjustment->setAdjustable($this)->shouldBeCalled(); |
179
|
|
|
$taxAdjustment->isNeutral()->willReturn(true); |
180
|
|
|
|
181
|
|
|
$this->addAdjustment($shippingAdjustment); |
182
|
|
|
$this->addAdjustment($taxAdjustment); |
183
|
|
|
|
184
|
|
|
$this->getAdjustments()->count()->shouldReturn(2); |
185
|
|
|
|
186
|
|
|
$shippingAdjustment->isLocked()->willReturn(false); |
187
|
|
|
$shippingAdjustment->setAdjustable(null)->shouldBeCalled(); |
188
|
|
|
$this->removeAdjustments(AdjustmentInterface::SHIPPING_ADJUSTMENT); |
189
|
|
|
|
190
|
|
|
$this->getAdjustments()->count()->shouldReturn(1); |
191
|
|
|
$this->getAdjustments(AdjustmentInterface::SHIPPING_ADJUSTMENT)->count()->shouldReturn(0); |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
function it_returns_tax_adjustments( |
195
|
|
|
AdjustmentInterface $shippingAdjustment, |
196
|
|
|
AdjustmentInterface $taxAdjustment |
197
|
|
|
) { |
198
|
|
|
$shippingAdjustment->getType()->willReturn(AdjustmentInterface::SHIPPING_ADJUSTMENT); |
199
|
|
|
$shippingAdjustment->setAdjustable($this)->shouldBeCalled(); |
200
|
|
|
$shippingAdjustment->isNeutral()->willReturn(true); |
201
|
|
|
|
202
|
|
|
$taxAdjustment->getType()->willReturn(AdjustmentInterface::TAX_ADJUSTMENT); |
203
|
|
|
$taxAdjustment->setAdjustable($this)->shouldBeCalled(); |
204
|
|
|
$taxAdjustment->isNeutral()->willReturn(true); |
205
|
|
|
|
206
|
|
|
$this->addAdjustment($shippingAdjustment); |
207
|
|
|
$this->addAdjustment($taxAdjustment); |
208
|
|
|
|
209
|
|
|
$this->getAdjustments()->count()->shouldReturn(2); |
210
|
|
|
|
211
|
|
|
$taxAdjustments = $this->getAdjustments(AdjustmentInterface::TAX_ADJUSTMENT); |
212
|
|
|
$taxAdjustments->count()->shouldReturn(1); |
213
|
|
|
$taxAdjustments->first()->shouldReturn($taxAdjustment); |
214
|
|
|
} |
215
|
|
|
|
216
|
|
|
function it_removes_tax_adjustments( |
217
|
|
|
AdjustmentInterface $shippingAdjustment, |
218
|
|
|
AdjustmentInterface $taxAdjustment |
219
|
|
|
) { |
220
|
|
|
$shippingAdjustment->getType()->willReturn(AdjustmentInterface::SHIPPING_ADJUSTMENT); |
221
|
|
|
$shippingAdjustment->setAdjustable($this)->shouldBeCalled(); |
222
|
|
|
$shippingAdjustment->isNeutral()->willReturn(true); |
223
|
|
|
|
224
|
|
|
$taxAdjustment->getType()->willReturn(AdjustmentInterface::TAX_ADJUSTMENT); |
225
|
|
|
$taxAdjustment->setAdjustable($this)->shouldBeCalled(); |
226
|
|
|
$taxAdjustment->isNeutral()->willReturn(true); |
227
|
|
|
|
228
|
|
|
$this->addAdjustment($shippingAdjustment); |
229
|
|
|
$this->addAdjustment($taxAdjustment); |
230
|
|
|
|
231
|
|
|
$this->getAdjustments()->count()->shouldReturn(2); |
232
|
|
|
|
233
|
|
|
$taxAdjustment->isLocked()->willReturn(false); |
234
|
|
|
$taxAdjustment->setAdjustable(null)->shouldBeCalled(); |
235
|
|
|
$this->removeAdjustments(AdjustmentInterface::TAX_ADJUSTMENT); |
236
|
|
|
|
237
|
|
|
$this->getAdjustments()->count()->shouldReturn(1); |
238
|
|
|
$this->getAdjustments(AdjustmentInterface::TAX_ADJUSTMENT)->count()->shouldReturn(0); |
239
|
|
|
} |
240
|
|
|
|
241
|
|
|
function it_does_not_have_a_currency_code_defined_by_default() |
242
|
|
|
{ |
243
|
|
|
$this->getCurrencyCode()->shouldReturn(null); |
244
|
|
|
} |
245
|
|
|
|
246
|
|
|
function it_allows_defining_a_currency_code() |
247
|
|
|
{ |
248
|
|
|
$this->setCurrencyCode('PLN'); |
249
|
|
|
$this->getCurrencyCode()->shouldReturn('PLN'); |
250
|
|
|
} |
251
|
|
|
|
252
|
|
|
function it_has_no_default_locale_code() |
253
|
|
|
{ |
254
|
|
|
$this->getLocaleCode()->shouldReturn(null); |
255
|
|
|
} |
256
|
|
|
|
257
|
|
|
function its_locale_code_is_mutable() |
258
|
|
|
{ |
259
|
|
|
$this->setLocaleCode('en'); |
260
|
|
|
$this->getLocaleCode()->shouldReturn('en'); |
261
|
|
|
} |
262
|
|
|
|
263
|
|
|
function it_has_a_cart_shipping_state_by_default() |
264
|
|
|
{ |
265
|
|
|
$this->getShippingState()->shouldReturn(OrderShippingStates::STATE_CART); |
266
|
|
|
} |
267
|
|
|
|
268
|
|
|
function its_shipping_state_is_mutable() |
269
|
|
|
{ |
270
|
|
|
$this->setShippingState(OrderShippingStates::STATE_SHIPPED); |
271
|
|
|
$this->getShippingState()->shouldReturn(OrderShippingStates::STATE_SHIPPED); |
272
|
|
|
} |
273
|
|
|
|
274
|
|
|
function it_adds_and_removes_payments(PaymentInterface $payment) |
275
|
|
|
{ |
276
|
|
|
$payment->getState()->willReturn(PaymentInterface::STATE_NEW); |
277
|
|
|
$payment->setOrder($this)->shouldBeCalled(); |
278
|
|
|
|
279
|
|
|
$this->addPayment($payment); |
280
|
|
|
$this->shouldHavePayment($payment); |
281
|
|
|
|
282
|
|
|
$payment->setOrder(null)->shouldBeCalled(); |
283
|
|
|
|
284
|
|
|
$this->removePayment($payment); |
285
|
|
|
$this->shouldNotHavePayment($payment); |
286
|
|
|
} |
287
|
|
|
|
288
|
|
|
function it_returns_last_payment_with_given_state( |
289
|
|
|
PaymentInterface $payment1, |
290
|
|
|
PaymentInterface $payment2, |
291
|
|
|
PaymentInterface $payment3, |
292
|
|
|
PaymentInterface $payment4 |
293
|
|
|
) { |
294
|
|
|
$payment1->getState()->willReturn(PaymentInterface::STATE_CART); |
295
|
|
|
$payment1->setOrder($this)->shouldBeCalled(); |
296
|
|
|
|
297
|
|
|
$payment2->getState()->willReturn(PaymentInterface::STATE_CANCELLED); |
298
|
|
|
$payment2->setOrder($this)->shouldBeCalled(); |
299
|
|
|
|
300
|
|
|
$payment3->getState()->willReturn(PaymentInterface::STATE_PROCESSING); |
301
|
|
|
$payment3->setOrder($this)->shouldBeCalled(); |
302
|
|
|
|
303
|
|
|
$payment4->getState()->willReturn(PaymentInterface::STATE_FAILED); |
304
|
|
|
$payment4->setOrder($this)->shouldBeCalled(); |
305
|
|
|
|
306
|
|
|
$this->addPayment($payment1); |
307
|
|
|
$this->addPayment($payment2); |
308
|
|
|
$this->addPayment($payment3); |
309
|
|
|
$this->addPayment($payment4); |
310
|
|
|
|
311
|
|
|
$this->getLastPayment(OrderInterface::STATE_CART)->shouldReturn($payment1); |
312
|
|
|
} |
313
|
|
|
|
314
|
|
|
function it_returns_a_null_if_there_is_no_payments_after_trying_to_get_last_payment() |
315
|
|
|
{ |
316
|
|
|
$this->getLastPayment(OrderInterface::STATE_CART)->shouldReturn(null); |
317
|
|
|
} |
318
|
|
|
|
319
|
|
|
function it_returns_last_payment_with_any_state_if_there_is_no_target_state_specified( |
320
|
|
|
PaymentInterface $payment1, |
321
|
|
|
PaymentInterface $payment2, |
322
|
|
|
PaymentInterface $payment3, |
323
|
|
|
PaymentInterface $payment4 |
324
|
|
|
) { |
325
|
|
|
$payment1->getState()->willReturn(PaymentInterface::STATE_CART); |
326
|
|
|
$payment1->setOrder($this)->shouldBeCalled(); |
327
|
|
|
|
328
|
|
|
$payment2->getState()->willReturn(PaymentInterface::STATE_CANCELLED); |
329
|
|
|
$payment2->setOrder($this)->shouldBeCalled(); |
330
|
|
|
|
331
|
|
|
$payment3->getState()->willReturn(PaymentInterface::STATE_PROCESSING); |
332
|
|
|
$payment3->setOrder($this)->shouldBeCalled(); |
333
|
|
|
|
334
|
|
|
$payment4->getState()->willReturn(PaymentInterface::STATE_FAILED); |
335
|
|
|
$payment4->setOrder($this)->shouldBeCalled(); |
336
|
|
|
|
337
|
|
|
$this->addPayment($payment1); |
338
|
|
|
$this->addPayment($payment2); |
339
|
|
|
$this->addPayment($payment3); |
340
|
|
|
$this->addPayment($payment4); |
341
|
|
|
|
342
|
|
|
$this->getLastPayment()->shouldReturn($payment4); |
343
|
|
|
} |
344
|
|
|
|
345
|
|
|
function it_adds_and_removes_shipments(ShipmentInterface $shipment) |
346
|
|
|
{ |
347
|
|
|
$shipment->setOrder($this)->shouldBeCalled(); |
348
|
|
|
|
349
|
|
|
$this->addShipment($shipment); |
350
|
|
|
$this->shouldHaveShipment($shipment); |
351
|
|
|
|
352
|
|
|
$shipment->setOrder(null)->shouldBeCalled(); |
353
|
|
|
|
354
|
|
|
$this->removeShipment($shipment); |
355
|
|
|
$this->shouldNotHaveShipment($shipment); |
356
|
|
|
} |
357
|
|
|
|
358
|
|
|
function it_has_a_promotion_coupon(PromotionCouponInterface $coupon) |
359
|
|
|
{ |
360
|
|
|
$this->setPromotionCoupon($coupon); |
361
|
|
|
$this->getPromotionCoupon()->shouldReturn($coupon); |
362
|
|
|
} |
363
|
|
|
|
364
|
|
|
function it_counts_promotions_subjects(OrderItemInterface $item1, OrderItemInterface $item2) |
365
|
|
|
{ |
366
|
|
|
$item1->getQuantity()->willReturn(4); |
367
|
|
|
$item1->getTotal()->willReturn(420); |
368
|
|
|
$item1->setOrder($this)->will(function () {}); |
369
|
|
|
|
370
|
|
|
$item2->getQuantity()->willReturn(3); |
371
|
|
|
$item2->getTotal()->willReturn(666); |
372
|
|
|
$item2->setOrder($this)->will(function () {}); |
373
|
|
|
|
374
|
|
|
$this->addItem($item1); |
375
|
|
|
$this->addItem($item2); |
376
|
|
|
|
377
|
|
|
$this->getPromotionSubjectCount()->shouldReturn(7); |
378
|
|
|
} |
379
|
|
|
|
380
|
|
|
function it_adds_and_removes_promotions(PromotionInterface $promotion) |
381
|
|
|
{ |
382
|
|
|
$this->addPromotion($promotion); |
383
|
|
|
$this->shouldHavePromotion($promotion); |
384
|
|
|
|
385
|
|
|
$this->removePromotion($promotion); |
386
|
|
|
$this->shouldNotHavePromotion($promotion); |
387
|
|
|
} |
388
|
|
|
|
389
|
|
|
function it_returns_0_tax_total_when_there_are_no_items_and_adjustments() |
390
|
|
|
{ |
391
|
|
|
$this->getTaxTotal()->shouldReturn(0); |
392
|
|
|
} |
393
|
|
|
|
394
|
|
|
function it_returns_a_tax_of_all_items_as_tax_total_when_there_are_no_tax_adjustments( |
395
|
|
|
OrderItemInterface $orderItem1, |
396
|
|
|
OrderItemInterface $orderItem2 |
397
|
|
|
) { |
398
|
|
|
$orderItem1->getTotal()->willReturn(1100); |
399
|
|
|
$orderItem1->getTaxTotal()->willReturn(100); |
400
|
|
|
$orderItem2->getTotal()->willReturn(1050); |
401
|
|
|
$orderItem2->getTaxTotal()->willReturn(50); |
402
|
|
|
|
403
|
|
|
$orderItem1->setOrder($this)->shouldBeCalled(); |
404
|
|
|
$orderItem2->setOrder($this)->shouldBeCalled(); |
405
|
|
|
$this->addItem($orderItem1); |
406
|
|
|
$this->addItem($orderItem2); |
407
|
|
|
|
408
|
|
|
$this->getTaxTotal()->shouldReturn(150); |
409
|
|
|
} |
410
|
|
|
|
411
|
|
|
function it_returns_a_tax_of_all_items_and_non_neutral_shipping_tax_as_tax_total( |
412
|
|
|
OrderItemInterface $orderItem1, |
413
|
|
|
OrderItemInterface $orderItem2, |
414
|
|
|
AdjustmentInterface $shippingAdjustment, |
415
|
|
|
AdjustmentInterface $shippingTaxAdjustment |
|
|
|
|
416
|
|
|
) { |
417
|
|
|
$orderItem1->getTotal()->willReturn(1100); |
418
|
|
|
$orderItem1->getTaxTotal()->willReturn(100); |
419
|
|
|
$orderItem2->getTotal()->willReturn(1050); |
420
|
|
|
$orderItem2->getTaxTotal()->willReturn(50); |
421
|
|
|
|
422
|
|
|
$shippingAdjustment->getType()->willReturn(AdjustmentInterface::SHIPPING_ADJUSTMENT); |
423
|
|
|
$shippingAdjustment->isNeutral()->willReturn(false); |
424
|
|
|
$shippingAdjustment->getAmount()->willReturn(1000); |
425
|
|
|
$shippingTaxAdjustment->getType()->willReturn(AdjustmentInterface::TAX_ADJUSTMENT); |
426
|
|
|
$shippingTaxAdjustment->isNeutral()->willReturn(false); |
427
|
|
|
$shippingTaxAdjustment->getAmount()->willReturn(70); |
428
|
|
|
|
429
|
|
|
$orderItem1->setOrder($this)->shouldBeCalled(); |
430
|
|
|
$orderItem2->setOrder($this)->shouldBeCalled(); |
431
|
|
|
$this->addItem($orderItem1); |
432
|
|
|
$this->addItem($orderItem2); |
433
|
|
|
|
434
|
|
|
$shippingAdjustment->setAdjustable($this)->shouldBeCalled(); |
435
|
|
|
$this->addAdjustment($shippingAdjustment); |
436
|
|
|
|
437
|
|
|
$shippingTaxAdjustment->setAdjustable($this)->shouldBeCalled(); |
438
|
|
|
$this->addAdjustment($shippingTaxAdjustment); |
439
|
|
|
|
440
|
|
|
$this->getTaxTotal()->shouldReturn(220); |
441
|
|
|
} |
442
|
|
|
|
443
|
|
|
function it_returns_a_tax_of_all_items_and_neutral_shipping_tax_as_tax_total( |
444
|
|
|
OrderItemInterface $orderItem1, |
445
|
|
|
OrderItemInterface $orderItem2, |
446
|
|
|
AdjustmentInterface $shippingAdjustment, |
447
|
|
|
AdjustmentInterface $shippingTaxAdjustment |
|
|
|
|
448
|
|
|
) { |
449
|
|
|
$orderItem1->getTotal()->willReturn(1100); |
450
|
|
|
$orderItem1->getTaxTotal()->willReturn(100); |
451
|
|
|
$orderItem2->getTotal()->willReturn(1050); |
452
|
|
|
$orderItem2->getTaxTotal()->willReturn(50); |
453
|
|
|
|
454
|
|
|
$shippingAdjustment->getType()->willReturn(AdjustmentInterface::SHIPPING_ADJUSTMENT); |
455
|
|
|
$shippingAdjustment->isNeutral()->willReturn(false); |
456
|
|
|
$shippingAdjustment->getAmount()->willReturn(1000); |
457
|
|
|
|
458
|
|
|
$shippingTaxAdjustment->getType()->willReturn(AdjustmentInterface::TAX_ADJUSTMENT); |
459
|
|
|
$shippingTaxAdjustment->isNeutral()->willReturn(true); |
460
|
|
|
$shippingTaxAdjustment->getAmount()->willReturn(70); |
461
|
|
|
|
462
|
|
|
$orderItem1->setOrder($this)->shouldBeCalled(); |
463
|
|
|
$orderItem2->setOrder($this)->shouldBeCalled(); |
464
|
|
|
$this->addItem($orderItem1); |
465
|
|
|
$this->addItem($orderItem2); |
466
|
|
|
|
467
|
|
|
$shippingAdjustment->setAdjustable($this)->shouldBeCalled(); |
468
|
|
|
$shippingTaxAdjustment->setAdjustable($this)->shouldBeCalled(); |
469
|
|
|
$this->addAdjustment($shippingAdjustment); |
470
|
|
|
$this->addAdjustment($shippingTaxAdjustment); |
471
|
|
|
|
472
|
|
|
$this->getTaxTotal()->shouldReturn(220); |
473
|
|
|
} |
474
|
|
|
|
475
|
|
|
function it_includes_a_non_neutral_tax_adjustments_in_shipping_total( |
476
|
|
|
AdjustmentInterface $shippingAdjustment, |
477
|
|
|
AdjustmentInterface $shippingTaxAdjustment |
|
|
|
|
478
|
|
|
) { |
479
|
|
|
$shippingAdjustment->getType()->willReturn(AdjustmentInterface::SHIPPING_ADJUSTMENT); |
480
|
|
|
$shippingAdjustment->isNeutral()->willReturn(false); |
481
|
|
|
$shippingAdjustment->getAmount()->willReturn(1000); |
482
|
|
|
|
483
|
|
|
$shippingTaxAdjustment->getType()->willReturn(AdjustmentInterface::TAX_ADJUSTMENT); |
484
|
|
|
$shippingTaxAdjustment->isNeutral()->willReturn(false); |
485
|
|
|
$shippingTaxAdjustment->getAmount()->willReturn(70); |
486
|
|
|
|
487
|
|
|
$shippingAdjustment->setAdjustable($this)->shouldBeCalled(); |
488
|
|
|
$shippingTaxAdjustment->setAdjustable($this)->shouldBeCalled(); |
489
|
|
|
$this->addAdjustment($shippingAdjustment); |
490
|
|
|
$this->addAdjustment($shippingTaxAdjustment); |
491
|
|
|
|
492
|
|
|
$this->getShippingTotal()->shouldReturn(1070); |
493
|
|
|
} |
494
|
|
|
|
495
|
|
|
function it_returns_a_shipping_total_decreased_by_shipping_promotion( |
496
|
|
|
AdjustmentInterface $shippingAdjustment, |
497
|
|
|
AdjustmentInterface $shippingTaxAdjustment, |
|
|
|
|
498
|
|
|
AdjustmentInterface $shippingPromotionAdjustment |
|
|
|
|
499
|
|
|
) { |
500
|
|
|
$shippingAdjustment->getType()->willReturn(AdjustmentInterface::SHIPPING_ADJUSTMENT); |
501
|
|
|
$shippingAdjustment->isNeutral()->willReturn(false); |
502
|
|
|
$shippingAdjustment->getAmount()->willReturn(1000); |
503
|
|
|
|
504
|
|
|
$shippingTaxAdjustment->getType()->willReturn(AdjustmentInterface::TAX_ADJUSTMENT); |
505
|
|
|
$shippingTaxAdjustment->isNeutral()->willReturn(false); |
506
|
|
|
$shippingTaxAdjustment->getAmount()->willReturn(70); |
507
|
|
|
|
508
|
|
|
$shippingPromotionAdjustment->getType()->willReturn(AdjustmentInterface::ORDER_SHIPPING_PROMOTION_ADJUSTMENT); |
509
|
|
|
$shippingPromotionAdjustment->isNeutral()->willReturn(false); |
510
|
|
|
$shippingPromotionAdjustment->getAmount()->willReturn(-100); |
511
|
|
|
|
512
|
|
|
$shippingAdjustment->setAdjustable($this)->shouldBeCalled(); |
513
|
|
|
$shippingTaxAdjustment->setAdjustable($this)->shouldBeCalled(); |
514
|
|
|
$shippingPromotionAdjustment->setAdjustable($this)->shouldBeCalled(); |
515
|
|
|
$this->addAdjustment($shippingAdjustment); |
516
|
|
|
$this->addAdjustment($shippingTaxAdjustment); |
517
|
|
|
$this->addAdjustment($shippingPromotionAdjustment); |
518
|
|
|
|
519
|
|
|
$this->getShippingTotal()->shouldReturn(970); |
520
|
|
|
} |
521
|
|
|
|
522
|
|
|
function it_does_not_include_neutral_tax_adjustments_in_shipping_total( |
523
|
|
|
AdjustmentInterface $shippingAdjustment, |
524
|
|
|
AdjustmentInterface $neutralShippingTaxAdjustment |
|
|
|
|
525
|
|
|
) { |
526
|
|
|
$shippingAdjustment->getType()->willReturn(AdjustmentInterface::SHIPPING_ADJUSTMENT); |
527
|
|
|
$shippingAdjustment->isNeutral()->willReturn(false); |
528
|
|
|
$shippingAdjustment->getAmount()->willReturn(1000); |
529
|
|
|
|
530
|
|
|
$neutralShippingTaxAdjustment->getType()->willReturn(AdjustmentInterface::TAX_ADJUSTMENT); |
531
|
|
|
$neutralShippingTaxAdjustment->isNeutral()->willReturn(true); |
532
|
|
|
$neutralShippingTaxAdjustment->getAmount()->willReturn(70); |
533
|
|
|
|
534
|
|
|
$shippingAdjustment->setAdjustable($this)->shouldBeCalled(); |
535
|
|
|
$neutralShippingTaxAdjustment->setAdjustable($this)->shouldBeCalled(); |
536
|
|
|
$this->addAdjustment($shippingAdjustment); |
537
|
|
|
$this->addAdjustment($neutralShippingTaxAdjustment); |
538
|
|
|
|
539
|
|
|
$this->getShippingTotal()->shouldReturn(1000); |
540
|
|
|
} |
541
|
|
|
|
542
|
|
|
function it_returns_0_as_promotion_total_when_there_are_no_order_promotion_adjustments() |
543
|
|
|
{ |
544
|
|
|
$this->getOrderPromotionTotal()->shouldReturn(0); |
545
|
|
|
} |
546
|
|
|
|
547
|
|
|
function it_returns_a_sum_of_all_order_promotion_adjustments_applied_to_items_as_order_promotion_total( |
548
|
|
|
OrderItemInterface $orderItem1, |
549
|
|
|
OrderItemInterface $orderItem2 |
550
|
|
|
) { |
551
|
|
|
$orderItem1->getTotal()->willReturn(500); |
552
|
|
|
$orderItem2->getTotal()->willReturn(300); |
553
|
|
|
|
554
|
|
|
$orderItem1->getAdjustmentsTotalRecursively(AdjustmentInterface::ORDER_PROMOTION_ADJUSTMENT)->willReturn(-400); |
555
|
|
|
$orderItem2->getAdjustmentsTotalRecursively(AdjustmentInterface::ORDER_PROMOTION_ADJUSTMENT)->willReturn(-600); |
556
|
|
|
|
557
|
|
|
$orderItem1->setOrder($this)->shouldBeCalled(); |
558
|
|
|
$orderItem2->setOrder($this)->shouldBeCalled(); |
559
|
|
|
$this->addItem($orderItem1); |
560
|
|
|
$this->addItem($orderItem2); |
561
|
|
|
|
562
|
|
|
$this->getOrderPromotionTotal()->shouldReturn(-1000); |
563
|
|
|
} |
564
|
|
|
|
565
|
|
|
function it_does_not_include_a_shipping_promotion_adjustment_in_order_promotion_total( |
566
|
|
|
AdjustmentInterface $shippingPromotionAdjustment, |
|
|
|
|
567
|
|
|
OrderItemInterface $orderItem1 |
568
|
|
|
) { |
569
|
|
|
$orderItem1->getTotal()->willReturn(500); |
570
|
|
|
$orderItem1->getAdjustmentsTotalRecursively(AdjustmentInterface::ORDER_PROMOTION_ADJUSTMENT)->willReturn(-400); |
571
|
|
|
|
572
|
|
|
$shippingPromotionAdjustment->getType()->willReturn(AdjustmentInterface::ORDER_PROMOTION_ADJUSTMENT); |
573
|
|
|
$shippingPromotionAdjustment->isNeutral()->willReturn(false); |
574
|
|
|
$shippingPromotionAdjustment->getAmount()->willReturn(-100); |
575
|
|
|
|
576
|
|
|
$orderItem1->setOrder($this)->shouldBeCalled(); |
577
|
|
|
$this->addItem($orderItem1); |
578
|
|
|
|
579
|
|
|
$shippingPromotionAdjustment->setAdjustable($this)->shouldBeCalled(); |
580
|
|
|
$this->addAdjustment($shippingPromotionAdjustment); |
581
|
|
|
|
582
|
|
|
$this->getOrderPromotionTotal()->shouldReturn(-400); |
583
|
|
|
} |
584
|
|
|
|
585
|
|
|
function it_has_a_token_value() |
586
|
|
|
{ |
587
|
|
|
$this->setTokenValue('xyzasdxqwe'); |
588
|
|
|
|
589
|
|
|
$this->getTokenValue()->shouldReturn('xyzasdxqwe'); |
590
|
|
|
} |
591
|
|
|
|
592
|
|
|
function it_has_customer_ip() |
593
|
|
|
{ |
594
|
|
|
$this->setCustomerIp('172.16.254.1'); |
595
|
|
|
$this->getCustomerIp()->shouldReturn('172.16.254.1'); |
596
|
|
|
} |
597
|
|
|
} |
598
|
|
|
|
Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.