forked from Sylius/Sylius
/
ManagingProductsContext.php
1104 lines (941 loc) · 34.2 KB
/
ManagingProductsContext.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Sylius\Behat\Context\Ui\Admin;
use Behat\Behat\Context\Context;
use Behat\Mink\Exception\ElementNotFoundException;
use Sylius\Behat\NotificationType;
use Sylius\Behat\Page\Admin\Crud\CreatePageInterface;
use Sylius\Behat\Page\Admin\Crud\UpdatePageInterface;
use Sylius\Behat\Page\Admin\Product\CreateConfigurableProductPageInterface;
use Sylius\Behat\Page\Admin\Product\CreateSimpleProductPageInterface;
use Sylius\Behat\Page\Admin\Product\IndexPageInterface;
use Sylius\Behat\Page\Admin\Product\IndexPerTaxonPageInterface;
use Sylius\Behat\Page\Admin\Product\UpdateConfigurableProductPageInterface;
use Sylius\Behat\Page\Admin\Product\UpdateSimpleProductPageInterface;
use Sylius\Behat\Page\Admin\ProductReview\IndexPageInterface as ProductReviewIndexPageInterface;
use Sylius\Behat\Page\Admin\ProductVariant\CreatePageInterface as VariantCreatePageInterface;
use Sylius\Behat\Page\Admin\ProductVariant\GeneratePageInterface;
use Sylius\Behat\Service\NotificationCheckerInterface;
use Sylius\Behat\Service\Resolver\CurrentPageResolverInterface;
use Sylius\Behat\Service\SharedStorageInterface;
use Sylius\Component\Core\Model\ChannelInterface;
use Sylius\Component\Core\Model\ProductInterface;
use Sylius\Component\Core\Model\TaxonInterface;
use Sylius\Component\Product\Model\ProductAssociationTypeInterface;
use Webmozart\Assert\Assert;
final class ManagingProductsContext implements Context
{
/** @var SharedStorageInterface */
private $sharedStorage;
/** @var CreateSimpleProductPageInterface */
private $createSimpleProductPage;
/** @var CreateConfigurableProductPageInterface */
private $createConfigurableProductPage;
/** @var IndexPageInterface */
private $indexPage;
/** @var UpdateSimpleProductPageInterface */
private $updateSimpleProductPage;
/** @var UpdateConfigurableProductPageInterface */
private $updateConfigurableProductPage;
/** @var ProductReviewIndexPageInterface */
private $productReviewIndexPage;
/** @var IndexPerTaxonPageInterface */
private $indexPerTaxonPage;
/** @var VariantCreatePageInterface */
private $variantCreatePage;
/** @var GeneratePageInterface */
private $variantGeneratePage;
/** @var CurrentPageResolverInterface */
private $currentPageResolver;
/** @var NotificationCheckerInterface */
private $notificationChecker;
public function __construct(
SharedStorageInterface $sharedStorage,
CreateSimpleProductPageInterface $createSimpleProductPage,
CreateConfigurableProductPageInterface $createConfigurableProductPage,
IndexPageInterface $indexPage,
UpdateSimpleProductPageInterface $updateSimpleProductPage,
UpdateConfigurableProductPageInterface $updateConfigurableProductPage,
ProductReviewIndexPageInterface $productReviewIndexPage,
IndexPerTaxonPageInterface $indexPerTaxonPage,
VariantCreatePageInterface $variantCreatePage,
GeneratePageInterface $variantGeneratePage,
CurrentPageResolverInterface $currentPageResolver,
NotificationCheckerInterface $notificationChecker
) {
$this->sharedStorage = $sharedStorage;
$this->createSimpleProductPage = $createSimpleProductPage;
$this->createConfigurableProductPage = $createConfigurableProductPage;
$this->indexPage = $indexPage;
$this->updateSimpleProductPage = $updateSimpleProductPage;
$this->updateConfigurableProductPage = $updateConfigurableProductPage;
$this->productReviewIndexPage = $productReviewIndexPage;
$this->indexPerTaxonPage = $indexPerTaxonPage;
$this->variantCreatePage = $variantCreatePage;
$this->variantGeneratePage = $variantGeneratePage;
$this->currentPageResolver = $currentPageResolver;
$this->notificationChecker = $notificationChecker;
}
/**
* @When I want to create a new simple product
*/
public function iWantToCreateANewSimpleProduct()
{
$this->createSimpleProductPage->open();
}
/**
* @When I want to create a new configurable product
*/
public function iWantToCreateANewConfigurableProduct(): void
{
$this->createConfigurableProductPage->open();
}
/**
* @When I specify its code as :code
* @When I do not specify its code
*/
public function iSpecifyItsCodeAs($code = null)
{
$currentPage = $this->resolveCurrentPage();
$currentPage->specifyCode($code ?? '');
}
/**
* @When I do not name it
* @When I name it :name in :language
* @When I rename it to :name in :language
*/
public function iRenameItToIn(?string $name = null, ?string $language = null): void
{
if ($name !== null && $language !== null) {
$currentPage = $this->resolveCurrentPage();
$currentPage->nameItIn($name, $language);
}
}
/**
* @When I add it
* @When I try to add it
*/
public function iAddIt()
{
/** @var CreatePageInterface $currentPage */
$currentPage = $this->resolveCurrentPage();
$currentPage->create();
}
/**
* @When I disable its inventory tracking
*/
public function iDisableItsTracking()
{
$this->updateSimpleProductPage->disableTracking();
}
/**
* @When I enable its inventory tracking
*/
public function iEnableItsTracking()
{
$this->updateSimpleProductPage->enableTracking();
}
/**
* @When /^I set its(?:| default) price to "(?:€|£|\$)([^"]+)" for "([^"]+)" channel$/
*/
public function iSetItsPriceTo(string $price, string $channelName)
{
$this->createSimpleProductPage->specifyPrice($channelName, $price);
}
/**
* @When /^I set its original price to "(?:€|£|\$)([^"]+)" for "([^"]+)" channel$/
*/
public function iSetItsOriginalPriceTo(int $originalPrice, $channelName)
{
$this->createSimpleProductPage->specifyOriginalPrice($channelName, $originalPrice);
}
/**
* @When I make it available in channel :channel
*/
public function iMakeItAvailableInChannel(ChannelInterface $channel)
{
$this->createSimpleProductPage->checkChannel($channel->getName());
}
/**
* @When I assign it to channel :channel
*/
public function iAssignItToChannel(ChannelInterface $channel)
{
// Temporary solution until we will make current page resolver work with product pages
$this->updateConfigurableProductPage->checkChannel($channel->getName());
}
/**
* @When I choose :calculatorName calculator
*/
public function iChooseCalculator($calculatorName)
{
$this->createSimpleProductPage->choosePricingCalculator($calculatorName);
}
/**
* @When I set its slug to :slug
* @When I set its slug to :slug in :language
* @When I remove its slug
*/
public function iSetItsSlugToIn(?string $slug = null, $language = 'en_US')
{
$this->createSimpleProductPage->specifySlugIn($slug, $language);
}
/**
* @When I choose to show this product in the :channel channel
*/
public function iChooseToShowThisProductInTheChannel(string $channel): void
{
$this->updateSimpleProductPage->showProductInChannel($channel);
}
/**
* @When I choose to show this product in this channel
*/
public function iChooseToShowThisProductInThisChannel(): void
{
$this->updateSimpleProductPage->showProductInSingleChannel();
}
/**
* @When I enable slug modification
* @When I enable slug modification in :localeCode
*/
public function iEnableSlugModification($localeCode = 'en_US')
{
$this->updateSimpleProductPage->activateLanguageTab($localeCode);
$this->updateSimpleProductPage->enableSlugModification($localeCode);
}
/**
* @When I choose :channelName as a channel filter
*/
public function iChooseChannelAsAChannelFilter(string $channelName): void
{
$this->indexPage->chooseChannelFilter($channelName);
}
/**
* @When I filter
*/
public function iFilter(): void
{
$this->indexPage->filter();
}
/**
* @Then I should see the product :productName in the list
* @Then the product :productName should appear in the store
* @Then the product :productName should be in the shop
* @Then this product should still be named :productName
*/
public function theProductShouldAppearInTheShop(string $productName): void
{
$this->iWantToBrowseProducts();
Assert::true($this->indexPage->isSingleResourceOnPage(['name' => $productName]));
}
/**
* @Given I am browsing products
* @When I browse products
* @When I want to browse products
*/
public function iWantToBrowseProducts()
{
$this->indexPage->open();
}
/**
* @When /^I am browsing products from ("([^"]+)" taxon)$/
*/
public function iAmBrowsingProductsFromTaxon(TaxonInterface $taxon)
{
$this->indexPerTaxonPage->open(['taxonId' => $taxon->getId()]);
}
/**
* @When I filter them by :taxonName taxon
*/
public function iFilterThemByTaxon($taxonName)
{
$this->indexPage->filterByTaxon($taxonName);
}
/**
* @When I check (also) the :productName product
*/
public function iCheckTheProduct(string $productName): void
{
$this->indexPage->checkResourceOnPage(['name' => $productName]);
}
/**
* @When I delete them
*/
public function iDeleteThem(): void
{
$this->indexPage->bulkDelete();
}
/**
* @Then I should( still) see a product with :field :value
*/
public function iShouldSeeProductWith($field, $value)
{
Assert::true($this->indexPage->isSingleResourceOnPage([$field => $value]));
}
/**
* @Then I should not see any product with :field :value
*/
public function iShouldNotSeeAnyProductWith($field, $value)
{
Assert::false($this->indexPage->isSingleResourceOnPage([$field => $value]));
}
/**
* @Then the first product on the list should have :field :value
*/
public function theFirstProductOnTheListShouldHave($field, $value)
{
$currentPage = $this->resolveCurrentPage();
Assert::same($currentPage->getColumnFields($field)[0], $value);
}
/**
* @Then the last product on the list should have :field :value
*/
public function theLastProductOnTheListShouldHave($field, $value)
{
$values = $this->indexPerTaxonPage->getColumnFields($field);
Assert::same(end($values), $value);
}
/**
* @When I switch the way products are sorted :sortType by :field
* @When I start sorting products by :field
* @When the products are already sorted :sortType by :field
* @When I sort the products :sortType by :field
*/
public function iSortProductsBy(string $field): void
{
$this->indexPage->sortBy($field);
}
/**
* @Then I should see a single product in the list
* @Then I should see :numberOfProducts products in the list
*/
public function iShouldSeeProductsInTheList(int $numberOfProducts = 1): void
{
Assert::same($this->indexPage->countItems(), (int) $numberOfProducts);
}
/**
* @When I delete the :product product
* @When I try to delete the :product product
*/
public function iDeleteProduct(ProductInterface $product)
{
$this->sharedStorage->set('product', $product);
$this->iWantToBrowseProducts();
$this->indexPage->deleteResourceOnPage(['name' => $product->getName()]);
}
/**
* @Then /^(this product) should not exist in the product catalog$/
*/
public function productShouldNotExist(ProductInterface $product)
{
$this->iWantToBrowseProducts();
Assert::false($this->indexPage->isSingleResourceOnPage(['code' => $product->getCode()]));
}
/**
* @Then I should be notified that this product is in use and cannot be deleted
*/
public function iShouldBeNotifiedOfFailure()
{
$this->notificationChecker->checkNotification(
'Cannot delete, the product is in use.',
NotificationType::failure()
);
}
/**
* @Then /^(this product) should still exist in the product catalog$/
*/
public function productShouldExistInTheProductCatalog(ProductInterface $product)
{
$this->theProductShouldAppearInTheShop($product->getName());
}
/**
* @When I want to modify the :product product
* @When /^I want to modify (this product)$/
* @When I modify the :product product
*/
public function iWantToModifyAProduct(ProductInterface $product): void
{
$this->sharedStorage->set('product', $product);
if ($product->isSimple()) {
$this->updateSimpleProductPage->open(['id' => $product->getId()]);
return;
}
$this->updateConfigurableProductPage->open(['id' => $product->getId()]);
}
/**
* @Then I should not be able to edit its code
*/
public function iShouldNotBeAbleToEditItsCode(): void
{
$currentPage = $this->resolveCurrentPage();
Assert::true($currentPage->isCodeDisabled());
}
/**
* @Then the slug field should not be editable
* @Then the slug field in :localeCode (also )should not be editable
*/
public function theSlugFieldShouldNotBeEditable($localeCode = 'en_US')
{
Assert::true($this->updateSimpleProductPage->isSlugReadonlyIn($localeCode));
}
/**
* @Then this product name should be :name
*/
public function thisProductElementShouldBe($name)
{
$this->assertElementValue('name', $name);
}
/**
* @Then /^I should be notified that (code|name|slug) is required$/
*/
public function iShouldBeNotifiedThatIsRequired($element)
{
$this->assertValidationMessage($element, sprintf('Please enter product %s.', $element));
}
/**
* @When I save my changes
* @When I try to save my changes
*/
public function iSaveMyChanges()
{
$currentPage = $this->resolveCurrentPage();
$currentPage->saveChanges();
}
/**
* @When /^I change its price to (?:€|£|\$)([^"]+) for "([^"]+)" channel$/
*/
public function iChangeItsPriceTo(string $price, $channelName)
{
$this->updateSimpleProductPage->specifyPrice($channelName, $price);
}
/**
* @When /^I change its original price to "(?:€|£|\$)([^"]+)" for "([^"]+)" channel$/
*/
public function iChangeItsOriginalPriceTo(string $price, $channelName)
{
$this->updateSimpleProductPage->specifyOriginalPrice($channelName, $price);
}
/**
* @Given I add the :optionName option to it
*/
public function iAddTheOptionToIt($optionName)
{
$this->createConfigurableProductPage->selectOption($optionName);
}
/**
* @When I set its :attribute attribute to :value
* @When I set its :attribute attribute to :value in :language
* @When I do not set its :attribute attribute in :language
*/
public function iSetItsAttributeTo($attribute, $value = null, $language = 'en_US')
{
$this->createSimpleProductPage->addAttribute($attribute, $value ?? '', $language);
}
/**
* @When I remove its :attribute attribute
* @When I remove its :attribute attribute from :language
*/
public function iRemoveItsAttribute($attribute, $language = 'en_US')
{
$this->createSimpleProductPage->removeAttribute($attribute, $language);
}
/**
* @When I try to add new attributes
*/
public function iTryToAddNewAttributes()
{
$this->updateSimpleProductPage->addSelectedAttributes();
}
/**
* @When I do not want to have shipping required for this product
*/
public function iDoNotWantToHaveShippingRequiredForThisProduct()
{
$this->createSimpleProductPage->setShippingRequired(false);
}
/**
* @Then attribute :attributeName of product :product should be :value
* @Then attribute :attributeName of product :product should be :value in :language
*/
public function itsAttributeShouldBe($attributeName, ProductInterface $product, $value, $language = 'en_US')
{
$this->updateSimpleProductPage->open(['id' => $product->getId()]);
Assert::same($this->updateSimpleProductPage->getAttributeValue($attributeName, $language), $value);
}
/**
* @Then /^(product "[^"]+") should not have a "([^"]+)" attribute$/
*/
public function productShouldNotHaveAttribute(ProductInterface $product, $attribute)
{
$this->updateSimpleProductPage->open(['id' => $product->getId()]);
Assert::false($this->updateSimpleProductPage->hasAttribute($attribute));
}
/**
* @Then /^product "[^"]+" should not have any attributes$/
* @Then /^product "[^"]+" should have (\d+) attributes?$/
*/
public function productShouldNotHaveAnyAttributes($count = 0)
{
Assert::same($this->updateSimpleProductPage->getNumberOfAttributes(), (int) $count);
}
/**
* @Then product with :element :value should not be added
*/
public function productWithNameShouldNotBeAdded($element, $value)
{
$this->iWantToBrowseProducts();
Assert::false($this->indexPage->isSingleResourceOnPage([$element => $value]));
}
/**
* @When I remove its name from :language translation
*/
public function iRemoveItsNameFromTranslation($language)
{
$currentPage = $this->resolveCurrentPage();
$currentPage->nameItIn('', $language);
}
/**
* @Then /^this product should have (?:a|an) "([^"]+)" option$/
*/
public function thisProductShouldHaveOption($productOption)
{
$this->updateConfigurableProductPage->isProductOptionChosen($productOption);
}
/**
* @Then the option field should be disabled
*/
public function theOptionFieldShouldBeDisabled()
{
Assert::true($this->updateConfigurableProductPage->isProductOptionsDisabled());
}
/**
* @When /^I choose main (taxon "[^"]+")$/
*/
public function iChooseMainTaxon(TaxonInterface $taxon)
{
$currentPage = $this->resolveCurrentPage();
$currentPage->selectMainTaxon($taxon);
}
/**
* @Then /^the slug of the ("[^"]+" product) should(?:| still) be "([^"]+)"$/
* @Then /^the slug of the ("[^"]+" product) should(?:| still) be "([^"]+)" (in the "[^"]+" locale)$/
*/
public function productSlugShouldBe(ProductInterface $product, $slug, $locale = 'en_US')
{
$this->updateSimpleProductPage->open(['id' => $product->getId()]);
Assert::same($this->updateSimpleProductPage->getSlug($locale), $slug);
}
/**
* @Then /^(this product) main taxon should be "([^"]+)"$/
* @Then /^main taxon of (product "[^"]+") should be "([^"]+)"$/
*/
public function thisProductMainTaxonShouldBe(ProductInterface $product, $taxonName)
{
$currentPage = $this->resolveCurrentPage();
$currentPage->open(['id' => $product->getId()]);
Assert::true($currentPage->isMainTaxonChosen($taxonName));
}
/**
* @Then /^inventory of (this product) should not be tracked$/
*/
public function thisProductShouldNotBeTracked(ProductInterface $product)
{
$this->iWantToModifyAProduct($product);
Assert::false($this->updateSimpleProductPage->isTracked());
}
/**
* @Then /^inventory of (this product) should be tracked$/
*/
public function thisProductShouldBeTracked(ProductInterface $product)
{
$this->iWantToModifyAProduct($product);
Assert::true($this->updateSimpleProductPage->isTracked());
}
/**
* @When I attach the :path image with :type type
* @When I attach the :path image
*/
public function iAttachImageWithType($path, $type = null)
{
$currentPage = $this->resolveCurrentPage();
$currentPage->attachImage($path, $type);
}
/**
* @When I associate as :productAssociationType the :productName product
* @When I associate as :productAssociationType the :firstProductName and :secondProductName products
*/
public function iAssociateProductsAsProductAssociation(
ProductAssociationTypeInterface $productAssociationType,
...$productsNames
) {
$currentPage = $this->resolveCurrentPage();
$currentPage->associateProducts($productAssociationType, $productsNames);
}
/**
* @When I remove an associated product :productName from :productAssociationType
*/
public function iRemoveAnAssociatedProductFromProductAssociation(
$productName,
ProductAssociationTypeInterface $productAssociationType
) {
$currentPage = $this->resolveCurrentPage();
$currentPage->removeAssociatedProduct($productName, $productAssociationType);
}
/**
* @When I go to the variants list
*/
public function iGoToTheVariantsList(): void
{
$this->resolveCurrentPage()->goToVariantsList();
}
/**
* @When I go to the variant creation page
*/
public function iGoToTheVariantCreationPage(): void
{
$this->resolveCurrentPage()->goToVariantCreation();
}
/**
* @When I go to the variant generation page
*/
public function iGoToTheVariantGenerationPage(): void
{
$this->resolveCurrentPage()->goToVariantGeneration();
}
/**
* @Then /^(?:this product|the product "[^"]+"|it) should(?:| also) have an image with "([^"]*)" type$/
*/
public function thisProductShouldHaveAnImageWithType($type)
{
$currentPage = $this->resolveCurrentPage();
Assert::true($currentPage->isImageWithTypeDisplayed($type));
}
/**
* @Then /^the (product "[^"]+") should still have an accessible image$/
*/
public function productShouldStillHaveAnAccessibleImage(ProductInterface $product): void
{
Assert::true($this->indexPage->hasProductAccessibleImage($product->getCode()));
}
/**
* @Then /^(?:this product|it)(?:| also) should not have any images with "([^"]*)" type$/
*/
public function thisProductShouldNotHaveAnyImagesWithType($code)
{
$currentPage = $this->resolveCurrentPage();
Assert::false($currentPage->isImageWithTypeDisplayed($code));
}
/**
* @When I change the image with the :type type to :path
*/
public function iChangeItsImageToPathForTheType($type, $path)
{
$currentPage = $this->resolveCurrentPage();
$currentPage->changeImageWithType($type, $path);
}
/**
* @When /^I(?:| also) remove an image with "([^"]*)" type$/
*/
public function iRemoveAnImageWithType($code)
{
$currentPage = $this->resolveCurrentPage();
$currentPage->removeImageWithType($code);
}
/**
* @When I remove the first image
*/
public function iRemoveTheFirstImage()
{
$currentPage = $this->resolveCurrentPage();
$currentPage->removeFirstImage();
}
/**
* @When I change the first image type to :type
*/
public function iChangeTheFirstImageTypeTo($type)
{
$currentPage = $this->resolveCurrentPage();
$currentPage->modifyFirstImageType($type);
}
/**
* @Then /^(this product) should not have any images$/
*/
public function thisProductShouldNotHaveImages(ProductInterface $product)
{
$this->iWantToModifyAProduct($product);
$currentPage = $this->resolveCurrentPage();
Assert::same($currentPage->countImages(), 0);
}
/**
* @Then /^(this product) should(?:| still) have (?:only one|(\d+)) images?$/
*/
public function thereShouldStillBeOnlyOneImageInThisProduct(ProductInterface $product, $count = 1)
{
$this->iWantToModifyAProduct($product);
$currentPage = $this->resolveCurrentPage();
Assert::same($currentPage->countImages(), (int) $count);
}
/**
* @Then /^there should be no reviews of (this product)$/
*/
public function thereAreNoProductReviews(ProductInterface $product)
{
$this->productReviewIndexPage->open();
Assert::false($this->productReviewIndexPage->isSingleResourceOnPage(['reviewSubject' => $product->getName()]));
}
/**
* @Then this product should( also) have an association :productAssociationType with product :productName
* @Then this product should( also) have an association :productAssociationType with products :firstProductName and :secondProductName
*/
public function theProductShouldHaveAnAssociationWithProducts(
ProductAssociationTypeInterface $productAssociationType,
...$productsNames
) {
foreach ($productsNames as $productName) {
Assert::true(
$this->updateSimpleProductPage->hasAssociatedProduct($productName, $productAssociationType),
sprintf(
'This product should have an association %s with product %s.',
$productAssociationType->getName(),
$productName
)
);
}
}
/**
* @Then this product should not have an association :productAssociationType with product :productName
*/
public function theProductShouldNotHaveAnAssociationWithProduct(
ProductAssociationTypeInterface $productAssociationType,
$productName
) {
Assert::false($this->updateSimpleProductPage->hasAssociatedProduct($productName, $productAssociationType));
}
/**
* @Then I should be notified that simple product code has to be unique
*/
public function iShouldBeNotifiedThatSimpleProductCodeHasToBeUnique()
{
$this->assertValidationMessage('code', 'Simple product code must be unique among all products and product variants.');
}
/**
* @Then I should be notified that slug has to be unique
*/
public function iShouldBeNotifiedThatSlugHasToBeUnique()
{
$this->assertValidationMessage('slug', 'Product slug must be unique.');
}
/**
* @Then I should be notified that code has to be unique
*/
public function iShouldBeNotifiedThatCodeHasToBeUnique()
{
$this->assertValidationMessage('code', 'Product code must be unique.');
}
/**
* @Then I should be notified that price must be defined for every channel
*/
public function iShouldBeNotifiedThatPriceMustBeDefinedForEveryChannel()
{
$this->assertValidationMessage('channel_pricings', 'You must define price for every channel.');
}
/**
* @Then they should have order like :firstProductName, :secondProductName and :thirdProductName
*/
public function theyShouldHaveOrderLikeAnd(...$productNames)
{
Assert::true($this->indexPerTaxonPage->hasProductsInOrder($productNames));
}
/**
* @When I save my new configuration
*/
public function iSaveMyNewConfiguration()
{
$this->indexPerTaxonPage->savePositions();
}
/**
* @When I set the position of :productName to :position
*/
public function iSetThePositionOfTo(string $productName, string $position): void
{
$this->indexPerTaxonPage->setPositionOfProduct($productName, $position);
}
/**
* @Then this product should( still) have slug :value in :language
*/
public function thisProductElementShouldHaveSlugIn($slug, $language)
{
Assert::same($this->updateSimpleProductPage->getSlug($language), $slug);
}
/**
* @When I set its shipping category as :shippingCategoryName
*/
public function iSetItsShippingCategoryAs($shippingCategoryName)
{
$this->createSimpleProductPage->selectShippingCategory($shippingCategoryName);
}
/**
* @Then /^(it|this product) should be priced at (?:€|£|\$)([^"]+) for channel "([^"]+)"$/
* @Then /^(product "[^"]+") should be priced at (?:€|£|\$)([^"]+) for channel "([^"]+)"$/
*/
public function itShouldBePricedAtForChannel(ProductInterface $product, string $price, $channelName)
{
$this->updateSimpleProductPage->open(['id' => $product->getId()]);
Assert::same($this->updateSimpleProductPage->getPriceForChannel($channelName), $price);
}
/**
* @Then /^(its|this products) original price should be "(?:€|£|\$)([^"]+)" for channel "([^"]+)"$/
*/
public function itsOriginalPriceForChannel(ProductInterface $product, $originalPrice, $channelName)
{
$this->updateSimpleProductPage->open(['id' => $product->getId()]);
Assert::same(
$this->updateSimpleProductPage->getOriginalPriceForChannel($channelName),
$originalPrice
);
}
/**
* @Then /^(this product) should no longer have price for channel "([^"]+)"$/
*/
public function thisProductShouldNoLongerHavePriceForChannel(ProductInterface $product, $channelName)
{
$this->updateSimpleProductPage->open(['id' => $product->getId()]);
try {
$this->updateSimpleProductPage->getPriceForChannel($channelName);
} catch (ElementNotFoundException $exception) {
return;
}
throw new \Exception(
sprintf('Product "%s" should not have price defined for channel "%s".', $product->getName(), $channelName)
);
}
/**
* @Then I should be notified that I have to define product variants' prices for newly assigned channels first
*/
public function iShouldBeNotifiedThatIHaveToDefineProductVariantsPricesForNewlyAssignedChannelsFirst()
{
Assert::same(
$this->updateConfigurableProductPage->getValidationMessage('channels'),
'You have to define product variants\' prices for newly assigned channels first.'
);
}
/**
* @Then /^the (product "[^"]+") should not have shipping required$/
*/
public function theProductWithCodeShouldNotHaveShippingRequired(ProductInterface $product)
{
$this->updateSimpleProductPage->open(['id' => $product->getId()]);
Assert::false($this->updateSimpleProductPage->isShippingRequired());
}
/**
* @Then I should be notified that I have to define the :attribute attribute in :language
*/
public function iShouldBeNotifiedThatIHaveToDefineTheAttributeIn($attribute, $language)
{
Assert::same(
$this->resolveCurrentPage()->getAttributeValidationErrors($attribute, $language),
'This value should not be blank.'
);
}
/**
* @Then I should be notified that the :attribute attribute in :language should be longer than :number