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\PaymentMethod\CreatePageInterface; |
18
|
|
|
use Sylius\Behat\Page\Admin\PaymentMethod\UpdatePageInterface; |
19
|
|
|
use Sylius\Behat\Service\NotificationCheckerInterface; |
20
|
|
|
use Sylius\Behat\Service\Resolver\CurrentPageResolverInterface; |
21
|
|
|
use Sylius\Component\Payment\Model\PaymentMethodInterface; |
22
|
|
|
use Webmozart\Assert\Assert; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @author Arkadiusz Krakowiak <[email protected]> |
26
|
|
|
* @author Grzegorz Sadowski <[email protected]> |
27
|
|
|
*/ |
28
|
|
|
final class ManagingPaymentMethodsContext implements Context |
29
|
|
|
{ |
30
|
|
|
/** |
31
|
|
|
* @var CreatePageInterface |
32
|
|
|
*/ |
33
|
|
|
private $createPage; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var IndexPageInterface |
37
|
|
|
*/ |
38
|
|
|
private $indexPage; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @var UpdatePageInterface |
42
|
|
|
*/ |
43
|
|
|
private $updatePage; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @var CurrentPageResolverInterface |
47
|
|
|
*/ |
48
|
|
|
private $currentPageResolver; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @var NotificationCheckerInterface |
52
|
|
|
*/ |
53
|
|
|
private $notificationChecker; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @param CreatePageInterface $createPage |
57
|
|
|
* @param IndexPageInterface $indexPage |
58
|
|
|
* @param UpdatePageInterface $updatePage |
59
|
|
|
* @param CurrentPageResolverInterface $currentPageResolver |
60
|
|
|
*/ |
61
|
|
|
public function __construct( |
62
|
|
|
CreatePageInterface $createPage, |
63
|
|
|
IndexPageInterface $indexPage, |
64
|
|
|
UpdatePageInterface $updatePage, |
65
|
|
|
CurrentPageResolverInterface $currentPageResolver, |
66
|
|
|
NotificationCheckerInterface $notificationChecker |
67
|
|
|
) { |
68
|
|
|
$this->createPage = $createPage; |
69
|
|
|
$this->indexPage = $indexPage; |
70
|
|
|
$this->updatePage = $updatePage; |
71
|
|
|
$this->currentPageResolver = $currentPageResolver; |
72
|
|
|
$this->notificationChecker = $notificationChecker; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @Given I want to modify the :paymentMethod payment method |
77
|
|
|
*/ |
78
|
|
|
public function iWantToModifyAPaymentMethod(PaymentMethodInterface $paymentMethod) |
79
|
|
|
{ |
80
|
|
|
$this->updatePage->open(['id' => $paymentMethod->getId()]); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @When I name it :name in :language |
85
|
|
|
* @When I rename it to :name in :language |
86
|
|
|
* @When I remove its name from :language translation |
87
|
|
|
*/ |
88
|
|
|
public function iNameItIn($name = null, $language) |
89
|
|
|
{ |
90
|
|
|
$currentPage = $this->currentPageResolver->getCurrentPageWithForm([$this->createPage, $this->updatePage]); |
91
|
|
|
|
92
|
|
|
$currentPage->nameIt($name, $language); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @When I do not name it |
97
|
|
|
*/ |
98
|
|
|
public function iDoNotNameIt() |
99
|
|
|
{ |
100
|
|
|
// Intentionally left blank to fulfill context expectation |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* @When I enable it |
105
|
|
|
*/ |
106
|
|
|
public function iEnableIt() |
107
|
|
|
{ |
108
|
|
|
$this->updatePage->enable(); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @When I disable it |
113
|
|
|
*/ |
114
|
|
|
public function iDisableIt() |
115
|
|
|
{ |
116
|
|
|
$this->updatePage->disable(); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* @When I save my changes |
121
|
|
|
* @When I try to save my changes |
122
|
|
|
*/ |
123
|
|
|
public function iSaveMyChanges() |
124
|
|
|
{ |
125
|
|
|
$this->updatePage->saveChanges(); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* @When I delete the :paymentMethod payment method |
130
|
|
|
* @When I try to delete the :paymentMethod payment method |
131
|
|
|
*/ |
132
|
|
|
public function iDeletePaymentMethod(PaymentMethodInterface $paymentMethod) |
133
|
|
|
{ |
134
|
|
|
$this->indexPage->open(); |
135
|
|
|
$this->indexPage->deleteResourceOnPage(['code' => $paymentMethod->getCode(), 'name' => $paymentMethod->getName()]); |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* @Then I should be notified that it is in use |
140
|
|
|
*/ |
141
|
|
|
public function iShouldBeNotifiedThatItIsInUse() |
142
|
|
|
{ |
143
|
|
|
$this->notificationChecker->checkNotification('Cannot delete, the payment method is in use.', NotificationType::failure()); |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* @When I choose :gatewayName gateway |
148
|
|
|
*/ |
149
|
|
|
public function iChooseGateway($gatewayName) |
150
|
|
|
{ |
151
|
|
|
$currentPage = $this->currentPageResolver->getCurrentPageWithForm([$this->createPage, $this->updatePage]); |
152
|
|
|
|
153
|
|
|
$currentPage->chooseGateway($gatewayName); |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
/** |
157
|
|
|
* @Then this payment method :element should be :value |
158
|
|
|
*/ |
159
|
|
|
public function thisPaymentMethodElementShouldBe($element, $value) |
160
|
|
|
{ |
161
|
|
|
Assert::true( |
162
|
|
|
$this->updatePage->hasResourceValues([$element => $value]), |
163
|
|
|
sprintf('Payment method %s should be %s', $element, $value) |
164
|
|
|
); |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* @Given I want to create a new payment method |
169
|
|
|
*/ |
170
|
|
|
public function iWantToCreateANewPaymentMethod() |
171
|
|
|
{ |
172
|
|
|
$this->createPage->open(); |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
/** |
176
|
|
|
* @When I specify its code as :code |
177
|
|
|
* @When I do not specify its code |
178
|
|
|
*/ |
179
|
|
|
public function iSpecifyItsCodeAs($code = null) |
180
|
|
|
{ |
181
|
|
|
$this->createPage->specifyCode($code); |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
/** |
185
|
|
|
* @When I describe it as :description in :language |
186
|
|
|
*/ |
187
|
|
|
public function iDescribeItAsIn($description, $language) |
188
|
|
|
{ |
189
|
|
|
$this->createPage->describeIt($description, $language); |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
/** |
193
|
|
|
* @When make it available in channel :channel |
194
|
|
|
*/ |
195
|
|
|
public function iMakeItAvailableInChannel($channel) |
196
|
|
|
{ |
197
|
|
|
$this->createPage->checkChannel($channel); |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
/** |
201
|
|
|
* @Given I set its instruction as :instructions in :language |
202
|
|
|
*/ |
203
|
|
|
public function iSetItsInstructionAsIn($instructions, $language) |
204
|
|
|
{ |
205
|
|
|
$this->createPage->setInstructions($instructions, $language); |
206
|
|
|
} |
207
|
|
|
|
208
|
|
|
/** |
209
|
|
|
* @When I add it |
210
|
|
|
* @When I try to add it |
211
|
|
|
*/ |
212
|
|
|
public function iAddIt() |
213
|
|
|
{ |
214
|
|
|
$this->createPage->create(); |
215
|
|
|
} |
216
|
|
|
|
217
|
|
|
/** |
218
|
|
|
* @Then the payment method :paymentMethodName should appear in the registry |
219
|
|
|
* @Then the payment method :paymentMethodName should be in the registry |
220
|
|
|
*/ |
221
|
|
|
public function thePaymentMethodShouldAppearInTheRegistry($paymentMethodName) |
222
|
|
|
{ |
223
|
|
|
$this->indexPage->open(); |
224
|
|
|
|
225
|
|
|
Assert::true( |
226
|
|
|
$this->indexPage->isSingleResourceOnPage(['name' => $paymentMethodName]), |
227
|
|
|
sprintf('Payment method with name %s has not been found.', $paymentMethodName) |
228
|
|
|
); |
229
|
|
|
} |
230
|
|
|
|
231
|
|
|
/** |
232
|
|
|
* @Given /^(this payment method) should still be in the registry$/ |
233
|
|
|
*/ |
234
|
|
|
public function thisPaymentMethodShouldStillBeInTheRegistry(PaymentMethodInterface $paymentMethod) |
235
|
|
|
{ |
236
|
|
|
$this->thePaymentMethodShouldAppearInTheRegistry($paymentMethod->getName()); |
237
|
|
|
} |
238
|
|
|
|
239
|
|
|
/** |
240
|
|
|
* @Given I am browsing payment methods |
241
|
|
|
* @When I browse payment methods |
242
|
|
|
*/ |
243
|
|
|
public function iBrowsePaymentMethods() |
244
|
|
|
{ |
245
|
|
|
$this->indexPage->open(); |
246
|
|
|
} |
247
|
|
|
|
248
|
|
|
/** |
249
|
|
|
* @Then the first payment method on the list should have :field :value |
250
|
|
|
*/ |
251
|
|
|
public function theFirstPaymentMethodOnTheListShouldHave($field, $value) |
252
|
|
|
{ |
253
|
|
|
$actualValue = $this->indexPage->getColumnFields($field)[0]; |
254
|
|
|
|
255
|
|
|
Assert::same( |
256
|
|
|
$actualValue, |
257
|
|
|
$value, |
258
|
|
|
sprintf('Expected first payment method\'s %s to be "%s", but it is "%s".', $field, $value, $actualValue) |
259
|
|
|
); |
260
|
|
|
} |
261
|
|
|
|
262
|
|
|
/** |
263
|
|
|
* @Then the last payment method on the list should have :field :value |
264
|
|
|
*/ |
265
|
|
|
public function theLastPaymentMethodOnTheListShouldHave($field, $value) |
266
|
|
|
{ |
267
|
|
|
$fields = $this->indexPage->getColumnFields($field); |
268
|
|
|
$actualValue = end($fields); |
269
|
|
|
|
270
|
|
|
Assert::same( |
271
|
|
|
$actualValue, |
272
|
|
|
$value, |
273
|
|
|
sprintf('Expected last payment method\'s %s to be "%s", but it is "%s".', $field, $value, $actualValue) |
274
|
|
|
); |
275
|
|
|
} |
276
|
|
|
|
277
|
|
|
/** |
278
|
|
|
* @When I switch the way payment methods are sorted by :field |
279
|
|
|
* @When I start sorting payment methods by :field |
280
|
|
|
* @Given the payment methods are already sorted by :field |
281
|
|
|
*/ |
282
|
|
|
public function iSortPaymentMethodsBy($field) |
283
|
|
|
{ |
284
|
|
|
$this->indexPage->sortBy($field); |
285
|
|
|
} |
286
|
|
|
|
287
|
|
|
/** |
288
|
|
|
* @Then I should see :amount payment methods in the list |
289
|
|
|
*/ |
290
|
|
|
public function iShouldSeePaymentMethodsInTheList($amount) |
291
|
|
|
{ |
292
|
|
|
$foundRows = $this->indexPage->countItems(); |
293
|
|
|
|
294
|
|
|
Assert::same( |
295
|
|
|
(int) $amount, |
296
|
|
|
$foundRows, |
297
|
|
|
'%2$s rows with payment methods should appear on page, %s rows has been found' |
298
|
|
|
); |
299
|
|
|
} |
300
|
|
|
|
301
|
|
|
/** |
302
|
|
|
* @Then I should be notified that :element is required |
303
|
|
|
*/ |
304
|
|
|
public function iShouldBeNotifiedThatIsRequired($element) |
305
|
|
|
{ |
306
|
|
|
$this->assertFieldValidationMessage($element, sprintf('Please enter payment method %s.', $element)); |
307
|
|
|
} |
308
|
|
|
|
309
|
|
|
/** |
310
|
|
|
* @Then the payment method with :element :value should not be added |
311
|
|
|
*/ |
312
|
|
|
public function thePaymentMethodWithElementValueShouldNotBeAdded($element, $value) |
313
|
|
|
{ |
314
|
|
|
$this->iBrowsePaymentMethods(); |
315
|
|
|
|
316
|
|
|
Assert::false( |
317
|
|
|
$this->indexPage->isSingleResourceOnPage([$element => $value]), |
318
|
|
|
sprintf('Payment method with %s %s was created, but it should not.', $element, $value) |
319
|
|
|
); |
320
|
|
|
} |
321
|
|
|
|
322
|
|
|
/** |
323
|
|
|
* @Then /^(this payment method) should still be named "([^"]+)"$/ |
324
|
|
|
*/ |
325
|
|
|
public function thisShippingMethodNameShouldBe(PaymentMethodInterface $paymentMethod, $paymentMethodName) |
326
|
|
|
{ |
327
|
|
|
$this->iBrowsePaymentMethods(); |
328
|
|
|
|
329
|
|
|
Assert::true( |
330
|
|
|
$this->indexPage->isSingleResourceOnPage([ |
331
|
|
|
'code' => $paymentMethod->getCode(), |
332
|
|
|
'name' => $paymentMethodName, |
333
|
|
|
]), |
334
|
|
|
sprintf('Payment method name %s has not been assigned properly.', $paymentMethodName) |
335
|
|
|
); |
336
|
|
|
} |
337
|
|
|
|
338
|
|
|
/** |
339
|
|
|
* @param string $element |
340
|
|
|
* @param string $expectedMessage |
341
|
|
|
*/ |
342
|
|
|
private function assertFieldValidationMessage($element, $expectedMessage) |
343
|
|
|
{ |
344
|
|
|
/** @var CreatePageInterface|UpdatePageInterface $currentPage */ |
345
|
|
|
$currentPage = $this->currentPageResolver->getCurrentPageWithForm([$this->createPage, $this->updatePage]); |
346
|
|
|
|
347
|
|
|
Assert::same($currentPage->getValidationMessage($element), $expectedMessage); |
348
|
|
|
} |
349
|
|
|
|
350
|
|
|
/** |
351
|
|
|
* @Then the code field should be disabled |
352
|
|
|
*/ |
353
|
|
|
public function theCodeFieldShouldBeDisabled() |
354
|
|
|
{ |
355
|
|
|
Assert::true( |
356
|
|
|
$this->updatePage->isCodeDisabled(), |
357
|
|
|
'Code field should be disabled' |
358
|
|
|
); |
359
|
|
|
} |
360
|
|
|
|
361
|
|
|
/** |
362
|
|
|
* @Then this payment method should be enabled |
363
|
|
|
*/ |
364
|
|
|
public function thisPaymentMethodShouldBeEnabled() |
365
|
|
|
{ |
366
|
|
|
Assert::true( |
367
|
|
|
$this->updatePage->isPaymentMethodEnabled(), |
368
|
|
|
'Payment method should be enabled' |
369
|
|
|
); |
370
|
|
|
} |
371
|
|
|
|
372
|
|
|
/** |
373
|
|
|
* @Then this payment method should be disabled |
374
|
|
|
*/ |
375
|
|
|
public function thisPaymentMethodShouldBeDisabled() |
376
|
|
|
{ |
377
|
|
|
Assert::false( |
378
|
|
|
$this->updatePage->isPaymentMethodEnabled(), |
379
|
|
|
'Payment method should be disabled' |
380
|
|
|
); |
381
|
|
|
} |
382
|
|
|
|
383
|
|
|
/** |
384
|
|
|
* @Given the payment method :paymentMethod should have instructions :instructions in :language |
385
|
|
|
*/ |
386
|
|
|
public function thePaymentMethodShouldHaveInstructionsIn( |
387
|
|
|
PaymentMethodInterface $paymentMethod, |
388
|
|
|
$instructions, |
389
|
|
|
$language |
390
|
|
|
) { |
391
|
|
|
$this->iWantToModifyAPaymentMethod($paymentMethod); |
392
|
|
|
|
393
|
|
|
Assert::same( |
394
|
|
|
$this->updatePage->getPaymentMethodInstructions($language), |
395
|
|
|
$instructions |
396
|
|
|
); |
397
|
|
|
} |
398
|
|
|
|
399
|
|
|
/** |
400
|
|
|
* @Then the payment method :paymentMethod should be available in channel :channelName |
401
|
|
|
*/ |
402
|
|
|
public function thePaymentMethodShouldBeAvailableInChannel( |
403
|
|
|
PaymentMethodInterface $paymentMethod, |
404
|
|
|
$channelName |
405
|
|
|
) { |
406
|
|
|
$this->iWantToModifyAPaymentMethod($paymentMethod); |
407
|
|
|
|
408
|
|
|
Assert::true( |
409
|
|
|
$this->updatePage->isAvailableInChannel($channelName), |
410
|
|
|
sprintf('Payment method should be available in channel "%s" but it does not.', $channelName) |
411
|
|
|
); |
412
|
|
|
} |
413
|
|
|
|
414
|
|
|
/** |
415
|
|
|
* @Then /^(this payment method) should no longer exist in the registry$/ |
416
|
|
|
*/ |
417
|
|
|
public function thisPaymentMethodShouldNoLongerExistInTheRegistry(PaymentMethodInterface $paymentMethod) |
418
|
|
|
{ |
419
|
|
|
Assert::false( |
420
|
|
|
$this->indexPage->isSingleResourceOnPage(['code' => $paymentMethod->getCode(), 'name' => $paymentMethod->getName()]), |
421
|
|
|
sprintf('Payment method %s should no longer exist in the registry', $paymentMethod->getName()) |
422
|
|
|
); |
423
|
|
|
} |
424
|
|
|
|
425
|
|
|
/** |
426
|
|
|
* @Then I should be notified that payment method with this code already exists |
427
|
|
|
*/ |
428
|
|
|
public function iShouldBeNotifiedThatPaymentMethodWithThisCodeAlreadyExists() |
429
|
|
|
{ |
430
|
|
|
Assert::same($this->createPage->getValidationMessage('code'), 'The payment method with given code already exists.'); |
431
|
|
|
} |
432
|
|
|
|
433
|
|
|
/** |
434
|
|
|
* @Then there should still be only one payment method with :element :code |
435
|
|
|
*/ |
436
|
|
|
public function thereShouldStillBeOnlyOnePaymentMethodWith($element, $code) |
437
|
|
|
{ |
438
|
|
|
$this->iBrowsePaymentMethods(); |
439
|
|
|
|
440
|
|
|
Assert::true( |
441
|
|
|
$this->indexPage->isSingleResourceOnPage([$element => $code]), |
442
|
|
|
sprintf('Payment method with %s %s cannot be found.', $element, $code) |
443
|
|
|
); |
444
|
|
|
} |
445
|
|
|
} |
446
|
|
|
|