|
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 Behat\Behat\Tester\Exception\PendingException; |
|
16
|
|
|
use Sylius\Behat\Page\Admin\Crud\IndexPageInterface; |
|
17
|
|
|
use Sylius\Behat\Page\Admin\Order\ShowPageInterface; |
|
18
|
|
|
use Sylius\Component\Core\Model\CustomerInterface; |
|
19
|
|
|
use Sylius\Component\Core\Model\OrderInterface; |
|
20
|
|
|
use Sylius\Component\Core\Test\Services\SharedStorageInterface; |
|
21
|
|
|
use Webmozart\Assert\Assert; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @author Paweł Jędrzejewski <[email protected]> |
|
25
|
|
|
* @author Grzegorz Sadowski <[email protected]> |
|
26
|
|
|
*/ |
|
27
|
|
|
final class ManagingOrdersContext implements Context |
|
28
|
|
|
{ |
|
29
|
|
|
/** |
|
30
|
|
|
* @var SharedStorageInterface |
|
31
|
|
|
*/ |
|
32
|
|
|
private $sharedStorage; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @var IndexPageInterface |
|
36
|
|
|
*/ |
|
37
|
|
|
private $indexPage; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @var ShowPageInterface |
|
41
|
|
|
*/ |
|
42
|
|
|
private $showPage; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @param SharedStorageInterface $sharedStorage |
|
46
|
|
|
* @param IndexPageInterface $indexPage |
|
47
|
|
|
* @param ShowPageInterface $showPage |
|
48
|
|
|
*/ |
|
49
|
|
|
public function __construct( |
|
50
|
|
|
SharedStorageInterface $sharedStorage, |
|
51
|
|
|
IndexPageInterface $indexPage, |
|
52
|
|
|
ShowPageInterface $showPage |
|
53
|
|
|
) { |
|
54
|
|
|
$this->sharedStorage = $sharedStorage; |
|
55
|
|
|
$this->indexPage = $indexPage; |
|
56
|
|
|
$this->showPage = $showPage; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* @When I browse orders |
|
61
|
|
|
*/ |
|
62
|
|
|
public function iBrowseOrders() |
|
63
|
|
|
{ |
|
64
|
|
|
$this->indexPage->open(); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* @When I view the summary of the order :order |
|
69
|
|
|
*/ |
|
70
|
|
|
public function iSeeTheOrder(OrderInterface $order) |
|
71
|
|
|
{ |
|
72
|
|
|
$this->showPage->open(['id' => $order->getId()]); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* @Then I should see a single order from customer :customer |
|
77
|
|
|
*/ |
|
78
|
|
|
public function iShouldSeeASingleOrderFromCustomer(CustomerInterface $customer) |
|
79
|
|
|
{ |
|
80
|
|
|
Assert::true( |
|
81
|
|
|
$this->indexPage->isSingleResourceOnPage(['customer' => $customer->getEmail()]), |
|
82
|
|
|
sprintf('Cannot find order for customer "%s" in the list.', $customer->getEmail()) |
|
83
|
|
|
); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* @Then it should have been placed by the customer :customerEmail |
|
88
|
|
|
*/ |
|
89
|
|
|
public function itShouldBePlacedByCustomer($customerEmail) |
|
90
|
|
|
{ |
|
91
|
|
|
Assert::true( |
|
92
|
|
|
$this->showPage->hasCustomer($customerEmail), |
|
93
|
|
|
sprintf('Cannot find customer "%s".', $customerEmail) |
|
94
|
|
|
); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* @Then it should be shipped to :customerName, :street, :postcode, :city, :countryName |
|
99
|
|
|
*/ |
|
100
|
|
|
public function itShouldBeShippedTo($customerName, $street, $postcode, $city, $countryName) |
|
101
|
|
|
{ |
|
102
|
|
|
Assert::true( |
|
103
|
|
|
$this->showPage->hasShippingAddress($customerName, $street, $postcode, $city, $countryName), |
|
104
|
|
|
sprintf('Cannot find shipping address "%s, %s %s, %s".', $street, $postcode, $city, $countryName) |
|
105
|
|
|
); |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* @Then it should be billed to :customerName, :street, :postcode, :city, :countryName |
|
110
|
|
|
*/ |
|
111
|
|
|
public function itShouldBeBilledTo($customerName, $street, $postcode, $city, $countryName) |
|
112
|
|
|
{ |
|
113
|
|
|
Assert::true( |
|
114
|
|
|
$this->showPage->hasBillingAddress($customerName, $street, $postcode, $city, $countryName), |
|
115
|
|
|
sprintf('Cannot find shipping address "%s, %s %s, %s".', $street, $postcode, $city, $countryName) |
|
116
|
|
|
); |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
/** |
|
120
|
|
|
* @Then it should be shipped via the :shippingMethodName shipping method |
|
121
|
|
|
*/ |
|
122
|
|
|
public function itShouldBeShippedViaShippingMethod($shippingMethodName) |
|
123
|
|
|
{ |
|
124
|
|
|
Assert::true( |
|
125
|
|
|
$this->showPage->hasShipment($shippingMethodName), |
|
126
|
|
|
sprintf('Cannot find shipment "%s".', $shippingMethodName) |
|
127
|
|
|
); |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
/** |
|
131
|
|
|
* @Then it should be paid with :paymentMethodName |
|
132
|
|
|
*/ |
|
133
|
|
|
public function itShouldBePaidWith($paymentMethodName) |
|
134
|
|
|
{ |
|
135
|
|
|
Assert::true( |
|
136
|
|
|
$this->showPage->hasPayment($paymentMethodName), |
|
137
|
|
|
sprintf('Cannot find payment "%s".', $paymentMethodName) |
|
138
|
|
|
); |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
/** |
|
142
|
|
|
* @Then /^it should have (\d+) items$/ |
|
143
|
|
|
*/ |
|
144
|
|
|
public function itShouldHaveAmountOfItems($amount) |
|
145
|
|
|
{ |
|
146
|
|
|
$itemsCount = $this->showPage->countItems(); |
|
147
|
|
|
|
|
148
|
|
|
Assert::eq( |
|
149
|
|
|
$amount, |
|
150
|
|
|
$itemsCount, |
|
151
|
|
|
sprintf('There should be %d items, but get %d.', $amount, $itemsCount) |
|
152
|
|
|
); |
|
153
|
|
|
} |
|
154
|
|
|
|
|
155
|
|
|
/** |
|
156
|
|
|
* @Then the product named :productName should be in the items list |
|
157
|
|
|
*/ |
|
158
|
|
|
public function theProductShouldBeInTheItemsList($productName) |
|
159
|
|
|
{ |
|
160
|
|
|
Assert::true( |
|
161
|
|
|
$this->showPage->isProductInTheList($productName), |
|
162
|
|
|
sprintf('Product %s is not in the item list.', $productName) |
|
163
|
|
|
); |
|
164
|
|
|
} |
|
165
|
|
|
|
|
166
|
|
|
/** |
|
167
|
|
|
* @Then the order's items total should be :itemsTotal |
|
168
|
|
|
*/ |
|
169
|
|
|
public function theOrdersItemsTotalShouldBe($itemsTotal) |
|
170
|
|
|
{ |
|
171
|
|
|
$itemsTotalOnPage = $this->showPage->getItemsTotal(); |
|
172
|
|
|
|
|
173
|
|
|
Assert::eq( |
|
174
|
|
|
$itemsTotalOnPage, |
|
175
|
|
|
$itemsTotal, |
|
176
|
|
|
'Items total is %s, but should be %s.' |
|
177
|
|
|
); |
|
178
|
|
|
} |
|
179
|
|
|
|
|
180
|
|
|
/** |
|
181
|
|
|
* @Then the order's total should be :total |
|
182
|
|
|
*/ |
|
183
|
|
|
public function theOrdersTotalShouldBe($total) |
|
184
|
|
|
{ |
|
185
|
|
|
$totalOnPage = $this->showPage->getTotal(); |
|
186
|
|
|
|
|
187
|
|
|
Assert::eq( |
|
188
|
|
|
$totalOnPage, |
|
189
|
|
|
$total, |
|
190
|
|
|
'Total is %s, but should be %s.' |
|
191
|
|
|
); |
|
192
|
|
|
} |
|
193
|
|
|
|
|
194
|
|
|
/** |
|
195
|
|
|
* @Then there should be a shipping charge :shippingCharge |
|
196
|
|
|
*/ |
|
197
|
|
|
public function theOrdersShippingChargesShouldBe($shippingCharge) |
|
198
|
|
|
{ |
|
199
|
|
|
Assert::true( |
|
200
|
|
|
$this->showPage->hasShippingCharge($shippingCharge), |
|
201
|
|
|
sprintf('Shipping charges is not "%s".', $shippingCharge) |
|
202
|
|
|
); |
|
203
|
|
|
} |
|
204
|
|
|
|
|
205
|
|
|
/** |
|
206
|
|
|
* @Then the order's shipping total should be :shippingTotal |
|
207
|
|
|
*/ |
|
208
|
|
|
public function theOrdersShippingTotalShouldBe($shippingTotal) |
|
209
|
|
|
{ |
|
210
|
|
|
$shippingTotalOnPage = $this->showPage->getShippingTotal(); |
|
211
|
|
|
|
|
212
|
|
|
Assert::eq( |
|
213
|
|
|
$shippingTotal, |
|
214
|
|
|
$shippingTotalOnPage, |
|
215
|
|
|
sprintf('Shipping total is "%s", but should be "%s".', $shippingTotalOnPage, $shippingTotal) |
|
216
|
|
|
); |
|
217
|
|
|
} |
|
218
|
|
|
|
|
219
|
|
|
/** |
|
220
|
|
|
* @Then the order's tax total should be :taxTotal |
|
221
|
|
|
*/ |
|
222
|
|
|
public function theOrdersTaxTotalShouldBe($taxTotal) |
|
223
|
|
|
{ |
|
224
|
|
|
$taxTotalOnPage = $this->showPage->getTaxTotal(); |
|
225
|
|
|
|
|
226
|
|
|
Assert::eq( |
|
227
|
|
|
$taxTotal, |
|
228
|
|
|
$taxTotalOnPage, |
|
229
|
|
|
sprintf('Tax total is "%s", but should be "%s".', $taxTotalOnPage, $taxTotal) |
|
230
|
|
|
); |
|
231
|
|
|
} |
|
232
|
|
|
|
|
233
|
|
|
/** |
|
234
|
|
|
* @Then the order's promotion discount should be :promotionDiscount |
|
235
|
|
|
*/ |
|
236
|
|
|
public function theOrdersPromotionDiscountShouldBe($promotionDiscount) |
|
237
|
|
|
{ |
|
238
|
|
|
Assert::true( |
|
239
|
|
|
$this->showPage->hasPromotionDiscount($promotionDiscount), |
|
240
|
|
|
sprintf('Promotion discount is not "%s".', $promotionDiscount) |
|
241
|
|
|
); |
|
242
|
|
|
} |
|
243
|
|
|
|
|
244
|
|
|
/** |
|
245
|
|
|
* @Then the order's promotion total should be :promotionTotal |
|
246
|
|
|
*/ |
|
247
|
|
|
public function theOrdersPromotionTotalShouldBe($promotionTotal) |
|
248
|
|
|
{ |
|
249
|
|
|
$promotionTotalOnPage = $this->showPage->getPromotionTotal(); |
|
250
|
|
|
|
|
251
|
|
|
Assert::eq( |
|
252
|
|
|
$promotionTotalOnPage, |
|
253
|
|
|
$promotionTotal, |
|
254
|
|
|
'Promotion total is %s, but should be %s.' |
|
255
|
|
|
); |
|
256
|
|
|
} |
|
257
|
|
|
|
|
258
|
|
|
/** |
|
259
|
|
|
* @Then the :itemName should have :discount discount |
|
260
|
|
|
*/ |
|
261
|
|
|
public function theItemShouldHaveDiscount($itemName, $itemDiscount) |
|
262
|
|
|
{ |
|
263
|
|
|
$itemDiscountOnPage = $this->showPage->getItemDiscount($itemName); |
|
264
|
|
|
|
|
265
|
|
|
Assert::eq( |
|
266
|
|
|
$itemDiscountOnPage, |
|
267
|
|
|
$itemDiscount, |
|
268
|
|
|
'Item discount is %s, but should be %s.' |
|
269
|
|
|
); |
|
270
|
|
|
} |
|
271
|
|
|
|
|
272
|
|
|
/** |
|
273
|
|
|
* @When I delete the order :order |
|
274
|
|
|
*/ |
|
275
|
|
|
public function iDeleteOrder(OrderInterface $order) |
|
276
|
|
|
{ |
|
277
|
|
|
$this->sharedStorage->set('order', $order); |
|
278
|
|
|
|
|
279
|
|
|
$this->indexPage->open(); |
|
280
|
|
|
$this->indexPage->deleteResourceOnPage(['number' => $order->getNumber()]); |
|
281
|
|
|
} |
|
282
|
|
|
|
|
283
|
|
|
/** |
|
284
|
|
|
* @Then /^(this order) should not exist in the registry$/ |
|
285
|
|
|
*/ |
|
286
|
|
|
public function orderShouldNotExistInTheRegistry(OrderInterface $order) |
|
287
|
|
|
{ |
|
288
|
|
|
$this->indexPage->open(); |
|
289
|
|
|
|
|
290
|
|
|
Assert::false( |
|
291
|
|
|
$this->indexPage->isSingleResourceOnPage(['number' => $order->getNumber()]), |
|
292
|
|
|
sprintf('Order with number %s exists but should not.', $order->getNumber()) |
|
293
|
|
|
); |
|
294
|
|
|
} |
|
295
|
|
|
} |
|
296
|
|
|
|