[Behat] Add api tag to managing channel scenarios

This commit is contained in:
Kamil Grygierzec 2023-10-19 09:32:54 +02:00
parent a0b29867eb
commit f8222e5a4c
No known key found for this signature in database
GPG key ID: 7F54EE42DAD4B9E9
24 changed files with 604 additions and 75 deletions

View file

@ -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"

View file

@ -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"

View file

@ -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

View file

@ -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"

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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"

View file

@ -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

View file

@ -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"

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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"

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -0,0 +1,83 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Sylius Sp. z o.o.
*
* 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\Api\Admin;
use ApiPlatform\Api\IriConverterInterface;
use Behat\Behat\Context\Context;
use Sylius\Behat\Client\ApiClientInterface;
use Sylius\Behat\Client\ResponseCheckerInterface;
use Sylius\Behat\Context\Api\Resources;
use Sylius\Component\Addressing\Model\CountryInterface;
use Sylius\Component\Core\Model\ChannelInterface;
use Sylius\Component\Core\Model\ShopBillingDataInterface;
use Webmozart\Assert\Assert;
final class ManagingChannelsBillingDataContext implements Context
{
public function __construct(
private ApiClientInterface $client,
private ResponseCheckerInterface $responseChecker,
private IriConverterInterface $iriConverter,
) {
}
/**
* @Then /^(this channel) company should be "([^"]+)"$/
*/
public function thisChannelCompanyShouldBe(ChannelInterface $channel, string $company): void
{
$shopBillingData = $this->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;
}
}

View file

@ -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.',
);
}
}

View file

@ -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()),
);
}

View file

@ -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(

View file

@ -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
{

View file

@ -61,6 +61,12 @@
<argument type="service" id="sylius.behat.section_iri_converter" />
</service>
<service id="Sylius\Behat\Context\Api\Admin\ManagingChannelsBillingDataContext">
<argument type="service" id="sylius.behat.api_platform_client.admin" />
<argument type="service" id="Sylius\Behat\Client\ResponseCheckerInterface" />
<argument type="service" id="api_platform.iri_converter" />
</service>
<service id="sylius.behat.context.api.admin.managing_countries" class="Sylius\Behat\Context\Api\Admin\ManagingCountriesContext">
<argument type="service" id="sylius.behat.api_platform_client.admin" />
<argument type="service" id="Sylius\Behat\Client\ResponseCheckerInterface" />

View file

@ -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: