1 | <?php |
||
28 | final class CartContext implements Context |
||
29 | { |
||
30 | /** |
||
31 | * @var SharedStorageInterface |
||
32 | */ |
||
33 | private $sharedStorage; |
||
34 | |||
35 | /** |
||
36 | * @var SummaryPageInterface |
||
37 | */ |
||
38 | private $summaryPage; |
||
39 | |||
40 | /** |
||
41 | * @var ShowPageInterface |
||
42 | */ |
||
43 | private $productShowPage; |
||
44 | |||
45 | /** |
||
46 | * @var NotificationCheckerInterface |
||
47 | */ |
||
48 | private $notificationChecker; |
||
49 | |||
50 | /** |
||
51 | * @param SharedStorageInterface $sharedStorage |
||
52 | * @param SummaryPageInterface $summaryPage |
||
53 | * @param ShowPageInterface $productShowPage |
||
54 | * @param NotificationCheckerInterface $notificationChecker |
||
55 | */ |
||
56 | public function __construct( |
||
57 | SharedStorageInterface $sharedStorage, |
||
58 | SummaryPageInterface $summaryPage, |
||
59 | ShowPageInterface $productShowPage, |
||
60 | NotificationCheckerInterface $notificationChecker |
||
61 | ) { |
||
62 | $this->sharedStorage = $sharedStorage; |
||
63 | $this->summaryPage = $summaryPage; |
||
64 | $this->productShowPage = $productShowPage; |
||
65 | $this->notificationChecker = $notificationChecker; |
||
66 | } |
||
67 | |||
68 | /** |
||
69 | * @When I see the summary of my cart |
||
70 | */ |
||
71 | public function iOpenCartSummaryPage() |
||
75 | |||
76 | /** |
||
77 | * @Then my cart should be empty |
||
78 | * @Then cart should be empty with no value |
||
79 | */ |
||
80 | public function iShouldBeNotifiedThatMyCartIsEmpty() |
||
81 | { |
||
82 | $this->summaryPage->open(); |
||
83 | |||
84 | Assert::true( |
||
85 | $this->summaryPage->isEmpty(), |
||
86 | 'There should appear information about empty cart, but it does not.' |
||
87 | ); |
||
88 | } |
||
89 | |||
90 | /** |
||
91 | * @Given /^I (?:remove|removed) product "([^"]+)" from the cart$/ |
||
92 | */ |
||
93 | public function iRemoveProductFromTheCart($productName) |
||
94 | { |
||
95 | $this->summaryPage->open(); |
||
96 | $this->summaryPage->removeProduct($productName); |
||
97 | } |
||
98 | |||
99 | /** |
||
100 | * @Given I change :productName quantity to :quantity |
||
101 | */ |
||
102 | public function iChangeQuantityTo($productName, $quantity) |
||
103 | { |
||
104 | $this->summaryPage->open(); |
||
105 | $this->summaryPage->changeQuantity($productName, $quantity); |
||
106 | } |
||
107 | |||
108 | /** |
||
109 | * @Then grand total value should be :total |
||
110 | * @Then my cart total should be :total |
||
111 | */ |
||
112 | public function myCartTotalShouldBe($total) |
||
113 | { |
||
114 | $this->summaryPage->open(); |
||
115 | Assert::same( |
||
116 | $this->summaryPage->getGrandTotal(), |
||
117 | $total, |
||
118 | 'Grand total should be %2$s, but it is %s.' |
||
119 | ); |
||
120 | } |
||
121 | |||
122 | /** |
||
123 | * @Then tax total value should be :taxTotal |
||
124 | * @Then my cart taxes should be :taxTotal |
||
125 | */ |
||
126 | public function myCartTaxesShouldBe($taxTotal) |
||
127 | { |
||
128 | $this->summaryPage->open(); |
||
129 | |||
130 | Assert::same( |
||
131 | $this->summaryPage->getTaxTotal(), |
||
132 | $taxTotal, |
||
133 | 'Tax total value should be %2$s, but it is %s.' |
||
134 | ); |
||
135 | } |
||
136 | |||
137 | /** |
||
138 | * @Then shipping total value should be :shippingTotal |
||
139 | * @Then my cart shipping fee should be :shippingTotal |
||
140 | */ |
||
141 | public function myCartShippingFeeShouldBe($shippingTotal) |
||
142 | { |
||
143 | $this->summaryPage->open(); |
||
144 | |||
145 | Assert::same( |
||
146 | $this->summaryPage->getShippingTotal(), |
||
147 | $shippingTotal, |
||
148 | 'Shipping total value should be %2$s, but it is %s.' |
||
149 | ); |
||
150 | } |
||
151 | |||
152 | /** |
||
153 | * @Then my cart promotions should be :promotionsTotal |
||
154 | * @Then my discount should be :promotionsTotal |
||
155 | */ |
||
156 | public function myDiscountShouldBe($promotionsTotal) |
||
157 | { |
||
158 | $this->summaryPage->open(); |
||
159 | |||
160 | Assert::same( |
||
161 | $this->summaryPage->getPromotionTotal(), |
||
162 | $promotionsTotal, |
||
163 | 'Promotion total value should be %2$s, but it is %s.' |
||
164 | ); |
||
165 | } |
||
166 | |||
167 | /** |
||
168 | * @Given /^there should be no shipping fee$/ |
||
169 | */ |
||
170 | public function thereShouldBeNoShippingFee() |
||
171 | { |
||
172 | $this->summaryPage->open(); |
||
173 | |||
174 | expect($this->summaryPage)->toThrow(ElementNotFoundException::class)->during('getShippingTotal', []); |
||
175 | } |
||
176 | |||
177 | /** |
||
178 | * @Given /^there should be no discount$/ |
||
179 | */ |
||
180 | public function thereShouldBeNoDiscount() |
||
186 | |||
187 | /** |
||
188 | * @Then /^(its|theirs) price should be decreased by ("[^"]+")$/ |
||
189 | * @Then /^(product "[^"]+") price should be decreased by ("[^"]+")$/ |
||
190 | */ |
||
191 | public function itsPriceShouldBeDecreasedBy(ProductInterface $product, $amount) |
||
192 | { |
||
193 | $this->summaryPage->open(); |
||
194 | |||
195 | $discountPrice = $this->summaryPage->getItemDiscountPrice($product->getName()); |
||
196 | $regularPrice = $this->summaryPage->getItemRegularPrice($product->getName()); |
||
197 | |||
198 | Assert::same( |
||
199 | $discountPrice, |
||
200 | ($regularPrice - $amount), |
||
201 | 'Price after discount should be %2$s, but it is %s.' |
||
202 | ); |
||
203 | } |
||
204 | |||
205 | /** |
||
206 | * @Given /^(product "[^"]+") price should not be decreased$/ |
||
207 | */ |
||
208 | public function productPriceShouldNotBeDecreased(ProductInterface $product) |
||
209 | { |
||
210 | $this->summaryPage->open(); |
||
211 | |||
212 | Assert::false( |
||
213 | $this->summaryPage->isItemDiscounted($product->getName()), |
||
214 | 'The price should not be decreased, but it is.' |
||
215 | ); |
||
216 | } |
||
217 | |||
218 | |||
219 | /** |
||
220 | * @Given /^I add (this product) to the cart$/ |
||
221 | * @Given I added product :product to the cart |
||
222 | * @Given /^I (?:have|had) (product "([^"]+)") in the cart$/ |
||
223 | * @When I add product :product to the cart |
||
224 | */ |
||
225 | public function iAddProductToTheCart(ProductInterface $product) |
||
226 | { |
||
227 | $this->productShowPage->open(['slug' => $product->getSlug()]); |
||
228 | $this->productShowPage->addToCart(); |
||
229 | |||
230 | $this->sharedStorage->set('product', $product); |
||
231 | } |
||
232 | |||
233 | /** |
||
234 | * @Given /^I added (products "([^"]+)" and "([^"]+)") to the cart$/ |
||
235 | * @When /^I add (products "([^"]+)" and "([^"]+)") to the cart$/ |
||
236 | * @Given /^I added (products "([^"]+)", "([^"]+)" and "([^"]+)") to the cart$/ |
||
237 | * @When /^I add (products "([^"]+)", "([^"]+)" and "([^"]+)") to the cart$/ |
||
238 | */ |
||
239 | public function iAddMultipleProductsToTheCart(array $products) |
||
240 | { |
||
241 | foreach ($products as $product) { |
||
242 | $this->iAddProductToTheCart($product); |
||
243 | } |
||
244 | } |
||
245 | |||
246 | /** |
||
247 | * @Given I added :variant variant of product :product to the cart |
||
248 | * @When I add :variant variant of product :product to the cart |
||
249 | * @When I have :variant variant of product :product in the cart |
||
250 | * @When /^I add "([^"]+)" variant of (this product) to the cart$/ |
||
251 | */ |
||
252 | public function iAddProductToTheCartSelectingVariant($variant, ProductInterface $product) |
||
259 | |||
260 | /** |
||
261 | * @Given I have :quantity products :product in the cart |
||
262 | * @When I add :quantity products :product to the cart |
||
263 | */ |
||
264 | public function iAddProductsToTheCart(ProductInterface $product, $quantity) |
||
271 | |||
272 | /** |
||
273 | * @Then I should be on my cart summary page |
||
274 | */ |
||
275 | public function shouldBeOnMyCartSummaryPage() |
||
276 | { |
||
277 | Assert::true( |
||
278 | $this->summaryPage->isOpen(), |
||
279 | 'Cart summary page should be open, but it does not.' |
||
280 | ); |
||
281 | } |
||
282 | |||
283 | /** |
||
284 | * @Then I should be notified that the product has been successfully added |
||
285 | */ |
||
286 | public function iShouldBeNotifiedThatItHasBeenSuccessfullyAdded() |
||
290 | |||
291 | /** |
||
292 | * @Then there should be one item in my cart |
||
293 | */ |
||
294 | public function thereShouldBeOneItemInMyCart() |
||
301 | |||
302 | /** |
||
303 | * @Then this item should have name :itemName |
||
304 | */ |
||
305 | public function thisProductShouldHaveName($itemName) |
||
312 | |||
313 | /** |
||
314 | * @Then this item should have variant :variantName |
||
315 | */ |
||
316 | public function thisItemShouldHaveVariant($variantName) |
||
323 | |||
324 | /** |
||
325 | * @When /^I add (this product) with ([^"]+) "([^"]+)" to the cart$/ |
||
326 | */ |
||
327 | public function iAddThisProductWithSizeToTheCart(ProductInterface $product, $optionName, $optionValue) |
||
335 | |||
336 | /** |
||
337 | * @Given /^(this product) should have ([^"]+) "([^"]+)"$/ |
||
338 | */ |
||
339 | public function thisItemShouldHaveSize(ProductInterface $product, $optionName, $optionValue) |
||
347 | } |
||
348 |