|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Sylius package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Paweł Jędrzejewski |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Sylius\Behat\Context\Ui\Admin; |
|
13
|
|
|
|
|
14
|
|
|
use Behat\Behat\Context\Context; |
|
15
|
|
|
use Sylius\Behat\NotificationType; |
|
16
|
|
|
use Sylius\Behat\Page\Admin\ProductVariant\CreatePageInterface; |
|
17
|
|
|
use Sylius\Behat\Page\Admin\ProductVariant\GeneratePageInterface; |
|
18
|
|
|
use Sylius\Behat\Page\Admin\ProductVariant\IndexPageInterface; |
|
19
|
|
|
use Sylius\Behat\Page\Admin\ProductVariant\UpdatePageInterface; |
|
20
|
|
|
use Sylius\Behat\Service\NotificationCheckerInterface; |
|
21
|
|
|
use Sylius\Behat\Service\Resolver\CurrentPageResolverInterface; |
|
22
|
|
|
use Sylius\Component\Core\Model\ChannelInterface; |
|
23
|
|
|
use Sylius\Component\Core\Model\ProductInterface; |
|
24
|
|
|
use Sylius\Component\Core\Model\ProductVariantInterface; |
|
25
|
|
|
use Sylius\Behat\Service\SharedStorageInterface; |
|
26
|
|
|
use Sylius\Component\Currency\Model\CurrencyInterface; |
|
27
|
|
|
use Sylius\Component\Product\Resolver\DefaultProductVariantResolver; |
|
28
|
|
|
use Webmozart\Assert\Assert; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @author Łukasz Chruściel <[email protected]> |
|
32
|
|
|
*/ |
|
33
|
|
|
final class ManagingProductVariantsContext implements Context |
|
34
|
|
|
{ |
|
35
|
|
|
/** |
|
36
|
|
|
* @var SharedStorageInterface |
|
37
|
|
|
*/ |
|
38
|
|
|
private $sharedStorage; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @var DefaultProductVariantResolver |
|
42
|
|
|
*/ |
|
43
|
|
|
private $defaultProductVariantResolver; |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @var CreatePageInterface |
|
47
|
|
|
*/ |
|
48
|
|
|
private $createPage; |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @var IndexPageInterface |
|
52
|
|
|
*/ |
|
53
|
|
|
private $indexPage; |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @var UpdatePageInterface |
|
57
|
|
|
*/ |
|
58
|
|
|
private $updatePage; |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @var GeneratePageInterface |
|
62
|
|
|
*/ |
|
63
|
|
|
private $generatePage; |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* @var CurrentPageResolverInterface |
|
67
|
|
|
*/ |
|
68
|
|
|
private $currentPageResolver; |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* @var NotificationCheckerInterface |
|
72
|
|
|
*/ |
|
73
|
|
|
private $notificationChecker; |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* @param SharedStorageInterface $sharedStorage |
|
77
|
|
|
* @param DefaultProductVariantResolver $defaultProductVariantResolver |
|
78
|
|
|
* @param CreatePageInterface $createPage |
|
79
|
|
|
* @param IndexPageInterface $indexPage |
|
80
|
|
|
* @param UpdatePageInterface $updatePage |
|
81
|
|
|
* @param GeneratePageInterface $generatePage |
|
82
|
|
|
* @param CurrentPageResolverInterface $currentPageResolver |
|
83
|
|
|
* @param NotificationCheckerInterface $notificationChecker |
|
84
|
|
|
*/ |
|
85
|
|
|
public function __construct( |
|
86
|
|
|
SharedStorageInterface $sharedStorage, |
|
87
|
|
|
DefaultProductVariantResolver $defaultProductVariantResolver, |
|
|
|
|
|
|
88
|
|
|
CreatePageInterface $createPage, |
|
89
|
|
|
IndexPageInterface $indexPage, |
|
90
|
|
|
UpdatePageInterface $updatePage, |
|
91
|
|
|
GeneratePageInterface $generatePage, |
|
92
|
|
|
CurrentPageResolverInterface $currentPageResolver, |
|
93
|
|
|
NotificationCheckerInterface $notificationChecker |
|
94
|
|
|
) { |
|
95
|
|
|
$this->sharedStorage = $sharedStorage; |
|
96
|
|
|
$this->defaultProductVariantResolver = $defaultProductVariantResolver; |
|
97
|
|
|
$this->createPage = $createPage; |
|
98
|
|
|
$this->indexPage = $indexPage; |
|
99
|
|
|
$this->updatePage = $updatePage; |
|
100
|
|
|
$this->generatePage = $generatePage; |
|
101
|
|
|
$this->currentPageResolver = $currentPageResolver; |
|
102
|
|
|
$this->notificationChecker = $notificationChecker; |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* @Given /^I want to create a new variant of (this product)$/ |
|
107
|
|
|
*/ |
|
108
|
|
|
public function iWantToCreateANewProduct(ProductInterface $product) |
|
109
|
|
|
{ |
|
110
|
|
|
$this->createPage->open(['productId' => $product->getId()]); |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* @When I specify its code as :code |
|
115
|
|
|
* @When I do not specify its code |
|
116
|
|
|
*/ |
|
117
|
|
|
public function iSpecifyItsCodeAs($code = null) |
|
118
|
|
|
{ |
|
119
|
|
|
$this->createPage->specifyCode($code); |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
/** |
|
123
|
|
|
* @When I name it :name |
|
124
|
|
|
*/ |
|
125
|
|
|
public function iNameItIn($name) |
|
126
|
|
|
{ |
|
127
|
|
|
$this->createPage->nameIt($name); |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
/** |
|
131
|
|
|
* @When I rename it to :name |
|
132
|
|
|
*/ |
|
133
|
|
|
public function iRenameItTo($name) |
|
134
|
|
|
{ |
|
135
|
|
|
$this->updatePage->nameIt($name); |
|
|
|
|
|
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
/** |
|
139
|
|
|
* @When I add it |
|
140
|
|
|
* @When I try to add it |
|
141
|
|
|
*/ |
|
142
|
|
|
public function iAddIt() |
|
143
|
|
|
{ |
|
144
|
|
|
$this->createPage->create(); |
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
|
|
/** |
|
148
|
|
|
* @When I disable its inventory tracking |
|
149
|
|
|
*/ |
|
150
|
|
|
public function iDisableItsTracking() |
|
151
|
|
|
{ |
|
152
|
|
|
$this->updatePage->disableTracking(); |
|
153
|
|
|
} |
|
154
|
|
|
|
|
155
|
|
|
/** |
|
156
|
|
|
* @When I enable its inventory tracking |
|
157
|
|
|
*/ |
|
158
|
|
|
public function iEnableItsTracking() |
|
159
|
|
|
{ |
|
160
|
|
|
$this->updatePage->enableTracking(); |
|
161
|
|
|
} |
|
162
|
|
|
|
|
163
|
|
|
/** |
|
164
|
|
|
* @When /^I set its(?:| default) price to ("(?:€|£|\$)[^"]+")$/ |
|
165
|
|
|
*/ |
|
166
|
|
|
public function iSetItsPriceTo($price) |
|
167
|
|
|
{ |
|
168
|
|
|
$this->createPage->specifyPrice($price); |
|
169
|
|
|
} |
|
170
|
|
|
|
|
171
|
|
|
/** |
|
172
|
|
|
* @When I choose :calculatorName calculator |
|
173
|
|
|
*/ |
|
174
|
|
|
public function iChooseCalculator($calculatorName) |
|
175
|
|
|
{ |
|
176
|
|
|
$this->createPage->choosePricingCalculator($calculatorName); |
|
177
|
|
|
} |
|
178
|
|
|
|
|
179
|
|
|
/** |
|
180
|
|
|
* @When /^I set its price to "(?:€|£|\$)([^"]+)" for ("[^"]+" currency) and ("[^"]+" channel)$/ |
|
181
|
|
|
*/ |
|
182
|
|
|
public function iSetItsPriceToForCurrencyAndChannel($price, CurrencyInterface $currency, ChannelInterface $channel) |
|
183
|
|
|
{ |
|
184
|
|
|
$this->createPage->specifyPriceForChannelAndCurrency($price, $channel, $currency); |
|
185
|
|
|
} |
|
186
|
|
|
|
|
187
|
|
|
/** |
|
188
|
|
|
* @When I set its :optionName option to :optionValue |
|
189
|
|
|
*/ |
|
190
|
|
|
public function iSetItsOptionAs($optionName, $optionValue) |
|
191
|
|
|
{ |
|
192
|
|
|
$this->createPage->selectOption($optionName, $optionValue); |
|
193
|
|
|
} |
|
194
|
|
|
|
|
195
|
|
|
/** |
|
196
|
|
|
* @Then the :productVariantCode variant of the :product product should appear in the shop |
|
197
|
|
|
*/ |
|
198
|
|
|
public function theProductVariantShouldAppearInTheShop($productVariantCode, ProductInterface $product) |
|
199
|
|
|
{ |
|
200
|
|
|
$this->iWantToViewAllVariantsOfThisProduct($product); |
|
201
|
|
|
|
|
202
|
|
|
Assert::true( |
|
203
|
|
|
$this->indexPage->isSingleResourceOnPage(['code' => $productVariantCode]), |
|
204
|
|
|
sprintf('The product variant with code %s has not been found.', $productVariantCode) |
|
205
|
|
|
); |
|
206
|
|
|
} |
|
207
|
|
|
|
|
208
|
|
|
/** |
|
209
|
|
|
* @When /^I (?:|want to )view all variants of (this product)$/ |
|
210
|
|
|
* @When /^I view(?:| all) variants of the (product "[^"]+")$/ |
|
211
|
|
|
*/ |
|
212
|
|
|
public function iWantToViewAllVariantsOfThisProduct(ProductInterface $product) |
|
213
|
|
|
{ |
|
214
|
|
|
$this->indexPage->open(['productId' => $product->getId()]); |
|
215
|
|
|
} |
|
216
|
|
|
|
|
217
|
|
|
/** |
|
218
|
|
|
* @Then I should see :numberOfProductVariants variants in the list |
|
219
|
|
|
* @Then I should see :numberOfProductVariants variant in the list |
|
220
|
|
|
*/ |
|
221
|
|
|
public function iShouldSeeProductVariantsInTheList($numberOfProductVariants) |
|
|
|
|
|
|
222
|
|
|
{ |
|
223
|
|
|
$foundRows = $this->indexPage->countItems(); |
|
224
|
|
|
|
|
225
|
|
|
Assert::same( |
|
226
|
|
|
(int) $numberOfProductVariants, |
|
227
|
|
|
$foundRows, |
|
228
|
|
|
'%s rows with product variants should appear on page, %s rows has been found' |
|
229
|
|
|
); |
|
230
|
|
|
} |
|
231
|
|
|
|
|
232
|
|
|
/** |
|
233
|
|
|
* @When /^I delete the ("[^"]+" variant of product "[^"]+")$/ |
|
234
|
|
|
* @When /^I try to delete the ("[^"]+" variant of product "[^"]+")$/ |
|
235
|
|
|
*/ |
|
236
|
|
|
public function iDeleteTheVariantOfProduct(ProductVariantInterface $productVariant) |
|
237
|
|
|
{ |
|
238
|
|
|
$this->iWantToViewAllVariantsOfThisProduct($productVariant->getProduct()); |
|
|
|
|
|
|
239
|
|
|
|
|
240
|
|
|
$this->indexPage->deleteResourceOnPage(['code' => $productVariant->getCode()]); |
|
241
|
|
|
} |
|
242
|
|
|
|
|
243
|
|
|
/** |
|
244
|
|
|
* @Then /^(this variant) should not exist in the product catalog$/ |
|
245
|
|
|
*/ |
|
246
|
|
|
public function productVariantShouldNotExist(ProductVariantInterface $productVariant) |
|
247
|
|
|
{ |
|
248
|
|
|
$this->iWantToViewAllVariantsOfThisProduct($productVariant->getProduct()); |
|
|
|
|
|
|
249
|
|
|
|
|
250
|
|
|
Assert::false( |
|
251
|
|
|
$this->indexPage->isSingleResourceOnPage(['name' => $productVariant->getName()]), |
|
252
|
|
|
sprintf('Product variant with code %s exists but should not.', $productVariant->getName()) |
|
253
|
|
|
); |
|
254
|
|
|
} |
|
255
|
|
|
|
|
256
|
|
|
/** |
|
257
|
|
|
* @Then I should be notified that this variant is in use and cannot be deleted |
|
258
|
|
|
*/ |
|
259
|
|
|
public function iShouldBeNotifiedOfFailure() |
|
260
|
|
|
{ |
|
261
|
|
|
$this->notificationChecker->checkNotification( |
|
262
|
|
|
"Cannot delete, the product variant is in use.", |
|
|
|
|
|
|
263
|
|
|
NotificationType::failure() |
|
264
|
|
|
); |
|
265
|
|
|
} |
|
266
|
|
|
|
|
267
|
|
|
/** |
|
268
|
|
|
* @Then /^(this variant) should still exist in the product catalog$/ |
|
269
|
|
|
*/ |
|
270
|
|
|
public function productShouldExistInTheProductCatalog(ProductVariantInterface $productVariant) |
|
271
|
|
|
{ |
|
272
|
|
|
$this->theProductVariantShouldAppearInTheShop($productVariant->getCode(), $productVariant->getProduct()); |
|
|
|
|
|
|
273
|
|
|
} |
|
274
|
|
|
|
|
275
|
|
|
/** |
|
276
|
|
|
* @When /^I want to modify the ("[^"]+" product variant)$/ |
|
277
|
|
|
* @When /^I want to modify (this product variant)$/ |
|
278
|
|
|
*/ |
|
279
|
|
|
public function iWantToModifyAProduct(ProductVariantInterface $productVariant) |
|
280
|
|
|
{ |
|
281
|
|
|
$this->updatePage->open(['id' => $productVariant->getId(), 'productId' => $productVariant->getProduct()->getId()]); |
|
282
|
|
|
} |
|
283
|
|
|
|
|
284
|
|
|
/** |
|
285
|
|
|
* @Then the code field should be disabled |
|
286
|
|
|
*/ |
|
287
|
|
|
public function theCodeFieldShouldBeDisabled() |
|
288
|
|
|
{ |
|
289
|
|
|
Assert::true( |
|
290
|
|
|
$this->updatePage->isCodeDisabled(), |
|
291
|
|
|
'Code should be immutable, but it does not.' |
|
292
|
|
|
); |
|
293
|
|
|
} |
|
294
|
|
|
|
|
295
|
|
|
/** |
|
296
|
|
|
* @Then I should be notified that price is required |
|
297
|
|
|
*/ |
|
298
|
|
|
public function iShouldBeNotifiedThatPriceIsRequired() |
|
299
|
|
|
{ |
|
300
|
|
|
$this->assertValidationMessage('price', 'Please enter the price.'); |
|
301
|
|
|
} |
|
302
|
|
|
|
|
303
|
|
|
/** |
|
304
|
|
|
* @Then /^I should be notified that price is required for the (\d)(?:st|nd|rd|th) variant$/ |
|
305
|
|
|
*/ |
|
306
|
|
|
public function iShouldBeNotifiedThatPriceIsRequiredForVariant($position) |
|
307
|
|
|
{ |
|
308
|
|
|
Assert::same($this->generatePage->getValidationMessage('price', $position), 'Please enter the price.'); |
|
309
|
|
|
} |
|
310
|
|
|
|
|
311
|
|
|
/** |
|
312
|
|
|
* @Then /^I should be notified that code is required for the (\d)(?:st|nd|rd|th) variant$/ |
|
313
|
|
|
*/ |
|
314
|
|
|
public function iShouldBeNotifiedThatCodeIsRequiredForVariant($position) |
|
315
|
|
|
{ |
|
316
|
|
|
Assert::same($this->generatePage->getValidationMessage('code', $position), 'Please enter variant code.'); |
|
317
|
|
|
} |
|
318
|
|
|
|
|
319
|
|
|
/** |
|
320
|
|
|
* @When I save my changes |
|
321
|
|
|
* @When I try to save my changes |
|
322
|
|
|
*/ |
|
323
|
|
|
public function iSaveMyChanges() |
|
324
|
|
|
{ |
|
325
|
|
|
$this->updatePage->saveChanges(); |
|
326
|
|
|
} |
|
327
|
|
|
|
|
328
|
|
|
/** |
|
329
|
|
|
* @When /^I change its price to "(?:€|£|\$)([^"]+)"$/ |
|
330
|
|
|
*/ |
|
331
|
|
|
public function iChangeItsPriceTo($price) |
|
332
|
|
|
{ |
|
333
|
|
|
$this->updatePage->specifyPrice($price); |
|
334
|
|
|
} |
|
335
|
|
|
|
|
336
|
|
|
/** |
|
337
|
|
|
* @When I remove its name |
|
338
|
|
|
*/ |
|
339
|
|
|
public function iRemoveItsNameFromTranslation() |
|
340
|
|
|
{ |
|
341
|
|
|
$this->updatePage->nameIt(''); |
|
|
|
|
|
|
342
|
|
|
} |
|
343
|
|
|
|
|
344
|
|
|
/** |
|
345
|
|
|
* @Then /^the variant "([^"]+)" should have (\d+) items on hand$/ |
|
346
|
|
|
*/ |
|
347
|
|
|
public function thisVariantShouldHaveItemsOnHand($productVariantName, $quantity) |
|
348
|
|
|
{ |
|
349
|
|
|
Assert::true( |
|
350
|
|
|
$this->indexPage->isSingleResourceWithSpecificElementOnPage(['name' => $productVariantName], sprintf('td > div.ui.label:contains("%s")', $quantity)), |
|
351
|
|
|
sprintf('The product variant %s should have %s items on hand, but it does not.',$productVariantName, $quantity) |
|
352
|
|
|
); |
|
353
|
|
|
} |
|
354
|
|
|
|
|
355
|
|
|
/** |
|
356
|
|
|
* @Then /^the "([^"]+)" variant of ("[^"]+" product) should have (\d+) items on hand$/ |
|
357
|
|
|
*/ |
|
358
|
|
|
public function theVariantOfProductShouldHaveItemsOnHand($productVariantName, ProductInterface $product, $quantity) |
|
359
|
|
|
{ |
|
360
|
|
|
$this->indexPage->open(['productId' => $product->getId()]); |
|
361
|
|
|
|
|
362
|
|
|
Assert::true( |
|
363
|
|
|
$this->indexPage->isSingleResourceWithSpecificElementOnPage(['name' => $productVariantName], sprintf('td > div.ui.label:contains("%s")', $quantity)), |
|
364
|
|
|
sprintf('The product variant %s should have %s items on hand, but it does not.',$productVariantName, $quantity) |
|
365
|
|
|
); |
|
366
|
|
|
} |
|
367
|
|
|
|
|
368
|
|
|
/** |
|
369
|
|
|
* @Then /^inventory of (this variant) should not be tracked$/ |
|
370
|
|
|
*/ |
|
371
|
|
|
public function thisProductVariantShouldNotBeTracked(ProductVariantInterface $productVariant) |
|
372
|
|
|
{ |
|
373
|
|
|
$this->iWantToModifyAProduct($productVariant); |
|
374
|
|
|
|
|
375
|
|
|
Assert::false( |
|
376
|
|
|
$this->updatePage->isTracked(), |
|
377
|
|
|
'This variant should not be tracked, but it is.' |
|
378
|
|
|
); |
|
379
|
|
|
} |
|
380
|
|
|
|
|
381
|
|
|
/** |
|
382
|
|
|
* @Then /^inventory of (this variant) should be tracked$/ |
|
383
|
|
|
*/ |
|
384
|
|
|
public function thisProductVariantShouldBeTracked(ProductVariantInterface $productVariant) |
|
385
|
|
|
{ |
|
386
|
|
|
$this->iWantToModifyAProduct($productVariant); |
|
387
|
|
|
|
|
388
|
|
|
Assert::true( |
|
389
|
|
|
$this->updatePage->isTracked(), |
|
390
|
|
|
'This variant should be tracked, but it is not.' |
|
391
|
|
|
); |
|
392
|
|
|
} |
|
393
|
|
|
|
|
394
|
|
|
/** |
|
395
|
|
|
* @Then /^I should see that the ("([^"]+)" variant) is not tracked$/ |
|
396
|
|
|
*/ |
|
397
|
|
|
public function iShouldSeeThatIsNotTracked(ProductVariantInterface $productVariant) |
|
398
|
|
|
{ |
|
399
|
|
|
Assert::true( |
|
400
|
|
|
$this->indexPage->isSingleResourceOnPage(['name' => $productVariant->getName(), 'inventory' => 'Not tracked']), |
|
401
|
|
|
sprintf('This "%s" variant should have label not tracked, but it does not have', $productVariant->getName()) |
|
402
|
|
|
); |
|
403
|
|
|
} |
|
404
|
|
|
|
|
405
|
|
|
/** |
|
406
|
|
|
* @Then /^I should see that the ("[^"]+" variant) has zero on hand quantity$/ |
|
407
|
|
|
*/ |
|
408
|
|
|
public function iShouldSeeThatTheVariantHasZeroOnHandQuantity(ProductVariantInterface $productVariant) |
|
409
|
|
|
{ |
|
410
|
|
|
Assert::true( |
|
411
|
|
|
$this->indexPage->isSingleResourceOnPage(['name' => $productVariant->getName(), 'inventory' => '0 Available on hand']), |
|
412
|
|
|
sprintf('This "%s" variant should have 0 on hand quantity, but it does not.', $productVariant->getName()) |
|
413
|
|
|
); |
|
414
|
|
|
} |
|
415
|
|
|
|
|
416
|
|
|
/** |
|
417
|
|
|
* @Then /^(\d+) units of (this product) should be on hold$/ |
|
418
|
|
|
*/ |
|
419
|
|
|
public function unitsOfThisProductShouldBeOnHold($quantity, ProductInterface $product) |
|
420
|
|
|
{ |
|
421
|
|
|
/** @var ProductVariantInterface $variant */ |
|
422
|
|
|
$variant = $this->defaultProductVariantResolver->getVariant($product); |
|
423
|
|
|
|
|
424
|
|
|
$this->assertOnHoldQuantityOfVariant($quantity, $variant); |
|
425
|
|
|
} |
|
426
|
|
|
|
|
427
|
|
|
/** |
|
428
|
|
|
* @Then /^(\d+) units of (this product) should be on hand$/ |
|
429
|
|
|
*/ |
|
430
|
|
|
public function unitsOfThisProductShouldBeOnHand($quantity, ProductInterface $product) |
|
431
|
|
|
{ |
|
432
|
|
|
/** @var ProductVariantInterface $variant */ |
|
433
|
|
|
$variant = $this->defaultProductVariantResolver->getVariant($product); |
|
434
|
|
|
$actualQuantity = $this->indexPage->getOnHandQuantityFor($variant); |
|
435
|
|
|
|
|
436
|
|
|
Assert::same( |
|
437
|
|
|
(int) $quantity, |
|
438
|
|
|
$actualQuantity, |
|
439
|
|
|
sprintf( |
|
440
|
|
|
'Unexpected on hand quantity for "%s" variant. It should be "%s" but is "%s"', |
|
441
|
|
|
$variant->getName(), |
|
442
|
|
|
$quantity, |
|
443
|
|
|
$actualQuantity |
|
444
|
|
|
) |
|
445
|
|
|
); |
|
446
|
|
|
} |
|
447
|
|
|
|
|
448
|
|
|
/** |
|
449
|
|
|
* @Then /^there should be no units of (this product) on hold$/ |
|
450
|
|
|
*/ |
|
451
|
|
|
public function thereShouldBeNoUnitsOfThisProductOnHold(ProductInterface $product) |
|
452
|
|
|
{ |
|
453
|
|
|
/** @var ProductVariantInterface $variant */ |
|
454
|
|
|
$variant = $this->defaultProductVariantResolver->getVariant($product); |
|
455
|
|
|
|
|
456
|
|
|
$this->assertOnHoldQuantityOfVariant(0, $variant); |
|
457
|
|
|
} |
|
458
|
|
|
|
|
459
|
|
|
/** |
|
460
|
|
|
* @Then the :variant variant should have :amount items on hold |
|
461
|
|
|
* @Then /^(this variant) should have (\d+) items on hold$/ |
|
462
|
|
|
*/ |
|
463
|
|
|
public function thisVariantShouldHaveItemsOnHold(ProductVariantInterface $variant, $amount) |
|
464
|
|
|
{ |
|
465
|
|
|
$this->assertOnHoldQuantityOfVariant((int) $amount, $variant); |
|
466
|
|
|
} |
|
467
|
|
|
|
|
468
|
|
|
/** |
|
469
|
|
|
* @Then the :variant variant of :product product should have :amount items on hold |
|
470
|
|
|
*/ |
|
471
|
|
|
public function theVariantOfProductShouldHaveItemsOnHold(ProductVariantInterface $variant, ProductInterface $product, $amount) |
|
472
|
|
|
{ |
|
473
|
|
|
$this->indexPage->open(['productId' => $product->getId()]); |
|
474
|
|
|
|
|
475
|
|
|
$this->assertOnHoldQuantityOfVariant((int) $amount, $variant); |
|
476
|
|
|
} |
|
477
|
|
|
|
|
478
|
|
|
/** |
|
479
|
|
|
* @Then /^(variant with code "[^"]+") for ("[^"]+" currency) and ("[^"]+" channel) should have "(?:€|£|\$)([^"]+)"$/ |
|
480
|
|
|
*/ |
|
481
|
|
|
public function theProductForCurrencyAndChannelShouldHave( |
|
482
|
|
|
ProductVariantInterface $productVariant, |
|
483
|
|
|
CurrencyInterface $currency, |
|
484
|
|
|
ChannelInterface $channel, |
|
485
|
|
|
$price |
|
486
|
|
|
) { |
|
487
|
|
|
$this->updatePage->open(['id' => $productVariant->getId(), 'productId' => $productVariant->getProduct()->getId()]); |
|
488
|
|
|
|
|
489
|
|
|
Assert::same( |
|
490
|
|
|
$this->updatePage->getPricingConfigurationForChannelAndCurrencyCalculator($channel, $currency), |
|
491
|
|
|
$price |
|
492
|
|
|
); |
|
493
|
|
|
} |
|
494
|
|
|
|
|
495
|
|
|
/** |
|
496
|
|
|
* @Given /^I want to generate new variants for (this product)$/ |
|
497
|
|
|
*/ |
|
498
|
|
|
public function iWantToGenerateNewVariantsForThisProduct(ProductInterface $product) |
|
499
|
|
|
{ |
|
500
|
|
|
$this->generatePage->open(['productId' => $product->getId()]); |
|
501
|
|
|
} |
|
502
|
|
|
|
|
503
|
|
|
/** |
|
504
|
|
|
* @When I generate it |
|
505
|
|
|
* @When I try to generate it |
|
506
|
|
|
*/ |
|
507
|
|
|
public function iClickGenerate() |
|
508
|
|
|
{ |
|
509
|
|
|
$this->generatePage->generate(); |
|
510
|
|
|
} |
|
511
|
|
|
|
|
512
|
|
|
/** |
|
513
|
|
|
* @When /^I specify that the (\d)(?:st|nd|rd|th) variant is identified by ("[^"]+") code and costs "(?:€|£|\$)([^"]+)"$/ |
|
514
|
|
|
*/ |
|
515
|
|
|
public function iSpecifyThereAreVariantsIdentifiedByCodeWithCost($nthVariant, $code, $price) |
|
516
|
|
|
{ |
|
517
|
|
|
$this->generatePage->nameCode($nthVariant - 1, $code); |
|
518
|
|
|
$this->generatePage->specifyPrice($nthVariant - 1, $price); |
|
519
|
|
|
} |
|
520
|
|
|
|
|
521
|
|
|
/** |
|
522
|
|
|
* @When /^I specify that the (\d)(?:st|nd|rd|th) variant is identified by ("[^"]+") code$/ |
|
523
|
|
|
*/ |
|
524
|
|
|
public function iSpecifyThereAreVariantsIdentifiedByCode($nthVariant, $code) |
|
525
|
|
|
{ |
|
526
|
|
|
$this->generatePage->nameCode($nthVariant, $code - 1); |
|
527
|
|
|
} |
|
528
|
|
|
|
|
529
|
|
|
/** |
|
530
|
|
|
* @When /^I specify that the (\d)(?:st|nd|rd|th) variant costs "(?:€|£|\$)([^"]+)"$/ |
|
531
|
|
|
*/ |
|
532
|
|
|
public function iSpecifyThereAreVariantsWithCost($nthVariant, $price) |
|
533
|
|
|
{ |
|
534
|
|
|
$this->generatePage->specifyPrice($nthVariant, $price - 1); |
|
535
|
|
|
} |
|
536
|
|
|
|
|
537
|
|
|
/** |
|
538
|
|
|
* @When /^I remove (\d)(?:st|nd|rd|th) variant from the list$/ |
|
539
|
|
|
*/ |
|
540
|
|
|
public function iRemoveVariantFromTheList($nthVariant) |
|
541
|
|
|
{ |
|
542
|
|
|
$this->generatePage->removeVariant($nthVariant - 1); |
|
543
|
|
|
} |
|
544
|
|
|
|
|
545
|
|
|
/** |
|
546
|
|
|
* @Then I should be notified that it has been successfully generated |
|
547
|
|
|
*/ |
|
548
|
|
|
public function iShouldBeNotifiedThatItHasBeenSuccessfullyGenerated() |
|
549
|
|
|
{ |
|
550
|
|
|
$this->notificationChecker->checkNotification('Success Product variants have been successfully generated.', NotificationType::success()); |
|
551
|
|
|
} |
|
552
|
|
|
|
|
553
|
|
|
/** |
|
554
|
|
|
* @param string $element |
|
555
|
|
|
* @param $message |
|
556
|
|
|
*/ |
|
557
|
|
|
private function assertValidationMessage($element, $message) |
|
558
|
|
|
{ |
|
559
|
|
|
/** @var CreatePageInterface|UpdatePageInterface $currentPage */ |
|
560
|
|
|
$currentPage = $this->currentPageResolver->getCurrentPageWithForm([$this->createPage, $this->updatePage]); |
|
561
|
|
|
|
|
562
|
|
|
Assert::same($currentPage->getValidationMessage($element), $message); |
|
563
|
|
|
} |
|
564
|
|
|
|
|
565
|
|
|
/** |
|
566
|
|
|
* @param int $expectedAmount |
|
567
|
|
|
* @param ProductVariantInterface $variant |
|
568
|
|
|
* |
|
569
|
|
|
* @throws \InvalidArgumentException |
|
570
|
|
|
*/ |
|
571
|
|
|
private function assertOnHoldQuantityOfVariant($expectedAmount, $variant) |
|
572
|
|
|
{ |
|
573
|
|
|
$actualAmount = $this->indexPage->getOnHoldQuantityFor($variant); |
|
574
|
|
|
|
|
575
|
|
|
Assert::same( |
|
576
|
|
|
(int) $expectedAmount, |
|
577
|
|
|
$actualAmount, |
|
578
|
|
|
sprintf( |
|
579
|
|
|
'Unexpected on hold quantity for "%s" variant. It should be "%s" but is "%s"', |
|
580
|
|
|
$variant->getName(), |
|
581
|
|
|
$expectedAmount, |
|
582
|
|
|
$actualAmount |
|
583
|
|
|
) |
|
584
|
|
|
); |
|
585
|
|
|
} |
|
586
|
|
|
} |
|
587
|
|
|
|
Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.