From f8222e5a4c834d1ed3adee95eae4492f1093cf5d Mon Sep 17 00:00:00 2001 From: Kamil Grygierzec Date: Thu, 19 Oct 2023 09:32:54 +0200 Subject: [PATCH] [Behat] Add api tag to managing channel scenarios --- .../managing_channels/adding_channel.feature | 4 +- ...ing_channel_with_shop_billing_data.feature | 2 +- .../browsing_channels.feature | 2 +- .../channel_unique_code_validation.feature | 2 +- .../channel_validation.feature | 10 +- .../deleting_channel.feature | 2 +- .../managing_channels/editing_channel.feature | 22 +- .../editing_menu_taxon_on_channel.feature | 2 +- ...iting_shop_billing_data_on_channel.feature | 16 +- ...sabled_channel_when_no_other_exist.feature | 4 +- ...e_to_delete_last_available_channel.feature | 4 +- ..._to_disable_last_available_channel.feature | 2 +- ...g_currencies_available_for_channel.feature | 8 +- ...cting_default_tax_zone_for_channel.feature | 8 +- ...ting_locales_available_for_channel.feature | 17 +- ...x_calculation_strategy_for_channel.feature | 5 +- .../toggling_channel.feature | 4 +- .../ManagingChannelsBillingDataContext.php | 83 ++++ .../Api/Admin/ManagingChannelsContext.php | 424 +++++++++++++++++- .../Api/Admin/ManagingProductsContext.php | 26 +- .../ManagingChannelsBillingDataContext.php | 17 + .../Ui/Admin/ManagingChannelsContext.php | 8 +- .../config/services/contexts/api/admin.xml | 6 + .../suites/api/channel/managing_channels.yml | 1 + 24 files changed, 604 insertions(+), 75 deletions(-) create mode 100644 src/Sylius/Behat/Context/Api/Admin/ManagingChannelsBillingDataContext.php diff --git a/features/channel/managing_channels/adding_channel.feature b/features/channel/managing_channels/adding_channel.feature index aa48daf64c..32265b9a97 100644 --- a/features/channel/managing_channels/adding_channel.feature +++ b/features/channel/managing_channels/adding_channel.feature @@ -10,7 +10,7 @@ Feature: Adding a new channel And the store operates in "United States" and "Poland" And I am logged in as an administrator - @ui @api + @api @ui Scenario: Adding a new channel When I want to create a new channel And I specify its code as "MOBILE" @@ -23,7 +23,7 @@ Feature: Adding a new channel Then I should be notified that it has been successfully created And the channel "Mobile channel" should appear in the registry - @ui @api + @api @ui Scenario: Adding a new channel with additional fields When I want to create a new channel And I specify its code as "MOBILE" diff --git a/features/channel/managing_channels/adding_channel_with_shop_billing_data.feature b/features/channel/managing_channels/adding_channel_with_shop_billing_data.feature index dd3e351a7f..cb405a8382 100644 --- a/features/channel/managing_channels/adding_channel_with_shop_billing_data.feature +++ b/features/channel/managing_channels/adding_channel_with_shop_billing_data.feature @@ -10,7 +10,7 @@ Feature: Adding a new channel with shop billing data And the store operates in "United States" And I am logged in as an administrator - @ui @api + @api @ui Scenario: Adding a new channel with shop billing data When I want to create a new channel And I specify its code as "MOBILE" diff --git a/features/channel/managing_channels/browsing_channels.feature b/features/channel/managing_channels/browsing_channels.feature index f95b116ae0..070993551b 100644 --- a/features/channel/managing_channels/browsing_channels.feature +++ b/features/channel/managing_channels/browsing_channels.feature @@ -9,7 +9,7 @@ Feature: Browsing channels And the store operates on another channel named "Mobile Channel" And I am logged in as an administrator - @ui @api + @api @ui Scenario: Browsing defined channels When I want to browse channels Then I should see 2 channels in the list diff --git a/features/channel/managing_channels/channel_unique_code_validation.feature b/features/channel/managing_channels/channel_unique_code_validation.feature index f8b6e62cff..47d6543623 100644 --- a/features/channel/managing_channels/channel_unique_code_validation.feature +++ b/features/channel/managing_channels/channel_unique_code_validation.feature @@ -8,7 +8,7 @@ Feature: Channel unique code validation Given the store operates on a channel identified by "WEB" code And I am logged in as an administrator - @ui + @api @ui Scenario: Trying to add channel with taken code When I want to create a new channel And I specify its code as "WEB" diff --git a/features/channel/managing_channels/channel_validation.feature b/features/channel/managing_channels/channel_validation.feature index fe45e18b4b..766a3a4a2c 100644 --- a/features/channel/managing_channels/channel_validation.feature +++ b/features/channel/managing_channels/channel_validation.feature @@ -7,7 +7,7 @@ Feature: Channel validation Background: Given I am logged in as an administrator - @ui + @api @ui Scenario: Trying to add a new channel without specifying its code When I want to create a new channel And I name it "Mobile channel" @@ -16,7 +16,7 @@ Feature: Channel validation Then I should be notified that code is required And channel with name "Mobile channel" should not be added - @ui + @api @ui Scenario: Trying to add a new channel without specifying its name When I want to create a new channel And I specify its code as "MOBILE" @@ -25,7 +25,7 @@ Feature: Channel validation Then I should be notified that name is required And channel with code "MOBILE" should not be added - @ui + @api @ui Scenario: Trying to add a new channel without base currency When I want to create a new channel And I specify its code as "MOBILE" @@ -34,7 +34,7 @@ Feature: Channel validation Then I should be notified that base currency is required And channel with code "MOBILE" should not be added - @ui + @api @ui Scenario: Trying to add a new channel without default locale When I want to create a new channel And I specify its code as "MOBILE" @@ -43,7 +43,7 @@ Feature: Channel validation Then I should be notified that default locale is required And channel with code "MOBILE" should not be added - @ui + @api @ui Scenario: Trying to remove name from existing channel Given the store operates on a channel named "Web Channel" When I want to modify this channel diff --git a/features/channel/managing_channels/deleting_channel.feature b/features/channel/managing_channels/deleting_channel.feature index 372e70c0eb..fb2976984b 100644 --- a/features/channel/managing_channels/deleting_channel.feature +++ b/features/channel/managing_channels/deleting_channel.feature @@ -9,7 +9,7 @@ Feature: Deleting a channel And the store operates on another channel named "Mobile Store" And I am logged in as an administrator - @ui + @api @ui Scenario: Deleted channel should disappear from the registry When I delete channel "Web Store" Then I should be notified that it has been successfully deleted diff --git a/features/channel/managing_channels/editing_channel.feature b/features/channel/managing_channels/editing_channel.feature index 4a011b1f75..42e7fa0046 100644 --- a/features/channel/managing_channels/editing_channel.feature +++ b/features/channel/managing_channels/editing_channel.feature @@ -8,20 +8,12 @@ Feature: Editing channel Given the store operates on a channel named "Web Channel" And I am logged in as an administrator - @todo - Scenario: Trying to change channel code + @api @ui + Scenario: Being unable to change the code of an existing channel When I want to modify a channel "Web Channel" - And I change its code to "MOBILE" - And I save my changes - Then I should be notified that code cannot be changed - And channel "Web Channel" should still have code "MOBILE" + Then I should not be able to edit its code - @ui - Scenario: Seeing disabled code field when editing channel - When I want to modify a channel "Web Channel" - Then the code field should be disabled - - @ui + @api @ui Scenario: Renaming the channel When I want to modify a channel "Web Channel" And I rename it to "Website store" @@ -29,7 +21,7 @@ Feature: Editing channel Then I should be notified that it has been successfully edited And this channel name should be "Website store" - @ui - Scenario: Seeing disabled base currency field during channel edition + @api @ui + Scenario: Being unable to change base currency of an existing channel When I want to modify a channel "Web Channel" - Then the base currency field should be disabled + Then I should not be able to edit its base currency diff --git a/features/channel/managing_channels/editing_menu_taxon_on_channel.feature b/features/channel/managing_channels/editing_menu_taxon_on_channel.feature index bb32cbf8b5..e0440d57a1 100644 --- a/features/channel/managing_channels/editing_menu_taxon_on_channel.feature +++ b/features/channel/managing_channels/editing_menu_taxon_on_channel.feature @@ -11,7 +11,7 @@ Feature: Editing menu taxon on channel And channel "Web Store" has menu taxon "Clothes" And I am logged in as an administrator - @ui @javascript + @api @ui @javascript Scenario: Editing menu taxon on the channel When I want to modify a channel "Web Store" And I change its menu taxon to "Guns" diff --git a/features/channel/managing_channels/editing_shop_billing_data_on_channel.feature b/features/channel/managing_channels/editing_shop_billing_data_on_channel.feature index 801ae49a6e..d1bb24601a 100644 --- a/features/channel/managing_channels/editing_shop_billing_data_on_channel.feature +++ b/features/channel/managing_channels/editing_shop_billing_data_on_channel.feature @@ -10,14 +10,20 @@ Feature: Editing shop billing data on channel And channel "Web Store" billing data is "Ragnarok", "Pacific Coast Hwy", "90806" "Los Angeles", "United States" with "1100110011" tax ID And I am logged in as an administrator - @ui + @api @ui Scenario: Editing shop billing data on channel When I want to modify a channel "Web Store" - And I specify company as "Götterdämmerung" - And I specify tax ID as "666777" - And I specify shop billing address as "Valhalla", "123" "Asgard", "United States" + And I specify shop billing data for this channel as "Götterdämmerung", "Valhalla", "123", "Asgard", "666777" tax ID and "United States" country And I save my changes Then I should be notified that it has been successfully edited And this channel company should be "Götterdämmerung" And this channel tax ID should be "666777" - And this channel shop billing address should be "Valhalla", "123" "Asgard", "United States" + And this channel shop billing address should be "Valhalla", "123" "Asgard" and "United States" country + + @api @no-ui + Scenario: Editing shop billing data with wrong country code + When I want to modify a channel "Web Store" + And I specify new country code for this channel as "ZZ" + And I save my changes + Then I should be notified that it is not a valid country + And this channel shop billing address should still be "Pacific Coast Hwy", "90806" "Los Angeles" and "United States" country diff --git a/features/channel/managing_channels/not_being_able_to_add_disabled_channel_when_no_other_exist.feature b/features/channel/managing_channels/not_being_able_to_add_disabled_channel_when_no_other_exist.feature index c9d19fd580..31f2cb450e 100644 --- a/features/channel/managing_channels/not_being_able_to_add_disabled_channel_when_no_other_exist.feature +++ b/features/channel/managing_channels/not_being_able_to_add_disabled_channel_when_no_other_exist.feature @@ -9,8 +9,8 @@ Feature: Not being able to add a disabled channel when no other exist And the store has locale "English (United States)" And I am logged in as an administrator - @ui - Scenario: Adding a new disabled channel should result + @api @ui + Scenario: Trying to add a new disabled channel when no other exist When I want to create a new channel And I specify its code as "MOBILE" And I name it "Mobile channel" diff --git a/features/channel/managing_channels/not_being_able_to_delete_last_available_channel.feature b/features/channel/managing_channels/not_being_able_to_delete_last_available_channel.feature index e30a65d27c..f46c66cb40 100644 --- a/features/channel/managing_channels/not_being_able_to_delete_last_available_channel.feature +++ b/features/channel/managing_channels/not_being_able_to_delete_last_available_channel.feature @@ -8,8 +8,8 @@ Feature: Not being able to delete a last available channel Given the store operates on a channel named "Web Store" And I am logged in as an administrator - @ui - Scenario: Prevented from deleting only channel + @api @ui + Scenario: Preventing from deleting only channel When I delete channel "Web Store" Then I should be notified that it cannot be deleted And this channel should still be in the registry diff --git a/features/channel/managing_channels/not_being_able_to_disable_last_available_channel.feature b/features/channel/managing_channels/not_being_able_to_disable_last_available_channel.feature index bb95ad1290..b7e302c4b4 100644 --- a/features/channel/managing_channels/not_being_able_to_disable_last_available_channel.feature +++ b/features/channel/managing_channels/not_being_able_to_disable_last_available_channel.feature @@ -8,7 +8,7 @@ Feature: Toggling a channel Given the store operates on a channel named "Web Channel" And I am logged in as an administrator - @ui + @api @ui Scenario: Disabling the last available channel Given the channel "Web Channel" is enabled When I want to modify this channel diff --git a/features/channel/managing_channels/selecting_currencies_available_for_channel.feature b/features/channel/managing_channels/selecting_currencies_available_for_channel.feature index b478e47268..339b63a728 100644 --- a/features/channel/managing_channels/selecting_currencies_available_for_channel.feature +++ b/features/channel/managing_channels/selecting_currencies_available_for_channel.feature @@ -7,20 +7,24 @@ Feature: Selecting available currencies for a channel Background: Given the store has currency "Euro" And the store has locale "English (United States)" + And the store operates in "United States" And I am logged in as an administrator - @ui + @api @ui Scenario: Adding a new channel with currencies When I want to create a new channel And I specify its code as MOBILE + And I choose "Euro" as the base currency And I name it "Mobile store" And I allow for paying in "Euro" + And I make it available in "English (United States)" And I choose "English (United States)" as a default locale + And I select the "Order items based" as tax calculation strategy And I add it Then I should be notified that it has been successfully created And paying in Euro should be possible for the "Mobile store" channel - @ui + @api @ui Scenario: Adding currencies to an existing channel Given the store operates on a channel named "Web store" When I want to modify this channel diff --git a/features/channel/managing_channels/selecting_default_tax_zone_for_channel.feature b/features/channel/managing_channels/selecting_default_tax_zone_for_channel.feature index 891dcd70ae..bc3e2ef5db 100644 --- a/features/channel/managing_channels/selecting_default_tax_zone_for_channel.feature +++ b/features/channel/managing_channels/selecting_default_tax_zone_for_channel.feature @@ -8,19 +8,21 @@ Feature: Selecting default tax zone for a channel Given the store operates on a single channel in "United States" And I am logged in as an administrator - @ui + @api @ui Scenario: Adding a new channel with default tax zone When I want to create a new channel And I specify its code as "MOBILE" And I name it "Mobile store" And I select the "United States" as default tax zone And I choose "USD" as the base currency + And I make it available in "English (United States)" And I choose "English (United States)" as a default locale + And I select the "Order items based" as tax calculation strategy And I add it Then I should be notified that it has been successfully created And the default tax zone for the "Mobile store" channel should be "United States" - @ui + @api @ui Scenario: Selecting default tax zone for existing channel Given the store operates on a channel named "Web store" When I want to modify this channel @@ -29,7 +31,7 @@ Feature: Selecting default tax zone for a channel Then I should be notified that it has been successfully edited And the default tax zone for the "Web store" channel should be "United States" - @ui + @api @ui Scenario: Removing existing channel default tax zone Given the store operates on a channel named "Web store" And its default tax zone is zone "US" diff --git a/features/channel/managing_channels/selecting_locales_available_for_channel.feature b/features/channel/managing_channels/selecting_locales_available_for_channel.feature index 25afdd3ff9..1c17675e3a 100644 --- a/features/channel/managing_channels/selecting_locales_available_for_channel.feature +++ b/features/channel/managing_channels/selecting_locales_available_for_channel.feature @@ -9,7 +9,7 @@ Feature: Selecting available locales for a channel And the store has locale "English (United States)" And I am logged in as an administrator - @ui + @api @ui Scenario: Adding a new channel with locales When I want to create a new channel And I specify its code as "MOBILE" @@ -17,11 +17,12 @@ Feature: Selecting available locales for a channel And I make it available in "English (United States)" And I choose "Euro" as the base currency And I choose "English (United States)" as a default locale + And I select the "Order items based" as tax calculation strategy And I add it Then I should be notified that it has been successfully created And the channel "Mobile Channel" should be available in "English (United States)" - @ui + @api @ui Scenario: Adding locales to an existing channel Given the store operates on a channel named "Web Channel" When I want to modify this channel @@ -30,23 +31,23 @@ Feature: Selecting available locales for a channel Then I should be notified that it has been successfully edited And the channel "Web Channel" should be available in "English (United States)" - @ui + @api @ui Scenario: Being unable to disable locale used as the default one for a channel Given the store operates on a channel named "Web" And this channel allows to shop using "English (United States)" and "Polish (Poland)" locales And this channel uses the "English (United States)" locale as default - And I am modifying a channel "Web" - When I make it available only in "Polish (Poland)" + When I want to modify this channel + And I make it available only in "Polish (Poland)" And I try to save my changes Then I should be notified that the default locale has to be enabled - @ui + @api @ui Scenario: Being unable to set disabled locale as a default one for a channel Given the store has locale "Polish (Poland)" And the store operates on a channel named "Web" And this channel allows to shop using the "English (United States)" locale And this channel uses the "English (United States)" locale as default - And I am modifying a channel "Web" - When I choose "Polish (Poland)" as a default locale + When I want to modify this channel + And I choose "Polish (Poland)" as a default locale And I try to save my changes Then I should be notified that the default locale has to be enabled diff --git a/features/channel/managing_channels/selecting_tax_calculation_strategy_for_channel.feature b/features/channel/managing_channels/selecting_tax_calculation_strategy_for_channel.feature index ff8f6bac6f..8b2d560df7 100644 --- a/features/channel/managing_channels/selecting_tax_calculation_strategy_for_channel.feature +++ b/features/channel/managing_channels/selecting_tax_calculation_strategy_for_channel.feature @@ -20,19 +20,20 @@ Feature: Selecting tax calculation strategy for a channel Then I should be notified that it has been successfully created And the tax calculation strategy for the "Mobile store" channel should be "Order items based" - @ui + @api @ui Scenario: Adding a new channel with tax calculation strategy When I want to create a new channel And I specify its code as "MOBILE" And I select the "Order item units based" as tax calculation strategy And I name it "Mobile store" And I choose "Euro" as the base currency + And I make it available in "English (United States)" And I choose "English (United States)" as a default locale And I add it Then I should be notified that it has been successfully created And the tax calculation strategy for the "Mobile store" channel should be "Order item units based" - @ui + @api @ui Scenario: Changing tax calculation strategy of existing channel Given the store operates on a channel named "Web store" When I want to modify this channel diff --git a/features/channel/managing_channels/toggling_channel.feature b/features/channel/managing_channels/toggling_channel.feature index 41875817f1..92d88bc4d0 100644 --- a/features/channel/managing_channels/toggling_channel.feature +++ b/features/channel/managing_channels/toggling_channel.feature @@ -9,7 +9,7 @@ Feature: Toggling a channel And the store operates on another channel named "Mobile Channel" And I am logged in as an administrator - @ui + @api @ui Scenario: Disabling the channel Given the channel "Web Channel" is enabled When I want to modify this channel @@ -18,7 +18,7 @@ Feature: Toggling a channel Then I should be notified that it has been successfully edited And this channel should be disabled - @ui + @api @ui Scenario: Enabling the channel Given the channel "Web Channel" is disabled When I want to modify this channel diff --git a/src/Sylius/Behat/Context/Api/Admin/ManagingChannelsBillingDataContext.php b/src/Sylius/Behat/Context/Api/Admin/ManagingChannelsBillingDataContext.php new file mode 100644 index 0000000000..02ff55114c --- /dev/null +++ b/src/Sylius/Behat/Context/Api/Admin/ManagingChannelsBillingDataContext.php @@ -0,0 +1,83 @@ +getShopBillingDataFromChannel($channel); + + Assert::same($shopBillingData->getCompany(), $company); + } + + /** + * @Then /^(this channel) tax ID should be "([^"]+)"$/ + */ + public function thisChanneTaxIdShouldBe(ChannelInterface $channel, string $taxId): void + { + $shopBillingData = $this->getShopBillingDataFromChannel($channel); + + Assert::same($shopBillingData->getTaxId(), $taxId); + } + + /** + * @Then /^(this channel) shop billing address should be "([^"]+)", "([^"]+)" "([^"]+)" and ("([^"]+)" country)$/ + * @Then /^(this channel) shop billing address should still be "([^"]+)", "([^"]+)" "([^"]+)" and ("([^"]+)" country)$/ + */ + public function thisChannelShopBillingAddressShouldBe( + ChannelInterface $channel, + string $street, + string $postcode, + string $city, + CountryInterface $country, + ): void { + $shopBillingData = $this->getShopBillingDataFromChannel($channel); + + Assert::same($shopBillingData->getStreet(), $street); + Assert::same($shopBillingData->getPostcode(), $postcode); + Assert::same($shopBillingData->getCity(), $city); + Assert::same($shopBillingData->getCountryCode(), $country->getCode()); + } + + private function getShopBillingDataFromChannel(ChannelInterface $channel): ShopBillingDataInterface + { + $this->client->show(Resources::CHANNELS, $channel->getCode()); + + /** @var ShopBillingDataInterface $shopBillingData */ + $shopBillingData = $this->iriConverter->getResourceFromIri($this->responseChecker->getValue($this->client->getLastResponse(), 'shopBillingData')); + + return $shopBillingData; + } +} diff --git a/src/Sylius/Behat/Context/Api/Admin/ManagingChannelsContext.php b/src/Sylius/Behat/Context/Api/Admin/ManagingChannelsContext.php index b1dee20e63..069b193980 100644 --- a/src/Sylius/Behat/Context/Api/Admin/ManagingChannelsContext.php +++ b/src/Sylius/Behat/Context/Api/Admin/ManagingChannelsContext.php @@ -20,6 +20,7 @@ use Sylius\Behat\Client\ResponseCheckerInterface; use Sylius\Behat\Context\Api\Resources; use Sylius\Behat\Service\Converter\SectionAwareIriConverterInterface; use Sylius\Component\Addressing\Model\CountryInterface; +use Sylius\Component\Addressing\Model\ZoneInterface; use Sylius\Component\Core\Formatter\StringInflector; use Sylius\Component\Core\Model\ChannelInterface; use Sylius\Component\Core\Model\TaxonInterface; @@ -47,6 +48,14 @@ final class ManagingChannelsContext implements Context $this->client->buildCreateRequest(Resources::CHANNELS); } + /** + * @When I delete channel :channel + */ + public function iDeleteChannel(ChannelInterface $channel): void + { + $this->client->delete(Resources::CHANNELS, $channel->getCode()); + } + /** * @When I want to modify a channel :channel */ @@ -55,23 +64,78 @@ final class ManagingChannelsContext implements Context $this->client->buildUpdateRequest(Resources::CHANNELS, $channel->getCode()); } + /** + * @When I rename it to :name + * @When I do not name it + * @When I remove its name + */ + public function iRenameIt(string $name = ''): void + { + $this->client->addRequestData('name', $name); + } + + /** + * @When /^I (enable|disable) it$/ + */ + public function iDisableIt(string $toggleAction): void + { + $this->client->addRequestData('enabled', $toggleAction === 'enable'); + } + + /** + * @When I change its menu taxon to :taxon + */ + public function iChangeItsMenuTaxonTo(TaxonInterface $taxon): void + { + $this->client->addRequestData('menuTaxon', $this->sectionAwareIriConverter->getIriFromResourceInSection($taxon, 'admin')); + } + /** * @When I specify its :field as :value * @When I :field it :value * @When I set its :field as :value * @When I define its :field as :value + * @When I do not specify its :field */ - public function iSpecifyItsAs(string $field, string $value): void + public function iSpecifyItsAs(string $field, string $value = ''): void { $this->client->addRequestData($field, $value); } /** * @When I choose :currency as the base currency + * @When I do not choose base currency */ - public function iChooseAsTheBaseCurrency(CurrencyInterface $currency): void + public function iChooseAsTheBaseCurrency(?CurrencyInterface $currency = null): void { - $this->client->addRequestData('baseCurrency', $this->sectionAwareIriConverter->getIriFromResourceInSection($currency, 'admin')); + $this->client->addRequestData( + 'baseCurrency', + null === $currency ? $currency : $this->sectionAwareIriConverter->getIriFromResourceInSection($currency, 'admin'), + ); + } + + /** + * @When I allow for paying in :currency + */ + public function iAllowToPayingForThisChannel(CurrencyInterface $currency): void + { + $this->client->addRequestData('currencies', [$this->iriConverter->getIriFromResource($currency)]); + } + + /** + * @When I select the :zone as default tax zone + */ + public function iSelectDefaultTaxZone(ZoneInterface $zone): void + { + $this->client->addRequestData('defaultTaxZone', $this->iriConverter->getIriFromResource($zone)); + } + + /** + * @When I remove its default tax zone + */ + public function iRemoveItsDefaultTaxZone(): void + { + $this->client->addRequestData('defaultTaxZone', null); } /** @@ -79,15 +143,29 @@ final class ManagingChannelsContext implements Context */ public function iMakeItAvailableInLocale(LocaleInterface $locale): void { - $this->client->addRequestData('locales', [$this->iriConverter->getIriFromResource($locale)]); + $this->client->addRequestData('locales', [$this->sectionAwareIriConverter->getIriFromResourceInSection($locale, 'admin')]); + } + + /** + * @When I make it available only in :locale + */ + public function iMakeItAvailableOnlyInLocale(LocaleInterface $locale): void + { + $this->client->addRequestData('locales', [ + $this->sectionAwareIriConverter->getIriFromResourceInSection($locale, 'admin'), + ]); } /** * @When I choose :locale as a default locale + * @When I do not choose default locale */ - public function iChooseAsADefaultLocale(LocaleInterface $locale): void + public function iChooseAsADefaultLocale(?LocaleInterface $locale = null): void { - $this->client->addRequestData('defaultLocale', $this->sectionAwareIriConverter->getIriFromResourceInSection($locale, 'admin')); + $this->client->addRequestData( + 'defaultLocale', + null === $locale ? $locale : $this->sectionAwareIriConverter->getIriFromResourceInSection($locale, 'admin'), + ); } /** @@ -165,6 +243,42 @@ final class ManagingChannelsContext implements Context $this->shopBillingData['taxId'] = $taxId; } + /** + * @When /^I specify shop billing data for (this channel) as "([^"]+)", "([^"]+)", "([^"]+)", "([^"]+)", "([^"]+)" tax ID and ("([^"]+)" country)$/ + */ + public function iSpecifyShopBillingDataAs( + ChannelInterface $channel, + string $company, + string $street, + string $postcode, + string $city, + string $taxId, + CountryInterface $country, + ): void { + $shopBillingDataId = $this->iriConverter->getIriFromResource($channel->getShopBillingData()); + + $this->client->addRequestData('shopBillingData', [ + '@id' => $shopBillingDataId, + 'company' => $company, + 'street' => $street, + 'postcode' => $postcode, + 'city' => $city, + 'countryCode' => $country->getCode(), + 'taxId' => $taxId + ] + ); + } + + /** + * @When /^I specify new country code for (this channel) as "([^"]+)"$/ + */ + public function iSpecifyNewCountryCodeForThisChannelAs(ChannelInterface $channel, string $code): void + { + $shopBillingDataId = $this->iriConverter->getIriFromResource($channel->getShopBillingData()); + + $this->client->addRequestData('shopBillingData', ['@id' => $shopBillingDataId, 'countryCode' => $code]); + } + /** * @When I specify shop billing address as :street, :postcode :city, :country */ @@ -180,6 +294,15 @@ final class ManagingChannelsContext implements Context $this->shopBillingData['countryCode'] = $country->getCode(); } + /** + * @Then I save it + */ + public function iSaveIt(): void + { + $this->iAddIt(); + $this->client->update(); + } + /** * @When I select the :taxCalculationStrategy as tax calculation strategy */ @@ -280,6 +403,74 @@ final class ManagingChannelsContext implements Context ); } + /** + * @Then I should not be able to edit its code + */ + public function iShouldNotBeAbleToEditItsCode(): void + { + $this->client->updateRequestData(['code' => 'NEW_CODE']); + + Assert::false($this->responseChecker->hasValue($this->client->update(), 'code', 'NEW_CODE')); + } + + /** + * @Then the base currency field should be disabled + * @Then I should not be able to edit its base currency + */ + public function theBaseCurrencyFieldShouldBeDisabled(): void + { + $this->client->updateRequestData(['baseCurrency' => 'PLN']); + + Assert::false($this->responseChecker->hasValue($this->client->update(), 'baseCurrency', 'PLN')); + } + + /** + * @Then /^(this channel) name should be "([^"]*)"$/ + */ + public function thisChannelNameShouldBe(ChannelInterface $channel, string $name): void + { + Assert::true( + $this->responseChecker->hasValue($this->client->show(Resources::CHANNELS, $channel->getCode()), 'name', $name), + sprintf('Its Channel does not have name %s.', $name), + ); + } + + /** + * @Then the :channel channel should no longer exist in the registry + */ + public function theChannelShouldNoLongerExistInTheRegistry(string $name): void + { + Assert::false( + $this->responseChecker->hasItemWithValue($this->client->index(Resources::CHANNELS), 'name', $name), + sprintf('Channel with name %s exists', $name), + ); + } + + /** + * @Then I should be notified that it has been successfully deleted + */ + public function iShouldBeNotifiedThatChannelHasBeenDeleted(): void + { + Assert::true($this->responseChecker->isDeletionSuccessful($this->client->getLastResponse())); + } + + /** + * @Then /^(this channel) menu (taxon should be "([^"]+)")$/ + */ + public function thisChannelMenuTaxonShouldBe(ChannelInterface $channel, TaxonInterface $taxon): void + { + Assert::true( + $this->responseChecker->hasValue( + $this->client->show( + Resources::CHANNELS, + $channel->getCode(), + ), + 'menuTaxon', + $this->sectionAwareIriConverter->getIriFromResourceInSection($taxon, 'admin'), + ), + ); + } + /** * @Then I should see :count channels in the list */ @@ -299,4 +490,225 @@ final class ManagingChannelsContext implements Context $type === 'shipping', )); } + + /** + * @Then I should be notified that it cannot be deleted + */ + public function iShouldBeNotifiedThatItCannotBeDeleted(): void + { + Assert::contains( + $this->responseChecker->getError($this->client->getLastResponse()), + 'The channel cannot be deleted. At least one enabled channel is required.', + ); + } + + /** + * @Then I should be notified that at least one channel has to be defined + */ + public function iShouldBeNotifiedThatAtLeastOneChannelHasToBeDefined(): void + { + Assert::contains( + $this->responseChecker->getError($this->client->getLastResponse()), + 'Must have at least one enabled entity', + ); + } + + /** + * @Then channel with name :channel should still be enabled + * @Then /^(this channel) should be enabled$/ + */ + public function channelWithNameShouldStillBeEnabled(ChannelInterface $channel): void + { + Assert::true( + $this->responseChecker->hasValue($this->client->show(Resources::CHANNELS, $channel->getCode()), 'enabled', true), + sprintf('Channel with name %s does not exists', $channel->getName()), + ); + } + + /** + * @Then this channel should still be named :channel + */ + public function thisChannelShouldStillBeNamed(ChannelInterface $channel): void + { + Assert::true( + $this->responseChecker->hasValue($this->client->show(Resources::CHANNELS, $channel->getCode()), 'name', $channel->getName()), + sprintf('Channel with name %s does not exists', $channel->getName()), + ); + } + + /** + * @Then paying in :currency should be possible for the :channel channel + */ + public function payingInCurrencyShouldBePossibleForTheChannel(CurrencyInterface $currency, ChannelInterface $channel): void + { + $currencies = $this->responseChecker->getValue( + $this->client->show(Resources::CHANNELS, $channel->getCode()), + 'currencies', + ); + + Assert::true(in_array($this->sectionAwareIriConverter->getIriFromResourceInSection($currency, 'admin'), $currencies)); + } + + /** + * @Then channel :channel should not have default tax zone + */ + public function channelShouldNotHaveDefaultTaxZone(ChannelInterface $channel): void + { + Assert::same( + $this->responseChecker->getValue($this->client->show(Resources::CHANNELS, $channel->getCode()), 'defaultTaxZone'), + null, + sprintf('Channel %s has default tax zone', $channel->getName()), + ); + } + + /** + * @Then the default tax zone for the :channel channel should be :zone + */ + public function theDefaultTaxZoneForTheChannelShouldBe(ChannelInterface $channel, ZoneInterface $zone): void + { + Assert::same( + $this->responseChecker->getValue($this->client->show(Resources::CHANNELS, $channel->getCode()), 'defaultTaxZone'), + $this->sectionAwareIriConverter->getIriFromResourceInSection($zone, 'admin'), + sprintf('Channel %s does not have %s default tax zone', $channel->getName(), $zone), + ); + } + + /** + * @Then the channel :channel should be available in :locale + */ + public function theChannelShouldBeAvailableIn(ChannelInterface $channel, LocaleInterface $locale): void + { + $locales = $this->responseChecker->getValue( + $this->client->show(Resources::CHANNELS, $channel->getCode()), + 'locales', + ); + + Assert::true(in_array($this->sectionAwareIriConverter->getIriFromResourceInSection($locale, 'admin'), $locales)); + } + + /** + * @Then I should be notified that the default locale has to be enabled + */ + public function iShouldBeNotifiedThatTheDefaultLocaleHasToBeEnabled(): void + { + Assert::contains( + $this->responseChecker->getError($this->client->getLastResponse()), + 'defaultLocale: Default locale has to be enabled.', + ); + } + + /** + * @Then /^(this channel) should still be in the registry$/ + */ + public function thisChannelShouldStillBeInTheRegistry(ChannelInterface $channel): void + { + Assert::true( + $this->responseChecker->hasItemWithValue($this->client->index(Resources::CHANNELS), 'code', $channel->getCode()), + sprintf('Channel with code %s does not exists', $channel->getCode()), + ); + } + + /** + * @Then the tax calculation strategy for the :channel channel should be :taxCalculationStrategy + */ + public function theTaxCalculationStrategyForTheChannelShouldBe( + ChannelInterface $channel, + string $taxCalculationStrategy, + ): void { + Assert::same( + $this->responseChecker->getValue($this->client->show(Resources::CHANNELS, $channel->getCode()), 'taxCalculationStrategy'), + StringInflector::nameToLowercaseCode($taxCalculationStrategy), + sprintf('Channel %s does not have %s tax calculation strategy', $channel->getName(), $taxCalculationStrategy), + ); + } + + /** + * @Then /^(this channel) should be disabled$/ + */ + public function thisChannelShouldBeDisabled(ChannelInterface $channel): void + { + Assert::same( + $this->responseChecker->getValue($this->client->show(Resources::CHANNELS, $channel->getCode()), 'enabled'), + false, + sprintf('Channel %s is enabled', $channel->getName()), + ); + } + + /** + * @Then I should be notified that :element is required + */ + public function iShouldBeNotifiedThatIsRequired(string $element): void + { + Assert::contains( + $this->responseChecker->getError($this->client->getLastResponse()), + sprintf('%s: Please enter channel %s.', $element, $element), + ); + } + + /** + * @Then I should be notified that base currency is required + */ + public function iShouldBeNotifiedThatBaseCurrencyIsRequired(): void + { + Assert::contains( + $this->responseChecker->getError($this->client->getLastResponse()), + 'Expected IRI or nested document for attribute "baseCurrency", "NULL" given.', + ); + } + + /** + * @Then I should be notified that default locale is required + */ + public function iShouldBeNotifiedThatDefaultLocaleIsRequired(): void + { + Assert::contains( + $this->responseChecker->getError($this->client->getLastResponse()), + 'Expected IRI or nested document for attribute "defaultLocale", "NULL" given.', + ); + } + + /** + * @Then channel with :element :value should not be added + */ + public function channelWithShouldNotBeAdded(string $element, string $value): void + { + Assert::false( + $this->responseChecker->hasItemWithValue($this->client->index(Resources::CHANNELS), $element, $value), + sprintf('Channel with %s: %s exists', $element, $value), + ); + } + + /** + * @Then I should be notified that channel with this code already exists + */ + public function iShouldBeNotifiedThatChannelWithThisCodeAlreadyExists(): void + { + Assert::contains( + $this->responseChecker->getError($this->client->getLastResponse()), + 'code: Channel code has to be unique.', + ); + } + + /** + * @Then there should still be only one channel with :element :value + */ + public function thereShouldStillBeOnlyOneChannelWithCode(string $element, string $value): void + { + Assert::same( + count($this->responseChecker->getCollectionItemsWithValue($this->client->index(Resources::CHANNELS), $element, $value)), + 1, + sprintf('There is more than one channel with %s: %s', $element, $value), + ); + } + + /** + * @Then I should be notified that it is not a valid country + */ + public function iShouldBeNotifiedThatItIsNotAValidCountryCode(): void + { + Assert::contains( + $this->responseChecker->getError($this->client->getLastResponse()), + 'countryCode: This value is not a valid country.', + ); + } } diff --git a/src/Sylius/Behat/Context/Api/Admin/ManagingProductsContext.php b/src/Sylius/Behat/Context/Api/Admin/ManagingProductsContext.php index e910784eda..4a5b7ad03f 100644 --- a/src/Sylius/Behat/Context/Api/Admin/ManagingProductsContext.php +++ b/src/Sylius/Behat/Context/Api/Admin/ManagingProductsContext.php @@ -276,7 +276,7 @@ final class ManagingProductsContext implements Context public function iSetItsNonTranslatableAttributeTo(ProductAttributeInterface $attribute, string $value): void { $this->client->addSubResourceData( - 'attributes', + 'attributes', [ 'attribute' => $this->iriConverter->getIriFromResource($attribute), 'value' => $this->getAttributeValueInProperType($attribute, $value), @@ -290,7 +290,7 @@ final class ManagingProductsContext implements Context public function iSetTheInvalidIntegerValueOfTheNonTranslatableAttributeTo(ProductAttributeInterface $attribute, int $value): void { $this->client->addSubResourceData( - 'attributes', + 'attributes', [ 'attribute' => $this->iriConverter->getIriFromResource($attribute), 'value' => $value, @@ -304,7 +304,7 @@ final class ManagingProductsContext implements Context public function iSetTheInvalidStringValueOfTheNonTranslatableAttributeTo(ProductAttributeInterface $attribute, string $value): void { $this->client->addSubResourceData( - 'attributes', + 'attributes', [ 'attribute' => $this->iriConverter->getIriFromResource($attribute), 'value' => $value, @@ -320,7 +320,7 @@ final class ManagingProductsContext implements Context public function iSetItsAttributeTo( ProductAttributeInterface $attribute, ?string $value = null, - string $localeCode = 'en_US' + string $localeCode = 'en_US', ): void { $this->client->addSubResourceData( 'attributes', @@ -363,7 +363,7 @@ final class ManagingProductsContext implements Context public function iSelectValueInForTheAttribute( string $value, string $localeCode, - ProductAttributeInterface $attribute + ProductAttributeInterface $attribute, ): void { $this->client->addSubResourceData( 'attributes', @@ -380,7 +380,7 @@ final class ManagingProductsContext implements Context */ public function iSelectValueForTheAttribute( string $value, - ProductAttributeInterface $attribute + ProductAttributeInterface $attribute, ): void { $this->client->addSubResourceData( 'attributes', @@ -678,7 +678,7 @@ final class ManagingProductsContext implements Context public function nonTranslatableAttributeOfProductShouldBe( ProductAttributeInterface $attribute, ProductInterface $product, - string $value + string $value, ): void { $this->client->show(Resources::PRODUCTS, $product->getCode()); @@ -702,7 +702,7 @@ final class ManagingProductsContext implements Context ProductAttributeInterface $attribute, ProductInterface $product, string $value, - string $localeCode = 'en_US' + string $localeCode = 'en_US', ): void { $this->client->show(Resources::PRODUCTS, $product->getCode()); @@ -718,7 +718,7 @@ final class ManagingProductsContext implements Context foreach ($attributes as $attributeValue) { if ($attributeValue['attribute'] === $this->sectionAwareIriConverter->getIriFromResourceInSection($attribute, 'admin')) { throw new \InvalidArgumentException( - sprintf('Product %s have attribute %s', $product->getName(), $attribute->getName()) + sprintf('Product %s have attribute %s', $product->getName(), $attribute->getName()), ); } } @@ -780,7 +780,7 @@ final class ManagingProductsContext implements Context public function iShouldBeNotifiedThatTheAttributeInShouldBeLongerThan( string $attributeName, string $localeCode, - int $number + int $number, ): void { Assert::contains( $this->responseChecker->getError($this->client->getLastResponse()), @@ -861,7 +861,7 @@ final class ManagingProductsContext implements Context private function getAttributeValueInProperType( ProductAttributeInterface $productAttribute, - string $value + string $value, ): string|bool|float|int { switch ($productAttribute->getStorageType()) { case AttributeValueInterface::STORAGE_BOOLEAN: @@ -887,7 +887,7 @@ final class ManagingProductsContext implements Context } throw new \InvalidArgumentException( - sprintf('Value "%s" not found in attribute "%s"', $value, $attribute->getName()) + sprintf('Value "%s" not found in attribute "%s"', $value, $attribute->getName()), ); } @@ -908,7 +908,7 @@ final class ManagingProductsContext implements Context } throw new \InvalidArgumentException( - sprintf('The given product does not have attribute %s', $attribute->getName()) + sprintf('The given product does not have attribute %s', $attribute->getName()), ); } diff --git a/src/Sylius/Behat/Context/Ui/Admin/ManagingChannelsBillingDataContext.php b/src/Sylius/Behat/Context/Ui/Admin/ManagingChannelsBillingDataContext.php index 302623d43a..42eb04b045 100644 --- a/src/Sylius/Behat/Context/Ui/Admin/ManagingChannelsBillingDataContext.php +++ b/src/Sylius/Behat/Context/Ui/Admin/ManagingChannelsBillingDataContext.php @@ -24,6 +24,22 @@ final class ManagingChannelsBillingDataContext implements Context { } + /** + * @When I specify shop billing data for this channel as :company, :street, :postcode, :city, :taxId tax ID and :country country + */ + public function iSpecifyNewShopBillingDataForChannelAs( + string $company, + string $street, + string $postcode, + string $city, + string $taxId, + CountryInterface $country, + ): void { + $this->shopBillingDataElement->specifyCompany($company); + $this->shopBillingDataElement->specifyTaxId($taxId); + $this->shopBillingDataElement->specifyBillingAddress($street, $postcode, $city, $country->getCode()); + } + /** * @When I specify company as :company */ @@ -69,6 +85,7 @@ final class ManagingChannelsBillingDataContext implements Context } /** + * @Then this channel shop billing address should be :street, :postcode :city and :country country * @Then this channel shop billing address should be :street, :postcode :city, :country */ public function thisChannelShopBillingAddressShouldBe( diff --git a/src/Sylius/Behat/Context/Ui/Admin/ManagingChannelsContext.php b/src/Sylius/Behat/Context/Ui/Admin/ManagingChannelsContext.php index a44d18bb00..d1d43bd43e 100644 --- a/src/Sylius/Behat/Context/Ui/Admin/ManagingChannelsContext.php +++ b/src/Sylius/Behat/Context/Ui/Admin/ManagingChannelsContext.php @@ -292,6 +292,7 @@ final class ManagingChannelsContext implements Context * @Given I am modifying a channel :channel * @When I want to modify a channel :channel * @When /^I want to modify (this channel)$/ + * @When I want to modify a billing data of channel :channel */ public function iWantToModifyChannel(ChannelInterface $channel): void { @@ -315,6 +316,7 @@ final class ManagingChannelsContext implements Context /** * @When I save my changes * @When I try to save my changes + * @When I save it */ public function iSaveMyChanges(): void { @@ -332,7 +334,7 @@ final class ManagingChannelsContext implements Context /** * @Then there should still be only one channel with :element :value */ - public function thereShouldStillBeOnlyOneChannelWithCode(string $element, string $value) + public function thereShouldStillBeOnlyOneChannelWithCode(string $element, string $value): void { $this->iWantToBrowseChannels(); @@ -375,6 +377,7 @@ final class ManagingChannelsContext implements Context /** * @Then the code field should be disabled + * @Then I should not be able to edit its code */ public function theCodeFieldShouldBeDisabled(): void { @@ -461,7 +464,7 @@ final class ManagingChannelsContext implements Context /** * @Then paying in :currencyCode should be possible for the :channel channel */ - public function payingInEuroShouldBePossibleForTheChannel(string $currencyCode, ChannelInterface $channel): void + public function payingInCurrencyShouldBePossibleForTheChannel(string $currencyCode, ChannelInterface $channel): void { $this->updatePage->open(['id' => $channel->getId()]); @@ -607,6 +610,7 @@ final class ManagingChannelsContext implements Context /** * @Then the base currency field should be disabled + * @Then I should not be able to edit its base currency */ public function theBaseCurrencyFieldShouldBeDisabled(): void { 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 eb43c350aa..ef5e046a93 100644 --- a/src/Sylius/Behat/Resources/config/services/contexts/api/admin.xml +++ b/src/Sylius/Behat/Resources/config/services/contexts/api/admin.xml @@ -61,6 +61,12 @@ + + + + + + diff --git a/src/Sylius/Behat/Resources/config/suites/api/channel/managing_channels.yml b/src/Sylius/Behat/Resources/config/suites/api/channel/managing_channels.yml index 924a4300d3..1f68d15ceb 100644 --- a/src/Sylius/Behat/Resources/config/suites/api/channel/managing_channels.yml +++ b/src/Sylius/Behat/Resources/config/suites/api/channel/managing_channels.yml @@ -29,6 +29,7 @@ default: - sylius.behat.context.api.admin.managing_channels - sylius.behat.context.api.admin.response - sylius.behat.context.api.admin.save + - Sylius\Behat\Context\Api\Admin\ManagingChannelsBillingDataContext - Sylius\Behat\Context\Api\Admin\ManagingChannelPriceHistoryConfigsContext filters: