Shop billing data on channel tests

This commit is contained in:
Mateusz Zalewski 2019-01-08 15:45:03 +01:00
parent 65d62380db
commit f7cdb5522f
No known key found for this signature in database
GPG key ID: 0545A7503DD474B8
12 changed files with 240 additions and 24 deletions

View file

@ -0,0 +1,24 @@
@managing_channels
Feature: Adding a new channel with shop billing data
In order to sell through multiple channels of distributions with specific billing data
As an Administrator
I want to add a new channel with shop billing data to the registry
Background:
Given the store has currency "Euro"
And the store has locale "English (United States)"
And I am logged in as an administrator
@ui
Scenario: Adding a new channel with shop billing data
Given I want to create a new channel
When I specify its code as "MOBILE"
And I name it "Mobile channel"
And I choose "Euro" as the base currency
And I choose "English (United States)" as a default locale
And I specify company as "Ragnarok"
And I specify tax ID as "1100110011"
And I specify shop billing address as "Pacific Coast Hwy", "90806" "Los Angeles", "United States"
And I add it
Then I should be notified that it has been successfully created
And the channel "Mobile channel" should appear in the registry

View file

@ -0,0 +1,22 @@
@managing_channels
Feature: Editing shop billing data on channel
In order to have proper shop billing data on shop-related documents
As an Administrator
I want to be able to edit shop billing data on a channel
Background:
Given the store operates on a channel named "Web Store"
And the store ships to "United States"
And I am logged in as an administrator
@ui
Scenario: Editing shop billing data on channel
When I want to modify a channel "Web Store"
And I specify company as "Ragnarok"
And I specify tax ID as "1100110011"
And I specify shop billing address as "Pacific Coast Hwy", "90806" "Los Angeles", "United States"
And I save my changes
Then I should be notified that it has been successfully edited
And this channel company should be "Ragnarok"
And this channel tax ID should be "1100110011"
And this channel shop billing address should be "Pacific Coast Hwy", "90806" "Los Angeles", "United States"

View file

@ -0,0 +1,79 @@
<?php
declare(strict_types=1);
namespace Sylius\Behat\Context\Ui\Admin;
use Behat\Behat\Context\Context;
use Sylius\Behat\Element\Admin\Channel\ShopBillingDataElementInterface;
use Sylius\Component\Addressing\Model\CountryInterface;
use Webmozart\Assert\Assert;
final class ManagingChannelsBillingDataContext implements Context
{
/** @var ShopBillingDataElementInterface */
private $shopBillingDataElement;
public function __construct(ShopBillingDataElementInterface $shopBillingDataElement)
{
$this->shopBillingDataElement = $shopBillingDataElement;
}
/**
* @When I specify company as :company
*/
public function specifyCompanyAs(string $company): void
{
$this->shopBillingDataElement->specifyCompany($company);
}
/**
* @When I specify tax ID as :taxId
*/
public function specifyTaxIdAs(string $taxId): void
{
$this->shopBillingDataElement->specifyTaxId($taxId);
}
/**
* @When I specify shop billing address as :street, :postcode :city, :country
*/
public function specifyShopBillingAddressAs(
string $street,
string $postcode,
string $city,
CountryInterface $country
): void
{
$this->shopBillingDataElement->specifyBillingAddress($street, $postcode, $city, $country->getCode());
}
/**
* @Then this channel company should be :company
*/
public function thisChannelCompanyShouldBe(string $company): void
{
Assert::true($this->shopBillingDataElement->hasCompany($company));
}
/**
* @Then this channel tax ID should be :taxId
*/
public function thisChanneTaxIdShouldBe(string $taxId): void
{
Assert::true($this->shopBillingDataElement->hasTaxId($taxId));
}
/**
* @Then this channel shop billing address should be :street, :postcode :city, :country
*/
public function thisChannelShopBillingAddressShouldBe(
string $street,
string $postcode,
string $city,
CountryInterface $country
): void
{
Assert::true($this->shopBillingDataElement->hasBillingAddress($street, $postcode, $city, $country->getCode()));
}
}

View file

@ -0,0 +1,60 @@
<?php
declare(strict_types=1);
namespace Sylius\Behat\Element\Admin\Channel;
use FriendsOfBehat\PageObjectExtension\Element\Element;
final class ShopBillingDataElement extends Element implements ShopBillingDataElementInterface
{
public function specifyCompany(string $company): void
{
$this->getElement('company')->setValue($company);
}
public function specifyTaxId(string $taxId): void
{
$this->getElement('tax_id')->setValue($taxId);
}
public function specifyBillingAddress(string $street, string $postcode, string $city, string $countryCode): void
{
$this->getElement('street')->setValue($street);
$this->getElement('postcode')->setValue($postcode);
$this->getElement('city')->setValue($city);
$this->getElement('country_code')->setValue($countryCode);
}
public function hasCompany(string $company): bool
{
return $company === $this->getElement('company')->getValue();
}
public function hasTaxId(string $taxId): bool
{
return $taxId === $this->getElement('tax_id')->getValue();
}
public function hasBillingAddress(string $street, string $postcode, string $city, string $countryCode): bool
{
return
$street === $this->getElement('street')->getValue() &&
$postcode === $this->getElement('postcode')->getValue() &&
$city === $this->getElement('city')->getValue() &&
$countryCode === $this->getElement('country_code')->getValue()
;
}
protected function getDefinedElements(): array
{
return array_merge(parent::getDefinedElements(), [
'city' => '#sylius_channel_billingData_city',
'company' => '#sylius_channel_billingData_company',
'country_code' => '#sylius_channel_billingData_countryCode',
'postcode' => '#sylius_channel_billingData_postcode',
'street' => '#sylius_channel_billingData_street',
'tax_id' => '#sylius_channel_billingData_taxId',
]);
}
}

View file

@ -0,0 +1,20 @@
<?php
declare(strict_types=1);
namespace Sylius\Behat\Element\Admin\Channel;
interface ShopBillingDataElementInterface
{
public function specifyCompany(string $company): void;
public function specifyTaxId(string $taxId): void;
public function specifyBillingAddress(string $street, string $postcode, string $city, string $countryCode): void;
public function hasCompany(string $company): bool;
public function hasTaxId(string $taxId): bool;
public function hasBillingAddress(string $street, string $postcode, string $city, string $countryCode): bool;
}

View file

@ -38,21 +38,11 @@ class UpdatePage extends BaseUpdatePage implements UpdatePageInterface
$this->getDocument()->selectFieldOption('Locales', $language);
}
public function isLocaleChosen(string $language): bool
{
return $this->getElement('locales')->find('named', ['option', $language])->hasAttribute('selected');
}
public function chooseCurrency(string $currencyCode): void
{
$this->getDocument()->selectFieldOption('Currencies', $currencyCode);
}
public function isCurrencyChosen(string $currencyCode): bool
{
return $this->getElement('currencies')->find('named', ['option', $currencyCode])->hasAttribute('selected');
}
public function chooseDefaultTaxZone(string $taxZone): void
{
$this->getDocument()->selectFieldOption('Default tax zone', $taxZone);
@ -63,6 +53,16 @@ class UpdatePage extends BaseUpdatePage implements UpdatePageInterface
$this->getDocument()->selectFieldOption('Tax calculation strategy', $taxZone);
}
public function isLocaleChosen(string $language): bool
{
return $this->getElement('locales')->find('named', ['option', $language])->hasAttribute('selected');
}
public function isCurrencyChosen(string $currencyCode): bool
{
return $this->getElement('currencies')->find('named', ['option', $currencyCode])->hasAttribute('selected');
}
public function isDefaultTaxZoneChosen(string $taxZone): bool
{
return $this->getElement('default_tax_zone')->find('named', ['option', $taxZone])->hasAttribute('selected');

View file

@ -29,20 +29,20 @@ interface UpdatePageInterface extends BaseUpdatePageInterface
*/
public function unsetTheme(): void;
public function isCodeDisabled(): bool;
public function chooseLocale(string $language): void;
public function isLocaleChosen(string $language): bool;
public function chooseCurrency(string $currencyCode): void;
public function isCurrencyChosen(string $currencyCode): bool;
public function chooseDefaultTaxZone(string $taxZone): void;
public function chooseTaxCalculationStrategy(string $taxCalculationStrategy): void;
public function isCodeDisabled(): bool;
public function isLocaleChosen(string $language): bool;
public function isCurrencyChosen(string $currencyCode): bool;
public function isDefaultTaxZoneChosen(string $taxZone): bool;
public function isAnyDefaultTaxZoneChosen(): bool;

View file

@ -49,6 +49,11 @@
<tag name="fob.context_service" />
</service>
<service id="sylius.behat.context.ui.admin.managing_channels_billing_data" class="Sylius\Behat\Context\Ui\Admin\ManagingChannelsBillingDataContext">
<argument type="service" id="sylius.behat.element.admin.channel.shop_billing_data" />
<tag name="fob.context_service" />
</service>
<service id="sylius.behat.context.ui.admin.managing_countries" class="Sylius\Behat\Context\Ui\Admin\ManagingCountriesContext">
<argument type="service" id="sylius.behat.page.admin.country.index" />
<argument type="service" id="sylius.behat.page.admin.country.create" />

View file

@ -16,6 +16,13 @@
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"
>
<imports>
<import resource="elements/admin.xml" />
<import resource="elements/shop.xml" />
</imports>
<services>
<service id="sylius.behat.element" class="FriendsOfBehat\PageObjectExtension\Element\Element" abstract="true" public="false">
<argument type="service" id="mink.default_session" />
<argument>%__behat__.mink.parameters%</argument>
</service>
</services>
</container>

View file

@ -15,13 +15,9 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"
>
<parameters>
<parameter key="sylius.behat.element.shop.account.register.class">Sylius\Behat\Element\Shop\Account\RegisterElement</parameter>
</parameters>
<services>
<defaults public="true" />
<service id="sylius.behat.element.shop.account.register" class="%sylius.behat.element.shop.account.register.class%" parent="sylius.behat.symfony_page" public="false" />
<service id="sylius.behat.element.admin.channel.shop_billing_data" class="Sylius\Behat\Element\Admin\Channel\ShopBillingDataElement" parent="sylius.behat.element" public="false" />
</services>
</container>

View file

@ -15,7 +15,9 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"
>
<imports>
<import resource="shop/account.xml" />
</imports>
<services>
<defaults public="true" />
<service id="sylius.behat.element.shop.account.register" class="Sylius\Behat\Element\Shop\Account\RegisterElement" parent="sylius.behat.element" public="false" />
</services>
</container>

View file

@ -22,6 +22,7 @@ default:
- sylius.behat.context.setup.zone
- sylius.behat.context.ui.admin.managing_channels
- sylius.behat.context.ui.admin.managing_channels_billing_data
- sylius.behat.context.ui.admin.notification
filters:
tags: "@managing_channels && @ui"