[Behat] Merge base currency step with channel creation step

This commit is contained in:
Mateusz Zalewski 2016-11-21 14:33:48 +01:00
parent a3ae028d31
commit 597bb32620
No known key found for this signature in database
GPG key ID: CFC1E4176165876B
23 changed files with 46 additions and 61 deletions

View file

@ -5,7 +5,7 @@ Feature: Seeing province created manually in order history
I want to be able to see province in the order history
Background:
Given the store operates on a channel named "Web"
Given the store operates on a channel named "Web" in currency "USD"
And the store operates in "United Kingdom"
And the store has a zone "English" with code "EN"
And this zone has the "United Kingdom" country member

View file

@ -8,10 +8,9 @@ Feature: Viewing details of an order
Given the store ships to "British Virgin Islands"
And the store has a zone "English" with code "EN"
And this zone has the "British Virgin Islands" country member
And the store operates on a channel named "Web"
And the store operates on a channel named "Web" in currency "USD"
And that channel allows to shop using the "USD" currency
And that channel allows to shop using the "GBP" currency with exchange rate 3.0
And that channel uses the "USD" currency as base
And the store allows paying with "Cash on Delivery"
And the store has "DHL" shipping method with "$20.00" fee within the "EN" zone
And the store has a product "Angel T-Shirt" priced at "$20.00"

View file

@ -7,12 +7,10 @@ Feature: Adding a product to cart with prices dependent on a channel and a curre
Background:
Given the store has currency "EUR"
And the store has currency "GBP" with exchange rate 0.7
And the store operates on a channel named "Web-EU"
And the store operates on a channel named "Web-EU" in currency "EUR"
And that channel allows to shop using "EUR" and "GBP" currencies
And that channel uses the "EUR" currency as base
And the store operates on another channel named "Web-GB"
And that channel allows to shop using "EUR" and "GBP" currencies
And that channel uses the "GBP" currency as base
And the store has a product "Leprechaun's Gold" priced at "12.54" available in channel "Web-EU" and channel "Web-GB"
And it has different prices for different channels and currencies
And it has price "10.00" for "Web-EU" channel and "EUR" currency

View file

@ -7,7 +7,7 @@ Feature: Viewing a cart summary in many channels
Background:
Given the store operates on another channel named "France"
And there is product "Banana" available in this channel
And the store operates on a channel named "Poland"
And the store operates on a channel named "Poland" in currency "PLN"
And there is product "Onion" available in this channel
@ui

View file

@ -5,7 +5,7 @@ Feature: Browsing channels
I want to be able to browse list of them
Background:
Given the store operates on a channel named "Web Channel"
Given the store operates on a channel named "Web Channel" in currency "USD"
And the store operates on another channel named "Mobile Channel"
And I am logged in as an administrator

View file

@ -8,10 +8,9 @@ Feature: Seeing prices recalculated by exchange rate on order summary
Given the store ships to "British Virgin Islands"
And the store has a zone "English" with code "EN"
And this zone has the "British Virgin Islands" country member
And the store operates on a channel named "Web"
And the store operates on a channel named "Web" in currency "USD"
And that channel allows to shop using the "USD" currency
And that channel allows to shop using the "GBP" currency with exchange rate 3.0
And that channel uses the "USD" currency as base
And the store has a product "Lannister Coat" priced at "$100.00"
And the store has "DHL" shipping method with "$20.00" fee within the "EN" zone
And the store allows paying offline

View file

@ -5,12 +5,10 @@ Feature: Handling different currencies on multiple channels
I want to browse channels with a valid currency only
Background:
Given the store operates on a channel named "Web"
Given the store operates on a channel named "Web" in currency "EUR"
And that channel allows to shop using "EUR", "USD" and "GBP" currencies
And it uses the "EUR" currency as base
And the store operates on another channel named "Mobile"
And the store operates on another channel named "Mobile" in currency "USD"
And that channel allows to shop using "USD" and "GBP" currencies
And it uses the "USD" currency as base
@ui
Scenario: Showing currencies only from the current channel

View file

@ -5,9 +5,8 @@ Feature: Handling disabled currencies
I want to browse channels with a valid currency only
Background:
Given the store operates on a channel named "Web"
Given the store operates on a channel named "Web" in currency "EUR"
And that channel allows to shop using "EUR", "USD" and "GBP" currencies
And it uses the "EUR" currency as base
@ui
Scenario: Not showing the disabled currency

View file

@ -9,14 +9,12 @@ Feature: Inability of modifying the base currency
@ui
Scenario: Being prevented from disabling base currency
Given the store operates on a single channel
And it uses the "USD" currency as base
Given the store operates on a single channel in currency "USD"
When I want to edit this currency
Then I should not be able to disable this currency
@ui
Scenario: Being prevented from changing base currency exchange rate
Given the store operates on a single channel
And it uses the "USD" currency as base
Given the store operates on a single channel in currency "USD"
When I want to edit this currency
Then I should not be able to change exchange rate of this currency

View file

@ -5,9 +5,8 @@ Feature: Switching the current currency
I want to be able to switch currencies
Background:
Given the store operates on a channel named "Web"
Given the store operates on a channel named "Web" in currency "EUR"
And that channel allows to shop using "EUR" and "USD" currencies
And it uses the "EUR" currency as base
@ui
Scenario: Showing the current currency

View file

@ -5,13 +5,12 @@ Feature: Modifying a customer's shipping address of an order with a different cu
I want to be able to modify a customer's shipping address without changing an order's total
Background:
Given the store operates on a channel named "Web"
Given the store operates on a channel named "Web" in currency "USD"
And the store ships to "United States"
And the store has a zone "English" with code "EN"
And this zone has the "United States" country member
And that channel allows to shop using the "USD" currency
And that channel allows to shop using the "GBP" currency with exchange rate 3.0
And that channel uses the "USD" currency as base
And the store allows paying with "Cash on Delivery"
And the store has "DHL" shipping method with "$20.00" fee within the "EN" zone
And the store has a product "Suit" priced at "$400.00"

View file

@ -6,7 +6,6 @@ Feature: Modifying a customer's shipping address validation
Background:
Given the store operates on a single channel in the "United States" named "Web"
And that channel uses the "USD" currency as base
And the store ships everywhere for free
And the store allows paying with "Cash on Delivery"
And the store has a product "Suit" priced at "$400.00"

View file

@ -8,9 +8,8 @@ Feature: Seeing the currency an order has been placed in on it's details page
Given the store ships to "British Virgin Islands"
And the store has a zone "English" with code "EN"
And this zone has the "British Virgin Islands" country member
And the store operates on a channel named "Web"
And the store operates on a channel named "Web" in currency "USD"
And that channel allows to shop using "USD" and "GBP" currencies
And that channel uses the "USD" currency as base
And the store has "Low VAT" tax rate of 10% for "Lowered EN services" within the "EN" zone
And the store allows paying with "Cash on Delivery"
And the store has "DHL" shipping method with "$20.00" fee within the "EN" zone

View file

@ -8,10 +8,9 @@ Feature: Seeing all prices calculated accordingly to it's currency's exchange ra
Given the store ships to "British Virgin Islands"
And the store has a zone "English" with code "EN"
And this zone has the "British Virgin Islands" country member
And the store operates on a channel named "Web"
And the store operates on a channel named "Web" in currency "USD"
And that channel allows to shop using the "USD" currency
And that channel allows to shop using the "GBP" currency with exchange rate 2.00
And that channel uses the "USD" currency as base
And the store has "Low VAT" tax rate of 10% for "Lowered EN services" within the "EN" zone
And the store allows paying with "Cash on Delivery"
And the store has "DHL" shipping method with "$20.00" fee within the "EN" zone

View file

@ -8,9 +8,8 @@ Feature: Seeing the currency in which all orders have been placed
Given the store ships to "British Virgin Islands"
And the store has a zone "English" with code "EN"
And this zone has the "British Virgin Islands" country member
And the store operates on a channel named "Web"
And the store operates on a channel named "Web" in currency "USD"
And that channel allows to shop using "USD" and "GBP" currencies
And that channel uses the "USD" currency as base
And the store allows paying with "Cash on Delivery"
And the store has "DHL" shipping method with "$20.00" fee within the "EN" zone
And the store has a product "Angel T-Shirt" priced at "$20.00"

View file

@ -8,10 +8,9 @@ Feature: Seeing orders' total in their currency and respective exchange rate
Given the store ships to "British Virgin Islands"
And the store has a zone "English" with code "EN"
And this zone has the "British Virgin Islands" country member
And the store operates on a channel named "Web"
And the store operates on a channel named "Web" in currency "USD"
And that channel allows to shop using the "USD" currency
And that channel allows to shop using the "GBP" currency with exchange rate 3.0
And that channel uses the "USD" currency as base
And the store allows paying with "Cash on Delivery"
And the store has "DHL" shipping method with "$20.00" fee within the "EN" zone
And the store has a product "Angel T-Shirt" priced at "$20.00"

View file

@ -7,9 +7,8 @@ Feature: Adding a new promotion with action configured in different currencies
Background:
Given the store has currency "USD"
And the store has currency "GBP" with exchange rate 0.5
And the store operates on a channel named "Web-US"
And the store operates on a channel named "Web-US" in currency "USD"
And that channel allows to shop using "USD" and "GBP" currencies
And that channel uses the "USD" currency as base
And I am logged in as an administrator
@ui @javascript

View file

@ -7,9 +7,8 @@ Feature: Receiving fixed discount dependent on currency on cart
Background:
Given the store has currency "USD"
And the store has currency "GBP" with exchange rate 0.5
And the store operates on a channel named "Web-US"
And the store operates on a channel named "Web-US" in currency "USD"
And that channel allows to shop using "USD" and "GBP" currencies
And that channel uses the "USD" currency as base
And the store has a product "PHP T-Shirt" priced at "$100.00"
And there is a promotion "Holiday promotion"

View file

@ -105,10 +105,11 @@ final class ChannelContext implements Context
/**
* @Given the store operates on a single channel
* @Given the store operates on a single channel in currency :currencyCode
*/
public function storeOperatesOnASingleChannel()
public function storeOperatesOnASingleChannel($currencyCode = null)
{
$defaultData = $this->defaultChannelFactory->create();
$defaultData = $this->defaultChannelFactory->create(null, null, $currencyCode);
$this->sharedStorage->setClipboard($defaultData);
$this->sharedStorage->set('channel', $defaultData['channel']);
@ -116,11 +117,12 @@ final class ChannelContext implements Context
/**
* @Given /^the store operates on (?:a|another) channel named "([^"]+)"$/
* @Given /^the store operates on (?:a|another) channel named "([^"]+)" in currency "([^"]+)"$/
* @Given the store operates on a channel identified by :code code
*/
public function theStoreOperatesOnAChannelNamed($channelIdentifier)
public function theStoreOperatesOnAChannelNamed($channelIdentifier, $currencyCode = null)
{
$defaultData = $this->defaultChannelFactory->create($channelIdentifier, $channelIdentifier);
$defaultData = $this->defaultChannelFactory->create($channelIdentifier, $channelIdentifier, $currencyCode);
$this->sharedStorage->setClipboard($defaultData);
$this->sharedStorage->set('channel', $defaultData['channel']);

View file

@ -40,7 +40,6 @@
<argument type="service" id="sylius.factory.locale" />
<argument type="service" id="sylius.factory.zone" />
<argument type="service" id="sylius.factory.zone_member" />
<argument>%currency%</argument>
<argument>%locale%</argument>
</service>
<service id="sylius.behat.factory.default_channel" class="Sylius\Component\Core\Test\Services\DefaultChannelFactory">

View file

@ -99,9 +99,9 @@ final class DefaultChannelFactory implements DefaultChannelFactoryInterface
/**
* {@inheritdoc}
*/
public function create($code = null, $name = null)
public function create($code = null, $name = null, $currencyCode = null)
{
$currency = $this->provideCurrency();
$currency = $this->provideCurrency($currencyCode);
$locale = $this->provideLocale();
/** @var ChannelInterface $channel */
@ -127,14 +127,18 @@ final class DefaultChannelFactory implements DefaultChannelFactoryInterface
/**
* @return CurrencyInterface
*/
private function provideCurrency()
private function provideCurrency($currencyCode = null)
{
if (null === $currencyCode) {
$currencyCode = $this->defaultCurrencyCode;
}
/** @var CurrencyInterface $currency */
$currency = $this->currencyRepository->findOneBy(['code' => $this->defaultCurrencyCode]);
$currency = $this->currencyRepository->findOneBy(['code' => $currencyCode]);
if (null === $currency) {
$currency = $this->currencyFactory->createNew();
$currency->setCode($this->defaultCurrencyCode);
$currency->setCode($currencyCode);
$currency->setExchangeRate(1.00);
$this->currencyRepository->add($currency);

View file

@ -19,8 +19,9 @@ interface DefaultChannelFactoryInterface
/**
* @param string|null $code
* @param string|null $name
* @param string|null $currencyCode
*
* @return array
*/
public function create($code = null, $name = null);
public function create($code = null, $name = null, $currencyCode = null);
}

View file

@ -31,6 +31,7 @@ final class DefaultUnitedStatesChannelFactory implements DefaultChannelFactoryIn
const DEFAULT_ZONE_CODE = 'US';
const DEFAULT_ZONE_NAME = 'United States';
const DEFAULT_CHANNEL_NAME = 'United States';
const DEFAULT_CURRENCY_CODE = 'USD';
/**
* @var RepositoryInterface
@ -92,11 +93,6 @@ final class DefaultUnitedStatesChannelFactory implements DefaultChannelFactoryIn
*/
private $zoneFactory;
/**
* @var string
*/
private $defaultCurrencyCode;
/**
* @var string
*/
@ -115,7 +111,6 @@ final class DefaultUnitedStatesChannelFactory implements DefaultChannelFactoryIn
* @param FactoryInterface $localeFactory
* @param FactoryInterface $zoneFactory
* @param FactoryInterface $zoneMemberFactory
* @param string $defaultCurrencyCode
* @param string $defaultLocaleCode
*/
public function __construct(
@ -131,7 +126,6 @@ final class DefaultUnitedStatesChannelFactory implements DefaultChannelFactoryIn
FactoryInterface $localeFactory,
FactoryInterface $zoneFactory,
FactoryInterface $zoneMemberFactory,
$defaultCurrencyCode,
$defaultLocaleCode
) {
$this->channelRepository = $channelRepository;
@ -146,16 +140,15 @@ final class DefaultUnitedStatesChannelFactory implements DefaultChannelFactoryIn
$this->localeFactory = $localeFactory;
$this->zoneMemberFactory = $zoneMemberFactory;
$this->zoneFactory = $zoneFactory;
$this->defaultCurrencyCode = $defaultCurrencyCode;
$this->defaultLocaleCode = $defaultLocaleCode;
}
/**
* {@inheritdoc}
*/
public function create($code = null, $name = null)
public function create($code = null, $name = null, $currencyCode = null)
{
$currency = $this->provideCurrency();
$currency = $this->provideCurrency($currencyCode);
$locale = $this->provideLocale();
$channel = $this->createChannel($code ?: self::DEFAULT_CHANNEL_CODE, $name ?: self::DEFAULT_CHANNEL_NAME);
@ -206,14 +199,18 @@ final class DefaultUnitedStatesChannelFactory implements DefaultChannelFactoryIn
/**
* @return CurrencyInterface
*/
private function provideCurrency()
private function provideCurrency($currencyCode = null)
{
if (null === $currencyCode) {
$currencyCode = self::DEFAULT_CURRENCY_CODE;
}
/** @var CurrencyInterface $currency */
$currency = $this->currencyRepository->findOneBy(['code' => $this->defaultCurrencyCode]);
$currency = $this->currencyRepository->findOneBy(['code' => $currencyCode]);
if (null === $currency) {
$currency = $this->currencyFactory->createNew();
$currency->setCode($this->defaultCurrencyCode);
$currency->setCode($currencyCode);
$currency->setExchangeRate(1.00);
$this->currencyRepository->add($currency);