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