1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Sylius\Behat\Context\Ui\Shop\Checkout; |
4
|
|
|
|
5
|
|
|
use Behat\Behat\Context\Context; |
6
|
|
|
use Sylius\Behat\Page\Shop\Checkout\CompletePageInterface; |
7
|
|
|
use Sylius\Behat\Page\Shop\Checkout\SelectPaymentPageInterface; |
8
|
|
|
use Webmozart\Assert\Assert; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* @author Kamil Kokot <[email protected]> |
12
|
|
|
*/ |
13
|
|
|
final class PaymentContext implements Context |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* @var SelectPaymentPageInterface |
17
|
|
|
*/ |
18
|
|
|
private $selectPaymentPage; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @var CompletePageInterface |
22
|
|
|
*/ |
23
|
|
|
private $completePage; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @param SelectPaymentPageInterface $selectPaymentPage |
27
|
|
|
* @param CompletePageInterface $completePage |
28
|
|
|
*/ |
29
|
|
|
public function __construct(SelectPaymentPageInterface $selectPaymentPage, CompletePageInterface $completePage) |
30
|
|
|
{ |
31
|
|
|
$this->selectPaymentPage = $selectPaymentPage; |
32
|
|
|
$this->completePage = $completePage; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @When I try to open checkout payment page |
37
|
|
|
*/ |
38
|
|
|
public function iTryToOpenCheckoutPaymentPage() |
39
|
|
|
{ |
40
|
|
|
$this->selectPaymentPage->tryToOpen(); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @When I decide to change order shipping method |
45
|
|
|
*/ |
46
|
|
|
public function iDecideToChangeMyShippingMethod() |
47
|
|
|
{ |
48
|
|
|
$this->selectPaymentPage->changeShippingMethod(); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @When /^I choose "([^"]*)" payment method$/ |
53
|
|
|
*/ |
54
|
|
|
public function iChoosePaymentMethod($paymentMethodName) |
55
|
|
|
{ |
56
|
|
|
$this->selectPaymentPage->selectPaymentMethod($paymentMethodName ?: 'Offline'); |
57
|
|
|
$this->selectPaymentPage->nextStep(); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @When I want to pay for order |
62
|
|
|
*/ |
63
|
|
|
public function iWantToPayForOrder() |
64
|
|
|
{ |
65
|
|
|
$this->selectPaymentPage->tryToOpen(); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @Then I should be on the checkout payment step |
70
|
|
|
*/ |
71
|
|
|
public function iShouldBeOnTheCheckoutPaymentStep() |
72
|
|
|
{ |
73
|
|
|
Assert::true( |
74
|
|
|
$this->selectPaymentPage->isOpen(), |
75
|
|
|
'Checkout payment page should be opened, but it is not.' |
76
|
|
|
); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @When I go back to payment step of the checkout |
81
|
|
|
*/ |
82
|
|
|
public function iAmAtTheCheckoutPaymentStep() |
83
|
|
|
{ |
84
|
|
|
$this->selectPaymentPage->open(); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @When I complete the payment step |
89
|
|
|
*/ |
90
|
|
|
public function iCompleteThePaymentStep() |
91
|
|
|
{ |
92
|
|
|
$this->selectPaymentPage->nextStep(); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @When I select :name payment method |
97
|
|
|
*/ |
98
|
|
|
public function iSelectPaymentMethod($name) |
99
|
|
|
{ |
100
|
|
|
$this->selectPaymentPage->selectPaymentMethod($name); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* @Then I should not be able to select :paymentMethodName payment method |
105
|
|
|
*/ |
106
|
|
|
public function iShouldNotBeAbleToSelectPaymentMethod($paymentMethodName) |
107
|
|
|
{ |
108
|
|
|
Assert::false( |
109
|
|
|
$this->selectPaymentPage->hasPaymentMethod($paymentMethodName), |
110
|
|
|
sprintf('Payment method "%s" should not be available, but it does.', $paymentMethodName) |
111
|
|
|
); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @Then I should be able to select :paymentMethodName payment method |
116
|
|
|
*/ |
117
|
|
|
public function iShouldBeAbleToSelectPaymentMethod($paymentMethodName) |
118
|
|
|
{ |
119
|
|
|
Assert::true( |
120
|
|
|
$this->selectPaymentPage->hasPaymentMethod($paymentMethodName), |
121
|
|
|
sprintf('Payment method "%s" should be available, but it does not.', $paymentMethodName) |
122
|
|
|
); |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* @Then I should be redirected to the payment step |
127
|
|
|
*/ |
128
|
|
|
public function iShouldBeRedirectedToThePaymentStep() |
129
|
|
|
{ |
130
|
|
|
Assert::true( |
131
|
|
|
$this->selectPaymentPage->isOpen(), |
132
|
|
|
'Checkout payment step should be opened, but it is not.' |
133
|
|
|
); |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* @Given I should be able to go to the summary page again |
138
|
|
|
*/ |
139
|
|
|
public function iShouldBeAbleToGoToTheSummaryPageAgain() |
140
|
|
|
{ |
141
|
|
|
$this->selectPaymentPage->nextStep(); |
142
|
|
|
|
143
|
|
|
Assert::true( |
144
|
|
|
$this->completePage->isOpen(), |
145
|
|
|
'Checkout summary page should be opened, but it is not.' |
146
|
|
|
); |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* @Then I should have :paymentMethodName payment method available as the first choice |
151
|
|
|
*/ |
152
|
|
|
public function iShouldHavePaymentMethodAvailableAsFirstChoice($paymentMethodName) |
153
|
|
|
{ |
154
|
|
|
$paymentMethods = $this->selectPaymentPage->getPaymentMethods(); |
155
|
|
|
$firstPaymentMethod = reset($paymentMethods); |
156
|
|
|
|
157
|
|
|
Assert::same($paymentMethodName, $firstPaymentMethod); |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* @Then I should have :paymentMethodName payment method available as the last choice |
162
|
|
|
*/ |
163
|
|
|
public function iShouldHavePaymentMethodAvailableAsLastChoice($paymentMethodName) |
164
|
|
|
{ |
165
|
|
|
$paymentMethods = $this->selectPaymentPage->getPaymentMethods(); |
166
|
|
|
$lastPaymentMethod = end($paymentMethods); |
167
|
|
|
|
168
|
|
|
Assert::same($paymentMethodName, $lastPaymentMethod); |
169
|
|
|
} |
170
|
|
|
} |
171
|
|
|
|