1 | <?php |
||
34 | final class ManagingProductsContext implements Context |
||
35 | { |
||
36 | /** |
||
37 | * @var SharedStorageInterface |
||
38 | */ |
||
39 | private $sharedStorage; |
||
40 | |||
41 | /**x |
||
42 | * @var CreateSimpleProductPageInterface |
||
43 | */ |
||
44 | private $createSimpleProductPage; |
||
45 | |||
46 | /** |
||
47 | * @var CreateConfigurableProductPageInterface |
||
48 | */ |
||
49 | private $createConfigurableProductPage; |
||
50 | |||
51 | /** |
||
52 | * @var IndexPageInterface |
||
53 | */ |
||
54 | private $indexPage; |
||
55 | |||
56 | /** |
||
57 | * @var UpdateSimpleProductPageInterface |
||
58 | */ |
||
59 | private $updateSimpleProductPage; |
||
60 | |||
61 | /** |
||
62 | * @var UpdateConfigurableProductPageInterface |
||
63 | */ |
||
64 | private $updateConfigurableProductPage; |
||
65 | |||
66 | /** |
||
67 | * @var CurrentProductPageResolverInterface |
||
68 | */ |
||
69 | private $currentPageResolver; |
||
70 | |||
71 | /** |
||
72 | * @var NotificationCheckerInterface |
||
73 | */ |
||
74 | private $notificationChecker; |
||
75 | |||
76 | /** |
||
77 | * @param SharedStorageInterface $sharedStorage |
||
78 | * @param CreateSimpleProductPageInterface $createSimpleProductPage |
||
79 | * @param CreateConfigurableProductPageInterface $createConfigurableProductPage |
||
80 | * @param IndexPageInterface $indexPage |
||
81 | * @param UpdateSimpleProductPageInterface $updateSimpleProductPage |
||
82 | * @param UpdateConfigurableProductPageInterface $updateConfigurableProductPage |
||
83 | * @param CurrentProductPageResolverInterface $currentPageResolver |
||
84 | * @param NotificationCheckerInterface $notificationChecker |
||
85 | */ |
||
86 | public function __construct( |
||
87 | SharedStorageInterface $sharedStorage, |
||
88 | CreateSimpleProductPageInterface $createSimpleProductPage, |
||
89 | CreateConfigurableProductPageInterface $createConfigurableProductPage, |
||
90 | IndexPageInterface $indexPage, |
||
91 | UpdateSimpleProductPageInterface $updateSimpleProductPage, |
||
92 | UpdateConfigurableProductPageInterface $updateConfigurableProductPage, |
||
93 | CurrentProductPageResolverInterface $currentPageResolver, |
||
94 | NotificationCheckerInterface $notificationChecker |
||
95 | ) { |
||
96 | $this->sharedStorage = $sharedStorage; |
||
97 | $this->createSimpleProductPage = $createSimpleProductPage; |
||
98 | $this->createConfigurableProductPage = $createConfigurableProductPage; |
||
99 | $this->indexPage = $indexPage; |
||
100 | $this->updateSimpleProductPage = $updateSimpleProductPage; |
||
101 | $this->updateConfigurableProductPage = $updateConfigurableProductPage; |
||
102 | $this->currentPageResolver = $currentPageResolver; |
||
103 | $this->notificationChecker = $notificationChecker; |
||
104 | } |
||
105 | |||
106 | /** |
||
107 | * @Given I want to create a new simple product |
||
108 | */ |
||
109 | public function iWantToCreateANewSimpleProduct() |
||
113 | |||
114 | /** |
||
115 | * @Given I want to create a new configurable product |
||
116 | */ |
||
117 | public function iWantToCreateANewConfigurableProduct() |
||
121 | |||
122 | /** |
||
123 | * @When I specify its code as :code |
||
124 | * @When I do not specify its code |
||
125 | */ |
||
126 | public function iSpecifyItsCodeAs($code = null) |
||
135 | |||
136 | /** |
||
137 | * @When I name it :name in :language |
||
138 | */ |
||
139 | public function iNameItIn($name, $language) |
||
148 | |||
149 | /** |
||
150 | * @When I rename it to :name in :language |
||
151 | */ |
||
152 | public function iRenameItToIn($name, $language) |
||
161 | |||
162 | /** |
||
163 | * @When I add it |
||
164 | * @When I try to add it |
||
165 | */ |
||
166 | public function iAddIt() |
||
178 | |||
179 | /** |
||
180 | * @When /^I specify its price to ("(?:€|£|\$)[^"]+")$/ |
||
181 | */ |
||
182 | public function iSpecifyItsPriceTo($price) |
||
186 | |||
187 | /** |
||
188 | * @Given the product :productName should appear in the shop |
||
189 | * @Given the product :productName should be in the shop |
||
190 | * @Given this product should still be named :productName |
||
191 | */ |
||
192 | public function theProductShouldAppearInTheShop($productName) |
||
201 | |||
202 | /** |
||
203 | * @When I want to browse products |
||
204 | */ |
||
205 | public function iWantToBrowseProducts() |
||
209 | |||
210 | /** |
||
211 | * @Then I should see :numberOfProducts products in the list |
||
212 | */ |
||
213 | public function iShouldSeeProductsInTheList($numberOfProducts) |
||
223 | |||
224 | /** |
||
225 | * @When I delete the :product product |
||
226 | * @When I try to delete the :product product |
||
227 | */ |
||
228 | public function iDeleteProduct(ProductInterface $product) |
||
229 | { |
||
230 | $this->sharedStorage->set('product', $product); |
||
231 | |||
232 | $this->iWantToBrowseProducts(); |
||
233 | $this->indexPage->deleteResourceOnPage(['name' => $product->getName()]); |
||
234 | } |
||
235 | |||
236 | /** |
||
237 | * @Then /^(this product) should not exist in the product catalog$/ |
||
238 | */ |
||
239 | public function productShouldNotExist(ProductInterface $product) |
||
240 | { |
||
241 | $this->iWantToBrowseProducts(); |
||
242 | |||
243 | Assert::false( |
||
244 | $this->indexPage->isSingleResourceOnPage(['code' => $product->getCode()]), |
||
245 | sprintf('Product with code %s exists but should not.', $product->getCode()) |
||
246 | ); |
||
247 | } |
||
248 | |||
249 | /** |
||
250 | * @Then I should be notified that this product is in use and cannot be deleted |
||
251 | */ |
||
252 | public function iShouldBeNotifiedOfFailure() |
||
259 | |||
260 | /** |
||
261 | * @Then /^(this product) should still exist in the product catalog$/ |
||
262 | */ |
||
263 | public function productShouldExistInTheProductCatalog(ProductInterface $product) |
||
267 | |||
268 | /** |
||
269 | * @When I want to modify the :product product |
||
270 | * @When /^I want to modify (this product)$/ |
||
271 | */ |
||
272 | public function iWantToModifyAProduct(ProductInterface $product) |
||
283 | |||
284 | /** |
||
285 | * @Then the code field should be disabled |
||
286 | */ |
||
287 | public function theCodeFieldShouldBeDisabled() |
||
300 | |||
301 | /** |
||
302 | * @Then /^this product price should be "(?:€|£|\$)([^"]+)"$/ |
||
303 | */ |
||
304 | public function thisProductPriceShouldBeEqualTo($price) |
||
308 | |||
309 | /** |
||
310 | * @Then this product name should be :name |
||
311 | */ |
||
312 | public function thisProductElementShouldBe($name) |
||
316 | |||
317 | /** |
||
318 | * @Then /^I should be notified that (code|name) is required$/ |
||
319 | */ |
||
320 | public function iShouldBeNotifiedThatIsRequired($element) |
||
324 | |||
325 | /** |
||
326 | * @Then I should be notified that price is required |
||
327 | */ |
||
328 | public function iShouldBeNotifiedThatPriceIsRequired() |
||
332 | |||
333 | /** |
||
334 | * @When I save my changes |
||
335 | * @When I try to save my changes |
||
336 | */ |
||
337 | public function iSaveMyChanges() |
||
349 | |||
350 | /** |
||
351 | * @When /^I change its price to "(?:€|£|\$)([^"]+)"$/ |
||
352 | */ |
||
353 | public function iChangeItsPriceTo($price) |
||
357 | |||
358 | /** |
||
359 | * @Given I add the :optionName option to it |
||
360 | */ |
||
361 | public function iAddTheOptionToIt($optionName) |
||
365 | |||
366 | /** |
||
367 | * @Given product with :element :value should not be added |
||
368 | */ |
||
369 | public function productWithNameShouldNotBeAdded($element, $value) |
||
378 | |||
379 | /** |
||
380 | * @When I remove its name from :language translation |
||
381 | */ |
||
382 | public function iRemoveItsNameFromTranslation($language) |
||
391 | |||
392 | /** |
||
393 | * @Then /^this product should have (?:a|an) "([^"]+)" option$/ |
||
394 | */ |
||
395 | public function thisProductShouldHaveOption($productOption) |
||
399 | |||
400 | /** |
||
401 | * @Then the option field should be disabled |
||
402 | */ |
||
403 | public function theOptionFieldShouldBeDisabled() |
||
410 | |||
411 | /** |
||
412 | * @param string $element |
||
413 | * @param string $value |
||
414 | */ |
||
415 | private function assertElementValue($element, $value) |
||
432 | |||
433 | /** |
||
434 | * @param string $element |
||
435 | * @param string $message |
||
436 | */ |
||
437 | private function assertValidationMessage($element, $message) |
||
453 | } |
||
454 |