From cc137a567c908513c82979c9c0c4be2c4fd4d967 Mon Sep 17 00:00:00 2001 From: Rafikooo Date: Wed, 26 Apr 2023 18:02:03 +0200 Subject: [PATCH] [API][Behat][Taxon] Add step implementation --- .../managing_taxons/deleting_taxon.feature | 2 +- .../Api/Admin/ManagingProductsContext.php | 8 +++++++ .../Behat/Context/Setup/ProductContext.php | 23 +++++++++++++------ .../Behat/Context/Setup/TaxonomyContext.php | 7 +----- .../suites/api/taxon/managing_taxons.yml | 9 ++++++-- 5 files changed, 33 insertions(+), 16 deletions(-) diff --git a/features/taxonomy/managing_taxons/deleting_taxon.feature b/features/taxonomy/managing_taxons/deleting_taxon.feature index 727aad15b1..40c28596a8 100644 --- a/features/taxonomy/managing_taxons/deleting_taxon.feature +++ b/features/taxonomy/managing_taxons/deleting_taxon.feature @@ -32,7 +32,7 @@ Feature: Deleting a taxon When I try to delete taxon named "Caps" Then I should be notified that I cannot delete a menu taxon of any channel - @todo + @api Scenario: Deleting a taxon that is a main taxon of a product Given the store classifies its products as "T-Shirts" And the store has a product "T-Shirts PHP" diff --git a/src/Sylius/Behat/Context/Api/Admin/ManagingProductsContext.php b/src/Sylius/Behat/Context/Api/Admin/ManagingProductsContext.php index 297f59e9ed..a4724496ce 100644 --- a/src/Sylius/Behat/Context/Api/Admin/ManagingProductsContext.php +++ b/src/Sylius/Behat/Context/Api/Admin/ManagingProductsContext.php @@ -362,6 +362,14 @@ final class ManagingProductsContext implements Context Assert::same($mainTaxon, $this->iriConverter->getIriFromItem($taxon)); } + /** + * @Then the product :product should no longer have a main taxon + */ + public function theProductShouldNoLongerHaveAMainTaxon(ProductInterface $product): void + { + Assert::null($product->getMainTaxon()); + } + /** * @Then the product :product should have the :taxon taxon */ diff --git a/src/Sylius/Behat/Context/Setup/ProductContext.php b/src/Sylius/Behat/Context/Setup/ProductContext.php index 11eae9dca8..a089eb4f1c 100644 --- a/src/Sylius/Behat/Context/Setup/ProductContext.php +++ b/src/Sylius/Behat/Context/Setup/ProductContext.php @@ -89,7 +89,7 @@ final class ProductContext implements Context */ public function storeHasAProductPricedAtBelongingToTheTaxon( string $productName, - int $price = 100, + int $price, TaxonInterface $taxon, ): void { $product = $this->createProduct($productName, $price); @@ -98,6 +98,20 @@ final class ProductContext implements Context $this->saveProduct($product); } + /** + * @Given /^the store(?:| also) has a product "([^"]+)" belonging to the ("[^"]+" taxon)$/ + * @Given /^the store(?:| also) has a product "([^"]+)" belonging to (this taxon)$/ + */ + public function storeHasAProductBelongingToTheTaxon( + string $productName, + TaxonInterface $taxon, + ): void { + $product = $this->createProduct($productName); + $this->productTaxonContext->itBelongsTo($product, $taxon); + + $this->saveProduct($product); + } + /** * @Given the store has :numberOfProducts products */ @@ -1293,12 +1307,7 @@ final class ProductContext implements Context return (int) round((float) str_replace(['€', '£', '$'], '', $price) * 100, 2); } - /** - * @param string $productName - * - * @return ProductInterface - */ - private function createProduct($productName, int $price = 100, ChannelInterface $channel = null) + private function createProduct(string $productName, int $price = 100, ChannelInterface $channel = null): ProductInterface { if (null === $channel && $this->sharedStorage->has('channel')) { $channel = $this->sharedStorage->get('channel'); diff --git a/src/Sylius/Behat/Context/Setup/TaxonomyContext.php b/src/Sylius/Behat/Context/Setup/TaxonomyContext.php index c776d3a21b..105ac8a2c0 100644 --- a/src/Sylius/Behat/Context/Setup/TaxonomyContext.php +++ b/src/Sylius/Behat/Context/Setup/TaxonomyContext.php @@ -122,12 +122,7 @@ final class TaxonomyContext implements Context $this->objectManager->flush(); } - /** - * @param string $name - * - * @return TaxonInterface - */ - private function createTaxon($name) + private function createTaxon(string $name): TaxonInterface { /** @var TaxonInterface $taxon */ $taxon = $this->taxonFactory->createNew(); diff --git a/src/Sylius/Behat/Resources/config/suites/api/taxon/managing_taxons.yml b/src/Sylius/Behat/Resources/config/suites/api/taxon/managing_taxons.yml index 03b00cffac..13b0f228c0 100644 --- a/src/Sylius/Behat/Resources/config/suites/api/taxon/managing_taxons.yml +++ b/src/Sylius/Behat/Resources/config/suites/api/taxon/managing_taxons.yml @@ -8,12 +8,17 @@ default: - sylius.behat.context.hook.doctrine_orm - sylius.behat.context.transform.channel + - sylius.behat.context.transform.product + - sylius.behat.context.transform.shared_storage - sylius.behat.context.transform.taxon - - sylius.behat.context.setup.channel - - sylius.behat.context.setup.taxonomy - sylius.behat.context.setup.admin_api_security + - sylius.behat.context.setup.channel + - sylius.behat.context.setup.product + - sylius.behat.context.setup.product_taxon + - sylius.behat.context.setup.taxonomy + - sylius.behat.context.api.admin.managing_products - sylius.behat.context.api.admin.managing_taxons filters: tags: "@managing_taxons&&@api"