diff --git a/features/product/managing_product_variants/sorting_product_variants_within_product_by_position.feature b/features/product/managing_product_variants/sorting_product_variants_within_product_by_position.feature index 5e622f02d8b0..f948eb0a77c0 100644 --- a/features/product/managing_product_variants/sorting_product_variants_within_product_by_position.feature +++ b/features/product/managing_product_variants/sorting_product_variants_within_product_by_position.feature @@ -40,30 +40,16 @@ Feature: Sorting listed product variants from a product by position Then I should see 4 variants in the list And the first variant in the list should have name "Opel Insignia Country Tourer" - @ui @javascript @no-api + @ui @javascript @api Scenario: Setting product variant as the first one in the list When I view all variants of the product "Opel Insignia" And I set the position of "Opel Insignia Sedan" to 0 And I save my new configuration Then the first variant in the list should have name "Opel Insignia Sedan" - @api @no-ui - Scenario: Setting product variant as the first one in the list - When I set the position of "Opel Insignia Sedan" to 0 - And I save my new configuration - And I view all variants of the product "Opel Insignia" - Then the first variant in the list should have name "Opel Insignia Sedan" - - @ui @javascript @no-api + @ui @javascript @api Scenario: Setting product variant as the last one in the list When I view all variants of the product "Opel Insignia" And I set the position of "Opel Insignia Sedan" to 7 And I save my new configuration Then the last variant in the list should have name "Opel Insignia Sedan" - - @api @no-ui - Scenario: Setting product variant as the last one in the list - When I set the position of "Opel Insignia Sedan" to 7 - And I save my new configuration - And I view all variants of the product "Opel Insignia" - Then the last variant in the list should have name "Opel Insignia Sedan" diff --git a/src/Sylius/Behat/Context/Api/Admin/BrowsingProductVariantsContext.php b/src/Sylius/Behat/Context/Api/Admin/BrowsingProductVariantsContext.php index 494c0aed486d..3e0101ed2ec2 100644 --- a/src/Sylius/Behat/Context/Api/Admin/BrowsingProductVariantsContext.php +++ b/src/Sylius/Behat/Context/Api/Admin/BrowsingProductVariantsContext.php @@ -16,9 +16,6 @@ use Behat\Behat\Context\Context; use Sylius\Behat\Client\ApiClientInterface; use Sylius\Behat\Client\ResponseCheckerInterface; -use Sylius\Behat\Context\Api\Resources; -use Sylius\Component\Core\Model\ProductVariantInterface; -use Webmozart\Assert\Assert; final class BrowsingProductVariantsContext implements Context { @@ -27,71 +24,4 @@ public function __construct ( private ResponseCheckerInterface $responseChecker, ) { } - - /** - * @When I start sorting variants by position - */ - public function iSortProductsByPosition(): void - { - $this->client->index( - Resources::PRODUCT_VARIANTS, - [ - 'order[position]' => 'desc', - ], - ); - } - - /** - * @When I set the position of :productVariant to :position - */ - public function iSetThePositionOfTo(ProductVariantInterface $productVariant, int $position): void - { - $this->client->buildUpdateRequest(Resources::PRODUCT_VARIANTS, $productVariant->getCode()); - $this->client->updateRequestData(['position' => $position]); - } - - /** - * @When I save my new configuration - */ - public function iSaveMyNewConfiguration(): void - { - $this->client->update(); - } - - /** - * @Then the first variant in the list should have name :variantName - */ - public function theFirstVariantInTheListShouldHaveName(string $variantName): void - { - $variants = $this->responseChecker->getCollection($this->client->getLastResponse()); - - $firstVariant = reset($variants); - - $this->assertProductVariantName($firstVariant['translations']['en_US']['name'], $variantName); - } - - /** - * @Then the last variant in the list should have name :variantName - */ - public function theLastVariantInTheListShouldHaveName(string $variantName): void - { - $variants = $this->responseChecker->getCollection($this->client->getLastResponse()); - - $lastVariant = end($variants); - - $this->assertProductVariantName($lastVariant['translations']['en_US']['name'], $variantName); - } - - private function assertProductVariantName(string $variantName, string $expectedVariantName): void - { - Assert::same( - $variantName, - $expectedVariantName, - sprintf( - 'Expected product variant to have name "%s", but it is named "%s".', - $expectedVariantName, - $variantName, - ), - ); - } } diff --git a/src/Sylius/Behat/Context/Api/Admin/ManagingProductVariantsContext.php b/src/Sylius/Behat/Context/Api/Admin/ManagingProductVariantsContext.php index 758f0e5cf608..dc078852c2c4 100644 --- a/src/Sylius/Behat/Context/Api/Admin/ManagingProductVariantsContext.php +++ b/src/Sylius/Behat/Context/Api/Admin/ManagingProductVariantsContext.php @@ -19,6 +19,7 @@ use Sylius\Behat\Client\ResponseCheckerInterface; use Sylius\Behat\Context\Api\Resources; use Sylius\Behat\Service\Converter\SectionAwareIriConverterInterface; +use Sylius\Behat\Service\SharedStorageInterface; use Sylius\Component\Core\Formatter\StringInflector; use Sylius\Component\Core\Model\ChannelInterface; use Sylius\Component\Core\Model\ProductInterface; @@ -39,6 +40,7 @@ public function __construct( private ResponseCheckerInterface $responseChecker, private IriConverterInterface $iriConverter, private SectionAwareIriConverterInterface $sectionAwareIriConverter, + private SharedStorageInterface $sharedStorage, ) { } @@ -300,6 +302,36 @@ public function iChangeItsQuantityOfInventoryTo(int $amount): void $this->client->updateRequestData(['onHand' => $amount]); } + /** + * @When I start sorting variants by position + */ + public function iSortProductsByPosition(): void + { + $this->client->index( + Resources::PRODUCT_VARIANTS, + [ + 'order[position]' => 'desc', + ], + ); + } + + /** + * @When I set the position of :productVariant to :position + */ + public function iSetThePositionOfTo(ProductVariantInterface $productVariant, int $position): void + { + $this->client->buildUpdateRequest(Resources::PRODUCT_VARIANTS, $productVariant->getCode()); + $this->client->updateRequestData(['position' => $position]); + } + + /** + * @When I save my new configuration + */ + public function iSaveMyNewConfiguration(): void + { + $this->client->update(); + } + /** * @Then I should be notified that it has been successfully created */ @@ -733,4 +765,45 @@ public function iShouldBeNotifiedThatOnHandQuantityMustBeGreaterThanTheNumberOfO 'On hand must be greater than the number of on hold units', ); } + + /** + * @Then the first variant in the list should have name :variantName + */ + public function theFirstVariantInTheListShouldHaveName(string $variantName): void + { + $product = $this->sharedStorage->get('product'); + $this->iWantToViewAllVariantsOfThisProduct($product); + $variants = $this->responseChecker->getCollection($this->client->getLastResponse()); + + $firstVariant = reset($variants); + + $this->assertProductVariantName($firstVariant['translations']['en_US']['name'], $variantName); + } + + /** + * @Then the last variant in the list should have name :variantName + */ + public function theLastVariantInTheListShouldHaveName(string $variantName): void + { + $product = $this->sharedStorage->get('product'); + $this->iWantToViewAllVariantsOfThisProduct($product); + $variants = $this->responseChecker->getCollection($this->client->getLastResponse()); + + $lastVariant = end($variants); + + $this->assertProductVariantName($lastVariant['translations']['en_US']['name'], $variantName); + } + + private function assertProductVariantName(string $variantName, string $expectedVariantName): void + { + Assert::same( + $variantName, + $expectedVariantName, + sprintf( + 'Expected product variant to have name "%s", but it is named "%s".', + $expectedVariantName, + $variantName, + ), + ); + } } diff --git a/src/Sylius/Behat/Resources/config/services/contexts/api/admin.xml b/src/Sylius/Behat/Resources/config/services/contexts/api/admin.xml index 6ef0d9482b47..77fda82fece8 100644 --- a/src/Sylius/Behat/Resources/config/services/contexts/api/admin.xml +++ b/src/Sylius/Behat/Resources/config/services/contexts/api/admin.xml @@ -142,6 +142,7 @@ +