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\Service\SharedStorageInterface; |
8
|
|
|
use Sylius\Component\Core\Formatter\StringInflector; |
9
|
|
|
use Sylius\Component\Core\Model\PaymentMethodInterface; |
10
|
|
|
use Sylius\Component\Core\Model\ProductInterface; |
11
|
|
|
use Sylius\Component\Core\Model\PromotionInterface; |
12
|
|
|
use Sylius\Component\Core\Model\ShippingMethodInterface; |
13
|
|
|
use Webmozart\Assert\Assert; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @author Kamil Kokot <[email protected]> |
17
|
|
|
*/ |
18
|
|
|
final class CheckoutCompleteContext implements Context |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @var SharedStorageInterface |
22
|
|
|
*/ |
23
|
|
|
private $sharedStorage; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var CompletePageInterface |
27
|
|
|
*/ |
28
|
|
|
private $completePage; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @param SharedStorageInterface $sharedStorage |
32
|
|
|
* @param CompletePageInterface $completePage |
33
|
|
|
*/ |
34
|
|
|
public function __construct(SharedStorageInterface $sharedStorage, CompletePageInterface $completePage) |
35
|
|
|
{ |
36
|
|
|
$this->sharedStorage = $sharedStorage; |
37
|
|
|
$this->completePage = $completePage; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @When I try to open checkout complete page |
42
|
|
|
* @When I want to complete checkout |
43
|
|
|
*/ |
44
|
|
|
public function iTryToOpenCheckoutCompletePage() |
45
|
|
|
{ |
46
|
|
|
$this->completePage->tryToOpen(); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @When I decide to change the payment method |
51
|
|
|
*/ |
52
|
|
|
public function iGoToThePaymentStep() |
53
|
|
|
{ |
54
|
|
|
$this->completePage->changePaymentMethod(); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @When /^I provide additional note like "([^"]+)"$/ |
59
|
|
|
*/ |
60
|
|
|
public function iProvideAdditionalNotesLike($notes) |
61
|
|
|
{ |
62
|
|
|
$this->sharedStorage->set('additional_note', $notes); |
63
|
|
|
$this->completePage->addNotes($notes); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @When I return to the checkout summary step |
68
|
|
|
*/ |
69
|
|
|
public function iReturnToTheCheckoutSummaryStep() |
70
|
|
|
{ |
71
|
|
|
$this->completePage->open(); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @When I confirm my order |
76
|
|
|
*/ |
77
|
|
|
public function iConfirmMyOrder() |
78
|
|
|
{ |
79
|
|
|
$this->completePage->confirmOrder(); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @Then I should be on the checkout complete step |
84
|
|
|
* @Then I should be on the checkout summary step |
85
|
|
|
*/ |
86
|
|
|
public function iShouldBeOnTheCheckoutCompleteStep() |
87
|
|
|
{ |
88
|
|
|
Assert::true($this->completePage->isOpen()); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @Then my order's shipping address should be to :fullName |
93
|
|
|
*/ |
94
|
|
|
public function iShouldSeeThisShippingAddressAsShippingAddress($fullName) |
95
|
|
|
{ |
96
|
|
|
$address = $this->sharedStorage->get('shipping_address_'.StringInflector::nameToLowercaseCode($fullName)); |
97
|
|
|
|
98
|
|
|
Assert::true($this->completePage->hasShippingAddress($address)); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* @Then my order's billing address should be to :fullName |
103
|
|
|
*/ |
104
|
|
|
public function iShouldSeeThisBillingAddressAsBillingAddress($fullName) |
105
|
|
|
{ |
106
|
|
|
$address = $this->sharedStorage->get('billing_address_'.StringInflector::nameToLowercaseCode($fullName)); |
107
|
|
|
|
108
|
|
|
Assert::true($this->completePage->hasBillingAddress($address)); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @Then address to :fullName should be used for both shipping and billing of my order |
113
|
|
|
*/ |
114
|
|
|
public function iShouldSeeThisShippingAddressAsShippingAndBillingAddress($fullName) |
115
|
|
|
{ |
116
|
|
|
$this->iShouldSeeThisShippingAddressAsShippingAddress($fullName); |
117
|
|
|
$this->iShouldSeeThisBillingAddressAsBillingAddress($fullName); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* @Then I should have :quantity :productName products in the cart |
122
|
|
|
*/ |
123
|
|
|
public function iShouldHaveProductsInTheCart($quantity, $productName) |
124
|
|
|
{ |
125
|
|
|
Assert::true($this->completePage->hasItemWithProductAndQuantity($productName); |
|
|
|
|
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* @Then my order shipping should be :price |
130
|
|
|
*/ |
131
|
|
|
public function myOrderShippingShouldBe($price) |
132
|
|
|
{ |
133
|
|
|
Assert::true($this->completePage->hasShippingTotal($price)); |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* @Then /^the ("[^"]+" product) should have unit price discounted by ("\$\d+")$/ |
138
|
|
|
*/ |
139
|
|
|
public function theShouldHaveUnitPriceDiscountedFor(ProductInterface $product, $amount) |
140
|
|
|
{ |
141
|
|
|
Assert::true($this->completePage->hasProductDiscountedUnitPriceBy($product); |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* @Then /^my order total should be ("(?:\£|\$)\d+(?:\.\d+)?")$/ |
146
|
|
|
*/ |
147
|
|
|
public function myOrderTotalShouldBe($total) |
148
|
|
|
{ |
149
|
|
|
Assert::true($this->completePage->hasOrderTotal($total)); |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* @Then my order promotion total should be :promotionTotal |
154
|
|
|
*/ |
155
|
|
|
public function myOrderPromotionTotalShouldBe($promotionTotal) |
156
|
|
|
{ |
157
|
|
|
Assert::true($this->completePage->hasPromotionTotal($promotionTotal)); |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* @Then :promotionName should be applied to my order |
162
|
|
|
*/ |
163
|
|
|
public function shouldBeAppliedToMyOrder($promotionName) |
164
|
|
|
{ |
165
|
|
|
Assert::true($this->completePage->hasPromotion($promotionName)); |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* @Then :promotionName should be applied to my order shipping |
170
|
|
|
*/ |
171
|
|
|
public function shouldBeAppliedToMyOrderShipping($promotionName) |
172
|
|
|
{ |
173
|
|
|
Assert::true($this->completePage->hasShippingPromotion($promotionName)); |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
/** |
177
|
|
|
* @Given my tax total should be :taxTotal |
178
|
|
|
*/ |
179
|
|
|
public function myTaxTotalShouldBe($taxTotal) |
180
|
|
|
{ |
181
|
|
|
Assert::true($this->completePage->hasTaxTotal($taxTotal)); |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
/** |
185
|
|
|
* @Then my order's shipping method should be :shippingMethod |
186
|
|
|
*/ |
187
|
|
|
public function myOrdersShippingMethodShouldBe(ShippingMethodInterface $shippingMethod) |
188
|
|
|
{ |
189
|
|
|
Assert::true($this->completePage->hasShippingMethod($shippingMethod)); |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
/** |
193
|
|
|
* @Then my order's payment method should be :paymentMethod |
194
|
|
|
*/ |
195
|
|
|
public function myOrdersPaymentMethodShouldBe(PaymentMethodInterface $paymentMethod) |
196
|
|
|
{ |
197
|
|
|
Assert::same($this->completePage->getPaymentMethodName(), $paymentMethod->getName()); |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
/** |
201
|
|
|
* @Then the :product product should have unit price :price |
202
|
|
|
*/ |
203
|
|
|
public function theProductShouldHaveUnitPrice(ProductInterface $product, $price) |
204
|
|
|
{ |
205
|
|
|
Assert::true($this->completePage->hasProductUnitPrice($product, $price)); |
206
|
|
|
} |
207
|
|
|
|
208
|
|
|
/** |
209
|
|
|
* @Then /^I should be notified that (this product) does not have sufficient stock$/ |
210
|
|
|
*/ |
211
|
|
|
public function iShouldBeNotifiedThatThisProductDoesNotHaveSufficientStock(ProductInterface $product) |
212
|
|
|
{ |
213
|
|
|
Assert::true($this->completePage->hasProductOutOfStockValidationMessage($product)); |
214
|
|
|
} |
215
|
|
|
|
216
|
|
|
/** |
217
|
|
|
* @Then /^I should not be notified that (this product) does not have sufficient stock$/ |
218
|
|
|
*/ |
219
|
|
|
public function iShouldNotBeNotifiedThatThisProductDoesNotHaveSufficientStock(ProductInterface $product) |
220
|
|
|
{ |
221
|
|
|
Assert::false($this->completePage->hasProductOutOfStockValidationMessage($product)); |
222
|
|
|
} |
223
|
|
|
|
224
|
|
|
/** |
225
|
|
|
* @Then my order's locale should be :localeName |
226
|
|
|
*/ |
227
|
|
|
public function myOrderLocaleShouldBe($localeName) |
228
|
|
|
{ |
229
|
|
|
Assert::true($this->completePage->hasLocale($localeName)); |
230
|
|
|
} |
231
|
|
|
|
232
|
|
|
/** |
233
|
|
|
* @Then I should see :provinceName in the shipping address |
234
|
|
|
*/ |
235
|
|
|
public function iShouldSeeInTheShippingAddress($provinceName) |
236
|
|
|
{ |
237
|
|
|
Assert::true($this->completePage->hasShippingProvinceName($provinceName)); |
238
|
|
|
} |
239
|
|
|
|
240
|
|
|
/** |
241
|
|
|
* @Then I should see :provinceName in the billing address |
242
|
|
|
*/ |
243
|
|
|
public function iShouldSeeInTheBillingAddress($provinceName) |
244
|
|
|
{ |
245
|
|
|
Assert::true($this->completePage->hasBillingProvinceName($provinceName)); |
246
|
|
|
} |
247
|
|
|
|
248
|
|
|
/** |
249
|
|
|
* @Then I should not see any information about payment method |
250
|
|
|
*/ |
251
|
|
|
public function iShouldNotSeeAnyInformationAboutPaymentMethod() |
252
|
|
|
{ |
253
|
|
|
Assert::false($this->completePage->hasPaymentMethod()); |
254
|
|
|
} |
255
|
|
|
|
256
|
|
|
/** |
257
|
|
|
* @Then /^(this promotion) should give "([^"]+)" discount$/ |
258
|
|
|
*/ |
259
|
|
|
public function thisPromotionShouldGiveDiscount(PromotionInterface $promotion, $discount) |
260
|
|
|
{ |
261
|
|
|
Assert::same($this->completePage->getShippingPromotionDiscount($promotion->getName()), $discount); |
262
|
|
|
} |
263
|
|
|
} |
264
|
|
|
|