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 Sylius\Behat\Context\Ui\Admin; |
13
|
|
|
|
14
|
|
|
use Behat\Behat\Context\Context; |
15
|
|
|
use Sylius\Behat\NotificationType; |
16
|
|
|
use Sylius\Behat\Page\Admin\Crud\IndexPageInterface; |
17
|
|
|
use Sylius\Behat\Page\Admin\Order\ShowPageInterface; |
18
|
|
|
use Sylius\Behat\Page\Admin\Order\UpdatePageInterface; |
19
|
|
|
use Sylius\Behat\Service\NotificationCheckerInterface; |
20
|
|
|
use Sylius\Behat\Service\SharedSecurityServiceInterface; |
21
|
|
|
use Sylius\Behat\Service\SharedStorageInterface; |
22
|
|
|
use Sylius\Component\Addressing\Model\AddressInterface; |
23
|
|
|
use Sylius\Component\Core\Formatter\StringInflector; |
24
|
|
|
use Sylius\Component\Core\Model\AdminUserInterface; |
25
|
|
|
use Sylius\Component\Core\Model\CustomerInterface; |
26
|
|
|
use Sylius\Component\Core\Model\OrderInterface; |
27
|
|
|
use Webmozart\Assert\Assert; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @author Paweł Jędrzejewski <[email protected]> |
31
|
|
|
* @author Grzegorz Sadowski <[email protected]> |
32
|
|
|
*/ |
33
|
|
|
final class ManagingOrdersContext implements Context |
34
|
|
|
{ |
35
|
|
|
/** |
36
|
|
|
* @var SharedStorageInterface |
37
|
|
|
*/ |
38
|
|
|
private $sharedStorage; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @var IndexPageInterface |
42
|
|
|
*/ |
43
|
|
|
private $indexPage; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @var ShowPageInterface |
47
|
|
|
*/ |
48
|
|
|
private $showPage; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @var UpdatePageInterface |
52
|
|
|
*/ |
53
|
|
|
private $updatePage; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @var NotificationCheckerInterface |
57
|
|
|
*/ |
58
|
|
|
private $notificationChecker; |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @var SharedSecurityServiceInterface |
62
|
|
|
*/ |
63
|
|
|
private $sharedSecurityService; |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @param SharedStorageInterface $sharedStorage |
67
|
|
|
* @param IndexPageInterface $indexPage |
68
|
|
|
* @param ShowPageInterface $showPage |
69
|
|
|
* @param UpdatePageInterface $updatePage |
70
|
|
|
* @param NotificationCheckerInterface $notificationChecker |
71
|
|
|
* @param SharedSecurityServiceInterface $sharedSecurityService |
72
|
|
|
*/ |
73
|
|
|
public function __construct( |
74
|
|
|
SharedStorageInterface $sharedStorage, |
75
|
|
|
IndexPageInterface $indexPage, |
76
|
|
|
ShowPageInterface $showPage, |
77
|
|
|
UpdatePageInterface $updatePage, |
78
|
|
|
NotificationCheckerInterface $notificationChecker, |
79
|
|
|
SharedSecurityServiceInterface $sharedSecurityService |
|
|
|
|
80
|
|
|
) { |
81
|
|
|
$this->sharedStorage = $sharedStorage; |
82
|
|
|
$this->indexPage = $indexPage; |
83
|
|
|
$this->showPage = $showPage; |
84
|
|
|
$this->updatePage = $updatePage; |
85
|
|
|
$this->notificationChecker = $notificationChecker; |
86
|
|
|
$this->sharedSecurityService = $sharedSecurityService; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @Given I am browsing orders |
91
|
|
|
* @When I browse orders |
92
|
|
|
*/ |
93
|
|
|
public function iBrowseOrders() |
94
|
|
|
{ |
95
|
|
|
$this->indexPage->open(); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @Given /^I am viewing the summary of (this order)$/ |
100
|
|
|
* @When I view the summary of the order :order |
101
|
|
|
* @When /^I view the summary of (this order made by "[^"]+")$/ |
102
|
|
|
*/ |
103
|
|
|
public function iSeeTheOrder(OrderInterface $order) |
104
|
|
|
{ |
105
|
|
|
$this->showPage->open(['id' => $order->getId()]); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* @When /^I mark (this order) as paid$/ |
110
|
|
|
*/ |
111
|
|
|
public function iMarkThisOrderAsAPaid(OrderInterface $order) |
112
|
|
|
{ |
113
|
|
|
$this->showPage->completeOrderLastPayment($order); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* @When /^I mark (this order)'s payment as refunded$/ |
118
|
|
|
*/ |
119
|
|
|
public function iMarkThisOrderSPaymentAsRefunded(OrderInterface $order) |
120
|
|
|
{ |
121
|
|
|
$this->showPage->refundOrderLastPayment($order); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* @When specify its tracking code as :trackingCode |
126
|
|
|
*/ |
127
|
|
|
public function specifyItsTrackingCodeAs($trackingCode) |
128
|
|
|
{ |
129
|
|
|
$this->showPage->specifyTrackingCode($trackingCode); |
130
|
|
|
$this->sharedStorage->set('tracking_code', $trackingCode); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* @When /^I ship (this order)$/ |
135
|
|
|
*/ |
136
|
|
|
public function iShipThisOrder(OrderInterface $order) |
137
|
|
|
{ |
138
|
|
|
$this->showPage->shipOrder($order); |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* @When I switch the way orders are sorted by :fieldName |
143
|
|
|
*/ |
144
|
|
|
public function iSwitchSortingBy($fieldName) |
145
|
|
|
{ |
146
|
|
|
$this->indexPage->sortBy($fieldName); |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* @Then I should see a single order from customer :customer |
151
|
|
|
*/ |
152
|
|
|
public function iShouldSeeASingleOrderFromCustomer(CustomerInterface $customer) |
153
|
|
|
{ |
154
|
|
|
Assert::true( |
155
|
|
|
$this->indexPage->isSingleResourceOnPage(['customer' => $customer->getEmail()]), |
156
|
|
|
sprintf('Cannot find order for customer "%s" in the list.', $customer->getEmail()) |
157
|
|
|
); |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* @Then it should have been placed by the customer :customerEmail |
162
|
|
|
*/ |
163
|
|
|
public function itShouldBePlacedByCustomer($customerEmail) |
164
|
|
|
{ |
165
|
|
|
Assert::true( |
166
|
|
|
$this->showPage->hasCustomer($customerEmail), |
167
|
|
|
sprintf('Cannot find customer "%s".', $customerEmail) |
168
|
|
|
); |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
/** |
172
|
|
|
* @Then it should be shipped to :customerName, :street, :postcode, :city, :countryName |
173
|
|
|
* @Then /^(this order) should (?:|still )be shipped to "([^"]+)", "([^"]+)", "([^"]+)", "([^"]+)", "([^"]+)"$/ |
174
|
|
|
*/ |
175
|
|
|
public function itShouldBeShippedTo( |
176
|
|
|
OrderInterface $order = null, |
177
|
|
|
$customerName, |
|
|
|
|
178
|
|
|
$street, |
179
|
|
|
$postcode, |
180
|
|
|
$city, |
181
|
|
|
$countryName |
182
|
|
|
) { |
183
|
|
|
if (null !== $order) { |
184
|
|
|
$this->iSeeTheOrder($order); |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
Assert::true( |
188
|
|
|
$this->showPage->hasShippingAddress($customerName, $street, $postcode, $city, $countryName), |
189
|
|
|
sprintf('Cannot find shipping address "%s, %s %s, %s".', $street, $postcode, $city, $countryName) |
190
|
|
|
); |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
/** |
194
|
|
|
* @Then it should be billed to :customerName, :street, :postcode, :city, :countryName |
195
|
|
|
* @Then /^(this order) bill should (?:|still )be shipped to "([^"]+)", "([^"]+)", "([^"]+)", "([^"]+)", "([^"]+)"$/ |
196
|
|
|
*/ |
197
|
|
|
public function itShouldBeBilledTo( |
198
|
|
|
OrderInterface $order = null, |
199
|
|
|
$customerName, |
|
|
|
|
200
|
|
|
$street, |
201
|
|
|
$postcode, |
202
|
|
|
$city, |
203
|
|
|
$countryName |
204
|
|
|
) { |
205
|
|
|
if (null !== $order) { |
206
|
|
|
$this->iSeeTheOrder($order); |
207
|
|
|
} |
208
|
|
|
|
209
|
|
|
Assert::true( |
210
|
|
|
$this->showPage->hasBillingAddress($customerName, $street, $postcode, $city, $countryName), |
211
|
|
|
sprintf('Cannot find shipping address "%s, %s %s, %s".', $street, $postcode, $city, $countryName) |
212
|
|
|
); |
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
/** |
216
|
|
|
* @Then it should be shipped via the :shippingMethodName shipping method |
217
|
|
|
*/ |
218
|
|
|
public function itShouldBeShippedViaShippingMethod($shippingMethodName) |
219
|
|
|
{ |
220
|
|
|
Assert::true( |
221
|
|
|
$this->showPage->hasShipment($shippingMethodName), |
222
|
|
|
sprintf('Cannot find shipment "%s".', $shippingMethodName) |
223
|
|
|
); |
224
|
|
|
} |
225
|
|
|
|
226
|
|
|
/** |
227
|
|
|
* @Then it should be paid with :paymentMethodName |
228
|
|
|
*/ |
229
|
|
|
public function itShouldBePaidWith($paymentMethodName) |
230
|
|
|
{ |
231
|
|
|
Assert::true( |
232
|
|
|
$this->showPage->hasPayment($paymentMethodName), |
233
|
|
|
sprintf('Cannot find payment "%s".', $paymentMethodName) |
234
|
|
|
); |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
/** |
238
|
|
|
* @Then /^it should have (\d+) items$/ |
239
|
|
|
*/ |
240
|
|
|
public function itShouldHaveAmountOfItems($amount) |
241
|
|
|
{ |
242
|
|
|
$itemsCount = $this->showPage->countItems(); |
243
|
|
|
|
244
|
|
|
Assert::same( |
245
|
|
|
(int)$amount, |
246
|
|
|
$itemsCount, |
247
|
|
|
sprintf('There should be %d items, but get %d.', $amount, $itemsCount) |
248
|
|
|
); |
249
|
|
|
} |
250
|
|
|
|
251
|
|
|
/** |
252
|
|
|
* @Then the product named :productName should be in the items list |
253
|
|
|
*/ |
254
|
|
|
public function theProductShouldBeInTheItemsList($productName) |
255
|
|
|
{ |
256
|
|
|
Assert::true( |
257
|
|
|
$this->showPage->isProductInTheList($productName), |
258
|
|
|
sprintf('Product %s is not in the item list.', $productName) |
259
|
|
|
); |
260
|
|
|
} |
261
|
|
|
|
262
|
|
|
/** |
263
|
|
|
* @Then the order's items total should be :itemsTotal |
264
|
|
|
*/ |
265
|
|
|
public function theOrdersItemsTotalShouldBe($itemsTotal) |
266
|
|
|
{ |
267
|
|
|
$itemsTotalOnPage = $this->showPage->getItemsTotal(); |
268
|
|
|
|
269
|
|
|
Assert::eq( |
270
|
|
|
$itemsTotalOnPage, |
271
|
|
|
$itemsTotal, |
272
|
|
|
'Items total is %s, but should be %s.' |
273
|
|
|
); |
274
|
|
|
} |
275
|
|
|
|
276
|
|
|
/** |
277
|
|
|
* @Then /^the order's total should(?:| still) be "([^"]+)"$/ |
278
|
|
|
*/ |
279
|
|
|
public function theOrdersTotalShouldBe($total) |
280
|
|
|
{ |
281
|
|
|
$totalOnPage = $this->showPage->getTotal(); |
282
|
|
|
|
283
|
|
|
Assert::eq( |
284
|
|
|
$totalOnPage, |
285
|
|
|
$total, |
286
|
|
|
'Total is %s, but should be %s.' |
287
|
|
|
); |
288
|
|
|
} |
289
|
|
|
|
290
|
|
|
/** |
291
|
|
|
* @Then there should be a shipping charge :shippingCharge |
292
|
|
|
*/ |
293
|
|
|
public function theOrdersShippingChargesShouldBe($shippingCharge) |
294
|
|
|
{ |
295
|
|
|
Assert::true( |
296
|
|
|
$this->showPage->hasShippingCharge($shippingCharge), |
297
|
|
|
sprintf('Shipping charges is not "%s".', $shippingCharge) |
298
|
|
|
); |
299
|
|
|
} |
300
|
|
|
|
301
|
|
|
/** |
302
|
|
|
* @Then the order's shipping total should be :shippingTotal |
303
|
|
|
*/ |
304
|
|
|
public function theOrdersShippingTotalShouldBe($shippingTotal) |
305
|
|
|
{ |
306
|
|
|
$shippingTotalOnPage = $this->showPage->getShippingTotal(); |
307
|
|
|
|
308
|
|
|
Assert::eq( |
309
|
|
|
$shippingTotal, |
310
|
|
|
$shippingTotalOnPage, |
311
|
|
|
sprintf('Shipping total is "%s", but should be "%s".', $shippingTotalOnPage, $shippingTotal) |
312
|
|
|
); |
313
|
|
|
} |
314
|
|
|
|
315
|
|
|
/** |
316
|
|
|
* @Then the order's payment should (also) be :paymentAmount |
317
|
|
|
*/ |
318
|
|
|
public function theOrdersPaymentShouldBe($paymentAmount) |
319
|
|
|
{ |
320
|
|
|
$actualPaymentAmount = $this->showPage->getPaymentAmount(); |
321
|
|
|
|
322
|
|
|
Assert::eq($paymentAmount, $actualPaymentAmount); |
323
|
|
|
} |
324
|
|
|
|
325
|
|
|
/** |
326
|
|
|
* @Then the order should have tax :tax |
327
|
|
|
*/ |
328
|
|
|
public function theOrderShouldHaveTax($tax) |
329
|
|
|
{ |
330
|
|
|
Assert::true( |
331
|
|
|
$this->showPage->hasTax($tax), |
332
|
|
|
sprintf('Order should have tax "%s", but it does not.', $tax) |
333
|
|
|
); |
334
|
|
|
} |
335
|
|
|
|
336
|
|
|
/** |
337
|
|
|
* @Then /^the order's tax total should(?:| still) be "([^"]+)"$/ |
338
|
|
|
*/ |
339
|
|
|
public function theOrdersTaxTotalShouldBe($taxTotal) |
340
|
|
|
{ |
341
|
|
|
$taxTotalOnPage = $this->showPage->getTaxTotal(); |
342
|
|
|
|
343
|
|
|
Assert::eq( |
344
|
|
|
$taxTotal, |
345
|
|
|
$taxTotalOnPage, |
346
|
|
|
sprintf('Tax total is "%s", but should be "%s".', $taxTotalOnPage, $taxTotal) |
347
|
|
|
); |
348
|
|
|
} |
349
|
|
|
|
350
|
|
|
/** |
351
|
|
|
* @Then the order's promotion discount should be :promotionDiscount |
352
|
|
|
*/ |
353
|
|
|
public function theOrdersPromotionDiscountShouldBe($promotionDiscount) |
354
|
|
|
{ |
355
|
|
|
Assert::true( |
356
|
|
|
$this->showPage->hasPromotionDiscount($promotionDiscount), |
357
|
|
|
sprintf('Promotion discount is not "%s".', $promotionDiscount) |
358
|
|
|
); |
359
|
|
|
} |
360
|
|
|
|
361
|
|
|
/** |
362
|
|
|
* @Then /^the order's promotion total should(?:| still) be "([^"]+)"$/ |
363
|
|
|
*/ |
364
|
|
|
public function theOrdersPromotionTotalShouldBe($promotionTotal) |
365
|
|
|
{ |
366
|
|
|
$promotionTotalOnPage = $this->showPage->getPromotionTotal(); |
367
|
|
|
|
368
|
|
|
Assert::eq( |
369
|
|
|
$promotionTotalOnPage, |
370
|
|
|
$promotionTotal, |
371
|
|
|
'Promotion total is %s, but should be %s.' |
372
|
|
|
); |
373
|
|
|
} |
374
|
|
|
|
375
|
|
|
/** |
376
|
|
|
* @When I check :itemName data |
377
|
|
|
*/ |
378
|
|
|
public function iCheckData($itemName) |
379
|
|
|
{ |
380
|
|
|
$this->sharedStorage->set('item', $itemName); |
381
|
|
|
} |
382
|
|
|
|
383
|
|
|
/** |
384
|
|
|
* @Then /^(its) code should be "([^"]+)"$/ |
385
|
|
|
*/ |
386
|
|
|
public function itemCodeShouldBe($itemName, $code) |
387
|
|
|
{ |
388
|
|
|
$itemCodeOnPage = $this->showPage->getItemCode($itemName); |
389
|
|
|
|
390
|
|
|
Assert::same( |
391
|
|
|
$itemCodeOnPage, |
392
|
|
|
$code, |
393
|
|
|
'Item code is %s, but should be %s.' |
394
|
|
|
); |
395
|
|
|
} |
396
|
|
|
|
397
|
|
|
/** |
398
|
|
|
* @Then /^(its) unit price should be ([^"]+)$/ |
399
|
|
|
*/ |
400
|
|
|
public function itemUnitPriceShouldBe($itemName, $unitPrice) |
401
|
|
|
{ |
402
|
|
|
$itemUnitPriceOnPage = $this->showPage->getItemUnitPrice($itemName); |
403
|
|
|
|
404
|
|
|
Assert::eq( |
405
|
|
|
$itemUnitPriceOnPage, |
406
|
|
|
$unitPrice, |
407
|
|
|
'Item unit price is %s, but should be %s.' |
408
|
|
|
); |
409
|
|
|
} |
410
|
|
|
|
411
|
|
|
/** |
412
|
|
|
* @Then /^(its) discounted unit price should be ([^"]+)$/ |
413
|
|
|
*/ |
414
|
|
|
public function itemDiscountedUnitPriceShouldBe($itemName, $discountedUnitPrice) |
415
|
|
|
{ |
416
|
|
|
$itemUnitPriceOnPage = $this->showPage->getItemDiscountedUnitPrice($itemName); |
417
|
|
|
|
418
|
|
|
Assert::eq( |
419
|
|
|
$itemUnitPriceOnPage, |
420
|
|
|
$discountedUnitPrice, |
421
|
|
|
'Item discounted unit price is %s, but should be %s.' |
422
|
|
|
); |
423
|
|
|
} |
424
|
|
|
|
425
|
|
|
/** |
426
|
|
|
* @Then /^(its) quantity should be ([^"]+)$/ |
427
|
|
|
*/ |
428
|
|
|
public function itemQuantityShouldBe($itemName, $quantity) |
429
|
|
|
{ |
430
|
|
|
$itemQuantityOnPage = $this->showPage->getItemQuantity($itemName); |
431
|
|
|
|
432
|
|
|
Assert::eq( |
433
|
|
|
$itemQuantityOnPage, |
434
|
|
|
$quantity, |
435
|
|
|
'Item quantity is %s, but should be %s.' |
436
|
|
|
); |
437
|
|
|
} |
438
|
|
|
|
439
|
|
|
/** |
440
|
|
|
* @Then /^(its) subtotal should be ([^"]+)$/ |
441
|
|
|
*/ |
442
|
|
|
public function itemSubtotalShouldBe($itemName, $subtotal) |
443
|
|
|
{ |
444
|
|
|
$itemSubtotalOnPage = $this->showPage->getItemSubtotal($itemName); |
445
|
|
|
|
446
|
|
|
Assert::eq( |
447
|
|
|
$itemSubtotalOnPage, |
448
|
|
|
$subtotal, |
449
|
|
|
'Item subtotal is %s, but should be %s.' |
450
|
|
|
); |
451
|
|
|
} |
452
|
|
|
|
453
|
|
|
/** |
454
|
|
|
* @Then /^(its) discount should be ([^"]+)$/ |
455
|
|
|
* @Then the :itemName should have :discount discount |
456
|
|
|
*/ |
457
|
|
|
public function theItemShouldHaveDiscount($itemName, $discount) |
458
|
|
|
{ |
459
|
|
|
$itemDiscountOnPage = $this->showPage->getItemDiscount($itemName); |
460
|
|
|
|
461
|
|
|
Assert::eq( |
462
|
|
|
$itemDiscountOnPage, |
463
|
|
|
$discount, |
464
|
|
|
'Item discount is %s, but should be %s.' |
465
|
|
|
); |
466
|
|
|
} |
467
|
|
|
|
468
|
|
|
/** |
469
|
|
|
* @Then /^(its) tax should be ([^"]+)$/ |
470
|
|
|
*/ |
471
|
|
|
public function itemTaxShouldBe($itemName, $tax) |
472
|
|
|
{ |
473
|
|
|
$itemTaxOnPage = $this->showPage->getItemTax($itemName); |
474
|
|
|
|
475
|
|
|
Assert::eq( |
476
|
|
|
$itemTaxOnPage, |
477
|
|
|
$tax, |
478
|
|
|
'Item tax is %s, but should be %s.' |
479
|
|
|
); |
480
|
|
|
} |
481
|
|
|
|
482
|
|
|
/** |
483
|
|
|
* @Then /^(its) total should be ([^"]+)$/ |
484
|
|
|
*/ |
485
|
|
|
public function itemTotalShouldBe($itemName, $total) |
486
|
|
|
{ |
487
|
|
|
$itemTotalOnPage = $this->showPage->getItemTotal($itemName); |
488
|
|
|
|
489
|
|
|
Assert::eq( |
490
|
|
|
$itemTotalOnPage, |
491
|
|
|
$total, |
492
|
|
|
'Item total is %s, but should be %s.' |
493
|
|
|
); |
494
|
|
|
} |
495
|
|
|
|
496
|
|
|
/** |
497
|
|
|
* @Then I should be notified that the order's payment has been successfully completed |
498
|
|
|
*/ |
499
|
|
|
public function iShouldBeNotifiedThatTheOrderSPaymentHasBeenSuccessfullyCompleted() |
500
|
|
|
{ |
501
|
|
|
$this |
502
|
|
|
->notificationChecker |
503
|
|
|
->checkNotification('Payment has been successfully updated.', NotificationType::success()); |
504
|
|
|
} |
505
|
|
|
|
506
|
|
|
/** |
507
|
|
|
* @Then I should be notified that the order's payment has been successfully refunded |
508
|
|
|
*/ |
509
|
|
|
public function iShouldBeNotifiedThatTheOrderSPaymentHasBeenSuccessfullyRefunded() |
510
|
|
|
{ |
511
|
|
|
$this |
512
|
|
|
->notificationChecker |
513
|
|
|
->checkNotification('Payment has been successfully refunded.', NotificationType::success()); |
514
|
|
|
} |
515
|
|
|
|
516
|
|
|
/** |
517
|
|
|
* @Then it should have payment state :paymentState |
518
|
|
|
* @Then it should have payment with state :paymentState |
519
|
|
|
*/ |
520
|
|
|
public function itShouldHavePaymentState($paymentState) |
521
|
|
|
{ |
522
|
|
|
Assert::true( |
523
|
|
|
$this->showPage->hasPayment($paymentState), |
524
|
|
|
sprintf('It should have payment with %s state', $paymentState) |
525
|
|
|
); |
526
|
|
|
} |
527
|
|
|
|
528
|
|
|
/** |
529
|
|
|
* @Then it's payment state should be refunded |
530
|
|
|
*/ |
531
|
|
|
public function orderPaymentStateShouldBeRefunded() |
532
|
|
|
{ |
533
|
|
|
Assert::same( |
534
|
|
|
$this->showPage->getPaymentState(), |
535
|
|
|
'Refunded', |
536
|
|
|
'Order payment state should be refunded, but it is not.' |
537
|
|
|
); |
538
|
|
|
} |
539
|
|
|
|
540
|
|
|
/** |
541
|
|
|
* @Then /^I should not be able to mark (this order) as paid again$/ |
542
|
|
|
*/ |
543
|
|
|
public function iShouldNotBeAbleToFinalizeItsPayment(OrderInterface $order) |
544
|
|
|
{ |
545
|
|
|
Assert::false( |
546
|
|
|
$this->showPage->canCompleteOrderLastPayment($order), |
547
|
|
|
'It should not have complete payment button.' |
548
|
|
|
); |
549
|
|
|
} |
550
|
|
|
|
551
|
|
|
/** |
552
|
|
|
* @Then I should be notified that the order has been successfully shipped |
553
|
|
|
*/ |
554
|
|
|
public function iShouldBeNotifiedThatTheOrderHasBeenSuccessfullyShipped() |
555
|
|
|
{ |
556
|
|
|
$this->notificationChecker->checkNotification( |
557
|
|
|
'Shipment has been successfully updated.', |
558
|
|
|
NotificationType::success() |
559
|
|
|
); |
560
|
|
|
} |
561
|
|
|
|
562
|
|
|
/** |
563
|
|
|
* @Then /^I should not be able to ship (this order)$/ |
564
|
|
|
*/ |
565
|
|
|
public function iShouldNotBeAbleToShipThisOrder(OrderInterface $order) |
566
|
|
|
{ |
567
|
|
|
Assert::false( |
568
|
|
|
$this->showPage->canShipOrder($order), |
569
|
|
|
'It should not have ship shipment button.' |
570
|
|
|
); |
571
|
|
|
} |
572
|
|
|
|
573
|
|
|
/** |
574
|
|
|
* @When I cancel this order |
575
|
|
|
*/ |
576
|
|
|
public function iCancelThisOrder() |
577
|
|
|
{ |
578
|
|
|
$this->showPage->cancelOrder(); |
579
|
|
|
} |
580
|
|
|
|
581
|
|
|
/** |
582
|
|
|
* @Then I should be notified that it has been successfully updated |
583
|
|
|
*/ |
584
|
|
|
public function iShouldBeNotifiedAboutItHasBeenSuccessfullyCanceled() |
585
|
|
|
{ |
586
|
|
|
$this->notificationChecker->checkNotification( |
587
|
|
|
'Order has been successfully updated.', |
588
|
|
|
NotificationType::success() |
589
|
|
|
); |
590
|
|
|
} |
591
|
|
|
|
592
|
|
|
/** |
593
|
|
|
* @Then I should not be able to cancel this order |
594
|
|
|
*/ |
595
|
|
|
public function iShouldNotBeAbleToCancelThisOrder() |
596
|
|
|
{ |
597
|
|
|
Assert::false( |
598
|
|
|
$this->showPage->hasCancelButton(), |
599
|
|
|
'There should not be a cancel button, but it is.' |
600
|
|
|
); |
601
|
|
|
} |
602
|
|
|
|
603
|
|
|
/** |
604
|
|
|
* @Then this order should have state :state |
605
|
|
|
* @Then its state should be :state |
606
|
|
|
*/ |
607
|
|
|
public function itsStateShouldBe($state) |
608
|
|
|
{ |
609
|
|
|
Assert::same( |
610
|
|
|
$this->showPage->getOrderState(), |
611
|
|
|
$state, |
612
|
|
|
'The order state should be %2$s, but it is %s.' |
613
|
|
|
); |
614
|
|
|
} |
615
|
|
|
|
616
|
|
|
/** |
617
|
|
|
* @Then it should( still) have a :state state |
618
|
|
|
*/ |
619
|
|
|
public function itShouldHaveState($state) |
620
|
|
|
{ |
621
|
|
|
Assert::true( |
622
|
|
|
$this->indexPage->isSingleResourceOnPage(['state' => $state]), |
623
|
|
|
sprintf('Cannot find order with "%s" state in the list.', $state) |
624
|
|
|
); |
625
|
|
|
} |
626
|
|
|
|
627
|
|
|
/** |
628
|
|
|
* @Then /^(the administrator) should know about (this additional note) for (this order made by "[^"]+")$/ |
629
|
|
|
*/ |
630
|
|
|
public function theCustomerServiceShouldKnowAboutThisAdditionalNotes( |
631
|
|
|
AdminUserInterface $user, |
632
|
|
|
$note, |
633
|
|
|
OrderInterface $order |
634
|
|
|
) { |
635
|
|
|
$this->sharedSecurityService->performActionAsAdminUser( |
636
|
|
|
$user, |
637
|
|
|
function () use ($note, $order) { |
638
|
|
|
$this->showPage->open(['id' => $order->getId()]); |
639
|
|
|
Assert::true($this->showPage->hasNote($note), sprintf('I should see %s note, but I do not see', $note)); |
640
|
|
|
} |
641
|
|
|
); |
642
|
|
|
} |
643
|
|
|
|
644
|
|
|
/** |
645
|
|
|
* @Then I should see an order with :orderNumber number |
646
|
|
|
*/ |
647
|
|
|
public function iShouldSeeOrderWithNumber($orderNumber) |
648
|
|
|
{ |
649
|
|
|
Assert::true( |
650
|
|
|
$this->indexPage->isSingleResourceOnPage(['number' => $orderNumber]), |
651
|
|
|
sprintf('Cannot find order with "%s" number in the list.', $orderNumber) |
652
|
|
|
); |
653
|
|
|
} |
654
|
|
|
|
655
|
|
|
/** |
656
|
|
|
* @Then the first order should have number :number |
657
|
|
|
*/ |
658
|
|
|
public function theFirstOrderShouldHaveNumber($number) |
659
|
|
|
{ |
660
|
|
|
$actualNumber = $this->indexPage->getColumnFields('number')[0]; |
661
|
|
|
|
662
|
|
|
Assert::eq( |
663
|
|
|
$actualNumber, |
664
|
|
|
$number, |
665
|
|
|
sprintf('Expected first order\'s number to be %s, but it is %s.', $number, $actualNumber) |
666
|
|
|
); |
667
|
|
|
} |
668
|
|
|
|
669
|
|
|
/** |
670
|
|
|
* @Then it should have shipment in state :shipmentState |
671
|
|
|
*/ |
672
|
|
|
public function itShouldHaveShipmentState($shipmentState) |
673
|
|
|
{ |
674
|
|
|
Assert::true( |
675
|
|
|
$this->showPage->hasShipment($shipmentState), |
676
|
|
|
sprintf('It should have shipment with %s state', $shipmentState) |
677
|
|
|
); |
678
|
|
|
} |
679
|
|
|
|
680
|
|
|
/** |
681
|
|
|
* @Then order :orderNumber should have shipment state :shippingState |
682
|
|
|
*/ |
683
|
|
|
public function thisOrderShipmentStateShouldBe($shippingState) |
684
|
|
|
{ |
685
|
|
|
Assert::true( |
686
|
|
|
$this->indexPage->isSingleResourceOnPage(['shippingState' => $shippingState]), |
687
|
|
|
sprintf('Order should have %s shipping state', $shippingState) |
688
|
|
|
); |
689
|
|
|
} |
690
|
|
|
|
691
|
|
|
/** |
692
|
|
|
* @Then the order :order should have order payment state :orderPaymentState |
693
|
|
|
* @Then /^(this order) should have order payment state "([^"]+)"$/ |
694
|
|
|
* @Then /^(its) payment state should be "([^"]+)"$/ |
695
|
|
|
*/ |
696
|
|
|
public function theOrderShouldHavePaymentState(OrderInterface $order, $orderPaymentState) |
|
|
|
|
697
|
|
|
{ |
698
|
|
|
Assert::true( |
699
|
|
|
$this->indexPage->isSingleResourceOnPage(['paymentState' => $orderPaymentState]), |
700
|
|
|
sprintf('Cannot find order with "%s" order payment state in the list.', $orderPaymentState) |
701
|
|
|
); |
702
|
|
|
} |
703
|
|
|
|
704
|
|
|
/** |
705
|
|
|
* @Then the order :order should have order shipping state :orderShipmentState |
706
|
|
|
* @Then /^(this order) should have order shipping state "([^"]+)"$/ |
707
|
|
|
* @Then /^(its) shipping state should be "([^"]+)"$/ |
708
|
|
|
*/ |
709
|
|
|
public function theOrderShouldHaveShipmentState(OrderInterface $order, $orderShipmentState) |
|
|
|
|
710
|
|
|
{ |
711
|
|
|
Assert::true( |
712
|
|
|
$this->indexPage->isSingleResourceOnPage(['shippingState' => $orderShipmentState]), |
713
|
|
|
sprintf('Cannot find order with "%s" order shipping state on the list.', $orderShipmentState) |
714
|
|
|
); |
715
|
|
|
} |
716
|
|
|
|
717
|
|
|
/** |
718
|
|
|
* @Then /^there should be(?:| only) (\d+) payments?$/ |
719
|
|
|
*/ |
720
|
|
|
public function theOrderShouldHaveNumberOfPayments($number) |
721
|
|
|
{ |
722
|
|
|
$actualNumberOfPayments = $this->showPage->getPaymentsCount(); |
|
|
|
|
723
|
|
|
|
724
|
|
|
Assert::same((int)$number, $actualNumberOfPayments); |
725
|
|
|
} |
726
|
|
|
|
727
|
|
|
/** |
728
|
|
|
* @Then I should see the order :orderNumber with total :total |
729
|
|
|
*/ |
730
|
|
|
public function iShouldSeeTheOrderWithTotal($orderNumber, $total) |
731
|
|
|
{ |
732
|
|
|
Assert::true( |
733
|
|
|
$this->indexPage->isSingleResourceOnPage(['total' => $total]), |
734
|
|
|
sprintf('The total of order "%s" is not "%s".', $orderNumber, $total) |
735
|
|
|
); |
736
|
|
|
} |
737
|
|
|
|
738
|
|
|
/** |
739
|
|
|
* @When /^I want to modify a customer's (?:billing|shipping) address of (this order)$/ |
740
|
|
|
*/ |
741
|
|
|
public function iWantToModifyACustomerSShippingAddress(OrderInterface $order) |
742
|
|
|
{ |
743
|
|
|
$this->updatePage->open(['id' => $order->getId()]); |
744
|
|
|
} |
745
|
|
|
|
746
|
|
|
/** |
747
|
|
|
* @When I save my changes |
748
|
|
|
* @When I try to save my changes |
749
|
|
|
*/ |
750
|
|
|
public function iSaveMyChanges() |
751
|
|
|
{ |
752
|
|
|
$this->updatePage->saveChanges(); |
753
|
|
|
} |
754
|
|
|
|
755
|
|
|
/** |
756
|
|
|
* @When /^I specify their (?:|new )shipping (address as "([^"]+)", "([^"]+)", "([^"]+)", "([^"]+)" for "([^"]+)")$/ |
757
|
|
|
*/ |
758
|
|
|
public function iSpecifyTheirShippingAddressAsFor(AddressInterface $address) |
759
|
|
|
{ |
760
|
|
|
$this->updatePage->specifyShippingAddress($address); |
761
|
|
|
} |
762
|
|
|
|
763
|
|
|
/** |
764
|
|
|
* @When /^I specify their (?:|new )billing (address as "([^"]+)", "([^"]+)", "([^"]+)", "([^"]+)" for "([^"]+)")$/ |
765
|
|
|
*/ |
766
|
|
|
public function iSpecifyTheirBillingAddressAsFor(AddressInterface $address) |
767
|
|
|
{ |
768
|
|
|
$this->updatePage->specifyBillingAddress($address); |
769
|
|
|
} |
770
|
|
|
|
771
|
|
|
/** |
772
|
|
|
* @Then /^I should be notified that the "([^"]+)", the "([^"]+)", the "([^"]+)" and the "([^"]+)" in (shipping|billing) details are required$/ |
773
|
|
|
*/ |
774
|
|
|
public function iShouldBeNotifiedThatTheAndTheInShippingDetailsAreRequired($firstElement, $secondElement, $thirdElement, $fourthElement, $type) |
775
|
|
|
{ |
776
|
|
|
$this->assertElementValidationMessage($type, $firstElement, sprintf('Please enter %s.', $firstElement)); |
777
|
|
|
$this->assertElementValidationMessage($type, $secondElement, sprintf('Please enter %s.', $secondElement)); |
778
|
|
|
$this->assertElementValidationMessage($type, $thirdElement, sprintf('Please enter %s.', $thirdElement)); |
779
|
|
|
$this->assertElementValidationMessage($type, $fourthElement, sprintf('Please enter %s.', $fourthElement)); |
780
|
|
|
|
781
|
|
|
} |
782
|
|
|
|
783
|
|
|
/** |
784
|
|
|
* @Then I should see :provinceName as province in the shipping address |
785
|
|
|
*/ |
786
|
|
|
public function iShouldSeeAsProvinceInTheShippingAddress($provinceName) |
787
|
|
|
{ |
788
|
|
|
Assert::true( |
789
|
|
|
$this->showPage->hasShippingProvinceName($provinceName), |
790
|
|
|
sprintf('Cannot find shipping address with province %s', $provinceName) |
791
|
|
|
); |
792
|
|
|
} |
793
|
|
|
|
794
|
|
|
/** |
795
|
|
|
* @Then I should see :provinceName ad province in the billing address |
796
|
|
|
*/ |
797
|
|
|
public function iShouldSeeAdProvinceInTheBillingAddress($provinceName) |
798
|
|
|
{ |
799
|
|
|
Assert::true( |
800
|
|
|
$this->showPage->hasBillingProvinceName($provinceName), |
801
|
|
|
sprintf('Cannot find shipping address with province %s', $provinceName) |
802
|
|
|
); |
803
|
|
|
} |
804
|
|
|
|
805
|
|
|
/** |
806
|
|
|
* @Then /^(the administrator) should know about IP address of (this order made by "[^"]+")$/ |
807
|
|
|
*/ |
808
|
|
|
public function theAdministratorShouldKnowAboutIPAddressOfThisOrderMadeBy( |
809
|
|
|
AdminUserInterface $user, |
810
|
|
|
OrderInterface $order |
811
|
|
|
) { |
812
|
|
|
$this->sharedSecurityService->performActionAsAdminUser( |
813
|
|
|
$user, |
814
|
|
|
function () use ($order) { |
815
|
|
|
$this->showPage->open(['id' => $order->getId()]); |
816
|
|
|
|
817
|
|
|
Assert::notSame( |
818
|
|
|
$this->showPage->getIpAddressAssigned(), |
819
|
|
|
'', |
820
|
|
|
'There should be IP address assigned to order, but there is not.' |
821
|
|
|
); |
822
|
|
|
} |
823
|
|
|
); |
824
|
|
|
} |
825
|
|
|
|
826
|
|
|
/** |
827
|
|
|
* @When /^I (clear old billing address) information$/ |
828
|
|
|
*/ |
829
|
|
|
public function iSpecifyTheBillingAddressAs(AddressInterface $address) |
830
|
|
|
{ |
831
|
|
|
$this->updatePage->specifyBillingAddress($address); |
832
|
|
|
} |
833
|
|
|
|
834
|
|
|
/** |
835
|
|
|
* @When /^I (clear old shipping address) information$/ |
836
|
|
|
*/ |
837
|
|
|
public function iSpecifyTheShippingAddressAs(AddressInterface $address) |
838
|
|
|
{ |
839
|
|
|
$this->updatePage->specifyShippingAddress($address); |
840
|
|
|
} |
841
|
|
|
|
842
|
|
|
/** |
843
|
|
|
* @When /^I do not specify new information$/ |
844
|
|
|
*/ |
845
|
|
|
public function iDoNotSpecifyNewInformation() |
846
|
|
|
{ |
847
|
|
|
// Intentionally left blank to fulfill context expectation |
848
|
|
|
} |
849
|
|
|
|
850
|
|
|
/** |
851
|
|
|
* @param string $type |
852
|
|
|
* @param string $element |
853
|
|
|
* @param string $expectedMessage |
854
|
|
|
* |
855
|
|
|
* @throws \InvalidArgumentException |
856
|
|
|
*/ |
857
|
|
|
private function assertElementValidationMessage($type, $element, $expectedMessage) |
858
|
|
|
{ |
859
|
|
|
$element = sprintf('%s_%s', $type, implode('_', explode(' ', $element))); |
860
|
|
|
Assert::true( |
861
|
|
|
$this->updatePage->checkValidationMessageFor($element, $expectedMessage), |
862
|
|
|
sprintf('The %s should be required.', $element) |
863
|
|
|
); |
864
|
|
|
} |
865
|
|
|
} |
866
|
|
|
|
Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.