forked from Sylius/RefundPlugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRefundingContext.php
346 lines (308 loc) · 12.2 KB
/
RefundingContext.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
<?php
declare(strict_types=1);
namespace Tests\Sylius\RefundPlugin\Behat\Context\Ui;
use Behat\Behat\Context\Context;
use FriendsOfBehat\PageObjectExtension\Page\UnexpectedPageException;
use Sylius\Behat\NotificationType;
use Sylius\Behat\Service\NotificationCheckerInterface;
use Tests\Sylius\RefundPlugin\Behat\Page\Admin\OrderRefundsPageInterface;
use Webmozart\Assert\Assert;
final class RefundingContext implements Context
{
/** @var OrderRefundsPageInterface */
private $orderRefundsPage;
/** @var NotificationCheckerInterface */
private $notificationChecker;
public function __construct(
OrderRefundsPageInterface $orderRefundsPage,
NotificationCheckerInterface $notificationChecker
) {
$this->orderRefundsPage = $orderRefundsPage;
$this->notificationChecker = $notificationChecker;
}
/**
* @When I want to refund some units of order :orderNumber
*/
public function wantToRefundSomeUnitsOfOrder(string $orderNumber): void
{
$this->orderRefundsPage->open(['orderNumber' => $orderNumber]);
}
/**
* @When I try to refund some units of order :orderNumber
*/
public function tryToRefundSomeUnitsOfOrder(string $orderNumber): void
{
try {
$this->orderRefundsPage->open(['orderNumber' => $orderNumber]);
} catch (UnexpectedPageException $exception) {
}
}
/**
* @When /^I decide to refund (\d)st "([^"]+)" product with "([^"]+)" payment$/
* @When /^I decide to refund (\d)st "([^"]+)" product with ("[^"]+" payment) and "([^"]+)" comment$/
*/
public function decideToRefundProduct(
int $unitNumber,
string $productName,
string $paymentMethod,
string $comment = ''
): void {
$this->orderRefundsPage->pickUnitWithProductToRefund($productName, $unitNumber-1);
$this->orderRefundsPage->choosePaymentMethod($paymentMethod);
$this->orderRefundsPage->comment($comment);
$this->orderRefundsPage->refund();
}
/**
* @When /^I decide to refund (\d)st "([^"]+)" product with ("[^"]+" payment) and a very long comment$/
*/
public function decideToRefundProductWithVeryLongComment(
int $unitNumber,
string $productName,
string $paymentMethod
): void {
$this->orderRefundsPage->pickUnitWithProductToRefund($productName, $unitNumber-1);
$this->orderRefundsPage->choosePaymentMethod($paymentMethod);
$this->orderRefundsPage->comment($this->provideLongComment());
$this->orderRefundsPage->refund();
}
/**
* @When /^I decide to refund (\d+) "([^"]*)" products with "([^"]*)" payment$/
*/
public function iDecideToRefundProductsWithPayment(int $amount, string $productName, string $paymentMethodName): void
{
for ($number = 0; $number < $amount; $number++) {
$this->orderRefundsPage->pickUnitWithProductToRefund($productName, $number);
}
$this->orderRefundsPage->choosePaymentMethod($paymentMethodName);
$this->orderRefundsPage->refund();
}
/**
* @When /^I decide to refund (\d)st "([^"]+)" and (\d)st "([^"]+)" products with "([^"]+)" payment$/
*/
public function decideToRefundMultipleProduct(
int $firstUnitNumber,
string $firstProductName,
int $secondUnitNumber,
string $secondProductName,
string $paymentMethod,
string $comment = ''
): void {
$this->orderRefundsPage->pickUnitWithProductToRefund($firstProductName, $firstUnitNumber-1);
$this->orderRefundsPage->pickUnitWithProductToRefund($secondProductName, $secondUnitNumber-1);
$this->orderRefundsPage->choosePaymentMethod($paymentMethod);
$this->orderRefundsPage->comment($comment);
$this->orderRefundsPage->refund();
}
/**
* @Given /^I decide to refund ("[^"]+") from (\d)st "([^"]+)" product with "([^"]+)" payment$/
*/
public function decideToRefundPartFromProductWithPayment(
string $partialPrice,
int $unitNumber,
string $productName,
string $paymentMethod
): void {
$this->orderRefundsPage->pickPartOfUnitWithProductToRefund(
$productName,
$unitNumber-1,
sprintf("%f.2", $partialPrice / 100)
);
$this->orderRefundsPage->choosePaymentMethod($paymentMethod);
$this->orderRefundsPage->refund();
}
/**
* @When /^I decided to refund (\d)st "([^"]+)" product of the order "([^"]+)" with "([^"]+)" payment$/
*/
public function decidedToRefundProduct(
int $unitNumber,
string $productName,
string $orderNumber,
string $paymentMethod
): void {
$this->orderRefundsPage->open(['orderNumber' => $orderNumber]);
$this->orderRefundsPage->pickUnitWithProductToRefund($productName, $unitNumber-1);
$this->orderRefundsPage->choosePaymentMethod($paymentMethod);
$this->orderRefundsPage->refund();
}
/**
* @When I decide to refund all units of this order with :paymentMethod payment
*/
public function decideToRefundAllUnits(string $paymentMethod): void
{
$this->orderRefundsPage->pickAllUnitsToRefund();
$this->orderRefundsPage->choosePaymentMethod($paymentMethod);
$this->orderRefundsPage->refund();
}
/**
* @When /^I decide to refund order shipment with "([^"]+)" payment$/
*/
public function decideToRefundOrderShipment(string $paymentMethod): void
{
$this->orderRefundsPage->pickOrderShipment();
$this->orderRefundsPage->choosePaymentMethod($paymentMethod);
$this->orderRefundsPage->refund();
}
/**
* @When /^I decide to refund "\$([^"]+)" from order shipment with "([^"]+)" payment$/
* @When /^I try to refund ("[^"]+") from order shipment with "([^"]+)" payment$/
*/
public function decideToRefundPartOfOrderShipment(string $amount, string $paymentMethod): void
{
$this->orderRefundsPage->pickPartOfOrderShipmentToRefund($amount);
$this->orderRefundsPage->choosePaymentMethod($paymentMethod);
$this->orderRefundsPage->refund();
}
/**
* @When /^I decide to refund order shipment and (\d)st "([^"]+)" product with "([^"]+)" payment$/
*/
public function decideToRefundProductAndShipment(int $unitNumber, string $productName, string $paymentMethod): void
{
$this->orderRefundsPage->pickUnitWithProductToRefund($productName, $unitNumber-1);
$this->orderRefundsPage->pickOrderShipment();
$this->orderRefundsPage->choosePaymentMethod($paymentMethod);
$this->orderRefundsPage->refund();
}
/**
* @When I refund zero items
*/
public function refundZeroItems(): void
{
$this->orderRefundsPage->refund();
}
/**
* @Then I should be able to refund :count :productName products
*/
public function shouldBeAbleToRefundProducts(int $count, string $productName): void
{
Assert::same($count, $this->orderRefundsPage->countRefundableUnitsWithProduct($productName));
}
/**
* @Then I should be able to go back to order details
*/
public function shouldBeAbleToGoBackToOrderDetails(): void
{
Assert::true($this->orderRefundsPage->hasBackButton());
}
/**
* @Then I should be notified that selected order units have been successfully refunded
*/
public function shouldBeNotifiedThatSelectedOrderUnitsHaveBeenSuccessfullyRefunded(): void
{
$this->notificationChecker->checkNotification(
'Selected order units have been successfully refunded',
NotificationType::success()
);
}
/**
* @Then I should be notified that refunded amount should be greater than 0
*/
public function shouldBeNotifiedThatRefundedAmountShouldBeGreaterThan(): void
{
$this->notificationChecker->checkNotification(
'Refund amount must be greater than 0',
NotificationType::failure()
);
}
/**
* @Then I should be notified that I cannot refund more money than the order unit total
* @Then I should be notified that I cannot refund more money than the shipment total
*/
public function shouldBeNotifiedThatICannotRefundMoreMoneyThanTheRefundedUnitTotal(): void
{
$this->notificationChecker->checkNotification(
'You cannot refund more money than the refunded unit total',
NotificationType::failure()
);
}
/**
* @Then I should be notified that at least one unit should be selected to refund
*/
public function shouldBeNotifiedThatAtLeastOneUnitShouldBeSelectedToRefund(): void
{
$this->notificationChecker->checkNotification(
'At least one unit should be selected to refund',
NotificationType::failure()
);
}
/**
* @Then this order refunded total should (still) be :refundedTotal
*/
public function refundedTotalShouldBe(string $refundedTotal): void
{
Assert::same($this->orderRefundsPage->getRefundedTotal(), $refundedTotal);
}
/**
* @Then /^(\d+)st "([^"]+)" product should have "([^"]+)" refunded$/
*/
public function productShouldHaveSomeAmountRefunded(int $unitNumber, string $productName, string $amount): void
{
Assert::same($this->orderRefundsPage->getUnitWithProductRefundedTotal($unitNumber-1, $productName), $amount);
}
/**
* @Then /^I should not be able to refund (\d)(?:|st|nd|rd) unit with product "([^"]+)"$/
*/
public function shouldNotBeAbleToRefundUnitWithProduct(int $unitNumber, string $productName): void
{
Assert::false($this->orderRefundsPage->isUnitWithProductAvailableToRefund($productName, $unitNumber-1));
}
/**
* @Then I should still be able to refund order shipment with :paymentMethodName payment
*/
public function shouldStillBeAbleToRefundOrderShipment(): void
{
Assert::true($this->orderRefundsPage->isOrderShipmentAvailableToRefund());
}
/**
* @Then I should not be able to refund anything
*/
public function iShouldNotBeAbleToRefundAnything(): void
{
Assert::true($this->orderRefundsPage->eachRefundButtonIsDisabled());
}
/**
* @Then I should not be able to refund order shipment
*/
public function shouldNotBeAbleToRefundOrderShipment(): void
{
Assert::false($this->orderRefundsPage->isOrderShipmentAvailableToRefund());
}
/**
* @Then /^I should(?:| still) be able to refund (\d)(?:|st|nd|rd) unit with product "([^"]+)" with ("[^"]+" payment)$/
*/
public function shouldBeAbleToRefundUnitWithProduct(int $unitNumber, string $productName): void
{
Assert::true($this->orderRefundsPage->isUnitWithProductAvailableToRefund($productName, $unitNumber-1));
}
/**
* @Then I should be able to choose refund payment method
*/
public function shouldBeAbleToChooseRefundPaymentMethod(): void
{
Assert::true($this->orderRefundsPage->canChoosePaymentMethod());
}
/**
* @Then there should be :payment payment method
*/
public function thereShouldBePaymentMethod(string $payment): void
{
Assert::true($this->orderRefundsPage->isPaymentMethodVisible($payment));
}
/**
* @Then there should not be :payment payment method
*/
public function thereShouldNotBePaymentMethod(string $payment): void
{
Assert::false($this->orderRefundsPage->isPaymentMethodVisible($payment));
}
/**
* @Then the selected refund payment method should be :paymentMethod
*/
public function theSelectedRefundPaymentMethodShouldBe(string $paymentMethod): void
{
Assert::true($this->orderRefundsPage->isPaymentMethodSelected($paymentMethod));
}
private function provideLongComment(): string
{
return 'Tu ne quaesieris scire nefas, quem mihi quem tibi finem di dederint, Leuconoe, nec Babylonios temptaris numeros. Ut melius quidquid erit pati. Seu plures hiemes sue tribuit Iuppiter ultimam. Qae nunc oppositis debilitat pumicibus mare Tyrrenum: sapias vina liques et spatio brevi. Spem longam resecens. Dum loquimur fugerit invida Aetas: CARPE DIEM, quam minimum credula postero.';
}
}