Review fixes

This commit is contained in:
Arminek 2016-04-13 02:01:30 +02:00
parent 869c3f09d1
commit 8bf3e3b269
30 changed files with 293 additions and 447 deletions

View file

@ -74,8 +74,6 @@ install:
before_script:
- etc/travis/run-suite ${SYLIUS_SUITE} before_script
gulp
script:
- etc/travis/run-suite ${SYLIUS_SUITE} script

View file

@ -23,7 +23,6 @@
<parameter key="sylius.behat.context.setup.product.class">Sylius\Behat\Context\Setup\ProductContext</parameter>
<parameter key="sylius.behat.context.setup.product_review.class">Sylius\Behat\Context\Setup\ProductReviewContext</parameter>
<parameter key="sylius.behat.context.setup.promotion.class">Sylius\Behat\Context\Setup\PromotionContext</parameter>
<parameter key="sylius.behat.context.setup.province.class">Sylius\Behat\Context\Setup\ProvinceContext</parameter>
<parameter key="sylius.behat.context.setup.security.class">Sylius\Behat\Context\Setup\SecurityContext</parameter>
<parameter key="sylius.behat.context.setup.shipping.class">Sylius\Behat\Context\Setup\ShippingContext</parameter>
<parameter key="sylius.behat.context.setup.taxation.class">Sylius\Behat\Context\Setup\TaxationContext</parameter>
@ -31,7 +30,6 @@
<parameter key="sylius.behat.context.setup.theme.class">Sylius\Behat\Context\Setup\ThemeContext</parameter>
<parameter key="sylius.behat.context.setup.user.class">Sylius\Behat\Context\Setup\UserContext</parameter>
<parameter key="sylius.behat.context.setup.zone.class">Sylius\Behat\Context\Setup\ZoneContext</parameter>
<parameter key="sylius.behat.context.setup.zone_member.class">Sylius\Behat\Context\Setup\ZoneMemberContext</parameter>
</parameters>
<services>
@ -66,6 +64,7 @@
<argument type="service" id="sylius.repository.country" container="symfony" />
<argument type="service" id="sylius.converter.country_name" container="symfony" />
<argument type="service" id="sylius.manager.province" container="symfony" />
<argument type="service" id="sylius.repository.province" container="symfony" />
<tag name="sylius.behat.context" />
</service>
@ -125,13 +124,6 @@
<tag name="sylius.behat.context" />
</service>
<service id="sylius.behat.context.setup.province" class="%sylius.behat.context.setup.province.class%" scope="scenario">
<argument type="service" id="sylius.behat.shared_storage" container="symfony" />
<argument type="service" id="sylius.factory.province" container="symfony" />
<argument type="service" id="sylius.repository.province" container="symfony" />
<tag name="sylius.behat.context" />
</service>
<service id="sylius.behat.context.setup.security" class="%sylius.behat.context.setup.security.class%" scope="scenario">
<argument type="service" id="sylius.behat.shared_storage" container="symfony" />
<argument type="service" id="sylius.behat.security" />
@ -189,12 +181,8 @@
<argument type="service" id="sylius.behat.shared_storage" container="symfony" />
<argument type="service" id="sylius.repository.zone" container="symfony" />
<argument type="service" id="sylius.settings.manager" container="symfony" />
<argument type="service" id="sylius.factory.zone" container="symfony" />
<tag name="sylius.behat.context" />
</service>
<service id="sylius.behat.context.setup.zone_member" class="%sylius.behat.context.setup.zone_member.class%" scope="scenario">
<argument type="service" id="doctrine.orm.entity_manager" container="symfony" />
<argument type="service" id="sylius.factory.zone" container="symfony" />
<argument type="service" id="sylius.factory.zone_member" container="symfony" />
<tag name="sylius.behat.context" />
</service>

View file

@ -20,7 +20,7 @@
<parameter key="sylius.behat.context.ui.admin.managing_shipping_methods.class">Sylius\Behat\Context\Ui\Admin\ManagingShippingMethodsContext</parameter>
<parameter key="sylius.behat.context.ui.admin.managing_tax_category.class">Sylius\Behat\Context\Ui\Admin\ManagingTaxCategoryContext</parameter>
<parameter key="sylius.behat.context.ui.admin.managing_tax_rate.class">Sylius\Behat\Context\Ui\Admin\ManagingTaxRateContext</parameter>
<parameter key="sylius.behat.context.ui.admin.managing_zone.class">Sylius\Behat\Context\Ui\Admin\ManagingZoneContext</parameter>
<parameter key="sylius.behat.context.ui.admin.managing_zones.class">Sylius\Behat\Context\Ui\Admin\ManagingZonesContext</parameter>
<parameter key="sylius.behat.context.ui.cart.class">Sylius\Behat\Context\Ui\CartContext</parameter>
<parameter key="sylius.behat.context.ui.channel.class">Sylius\Behat\Context\Ui\ChannelContext</parameter>
@ -95,7 +95,7 @@
<tag name="sylius.behat.context" />
</service>
<service id="sylius.behat.context.ui.admin.managing_zone" class="%sylius.behat.context.ui.admin.managing_zone.class%" scope="scenario">
<service id="sylius.behat.context.ui.admin.managing_zones" class="%sylius.behat.context.ui.admin.managing_zones.class%" scope="scenario">
<argument type="service" id="sylius.behat.page.admin.zone.create" />
<argument type="service" id="sylius.behat.page.admin.zone.index" />
<argument type="service" id="sylius.behat.page.admin.zone.update" />

View file

@ -15,12 +15,10 @@ default:
- sylius.behat.context.transform.zone
- sylius.behat.context.setup.geographical
- sylius.behat.context.setup.province
- sylius.behat.context.setup.security
- sylius.behat.context.setup.taxation
- sylius.behat.context.setup.zone
- sylius.behat.context.setup.zone_member
- sylius.behat.context.ui.admin.managing_zone
- sylius.behat.context.ui.admin.managing_zones
filters:
tags: "@managing_zones && @ui"

View file

@ -6,36 +6,37 @@ Feature: Adding a new zone with country type members
Background:
Given the store has country "France"
And the store has a province "Alabama" with code "AL"
And the store also has country "United States"
And this country has the "Alabama" province with "AL" code
And the store has a zone "North America" with code "NA"
And I am logged in as an administrator
@ui @javascript
Scenario: Adding a zone with a country type member
Given I want to create a new zone with country members
Given I want to create a new zone consisting of country
When I name it "European Union"
And I specify its code as "EU"
And I add a country "France"
And I add it
Then I should be notified about successful creation
Then I should be notified that it has been successfully created
And the zone named "European Union" with the "France" country member should appear in the registry
@ui @javascript
Scenario: Adding a zone with province type member
Given I want to create a new zone with province members
Given I want to create a new zone consisting of province
When I name it "United States of America"
And I specify its code as "USA"
And I add a province "Alabama"
And I add it
Then I should be notified about successful creation
Then I should be notified that it has been successfully created
And the zone named "United States of America" with the "Alabama" province member should appear in the registry
@ui @javascript
Scenario: Adding a zone with zone type member
Given I want to create a new zone with zone members
Given I want to create a new zone consisting of zone
When I name it "America"
And I specify its code as "AM"
And I add a zone "North America"
And I add it
Then I should be notified about successful creation
Then I should be notified that it has been successfully created
And the zone named "America" with the "North America" zone member should appear in the registry

View file

@ -13,4 +13,4 @@ Feature: Browsing zones
Scenario: Browsing zones in store
Given I want to see all zones in store
Then I should see 2 zones in the list
And I should see the zone named "North America" in the list
And I should see the zone named "North America" in the list

View file

@ -8,7 +8,7 @@ Feature: Deleting a zone
Given the store has a zone "North America" with code "NA"
And the store also has a zone "South America" with code "SA"
And the store has a tax category "Sports gear"
And the store has "European Union Sales Tax" tax rate of 20% for "Sports gear" within "SA" zone
And the store has "Sales Tax" tax rate of 20% for "Sports gear" within "SA" zone
And I am logged in as an administrator
@ui
@ -18,7 +18,7 @@ Feature: Deleting a zone
And the zone named "North America" should no longer exist in the registry
@ui
Scenario: Delete zone with associated tax rates should not be possible
Scenario: Deleting zone with associated tax rates should not be possible
When I delete zone named "South America"
Then I should be notified that this zone cannot be deleted
And I should still see the zone named "South America" in the list

View file

@ -1,14 +1,14 @@
@managing_zones
Feature: Editing a zone
In order to change the membership of areas
In order to change my my tax and shipping configuration
As an Administrator
I want to be able to edit a zone
Background:
Given the store has country "France"
And the store also has country "Germany"
And the store has a province "Alabama" with code "AL"
And the store has a province "Arizona" with code "AZ"
Given the store operates in "France" and "Germany"
And the store also has country "United States"
And this country has the "Alabama" province with "AL" code
And this country has the "Arizona" province with "AZ" code
And the store has a zone "North America" with code "NA"
And the store has a zone "South America" with code "SA"
And I am logged in as an administrator
@ -21,7 +21,7 @@ Feature: Editing a zone
And I want to modify the zone named "European Union"
When I remove the "Germany" country member
And I save my changes
Then I should be notified about successful edition
Then I should be notified that it has been successfully edited
And this zone should have only the "France" country member
@ui @javascript
@ -32,7 +32,7 @@ Feature: Editing a zone
And I want to modify the zone named "United States of America"
When I remove the "Arizona" province member
And I save my changes
Then I should be notified about successful edition
Then I should be notified that it has been successfully edited
And this zone should have only the "Alabama" province member
@ui @javascript
@ -43,7 +43,7 @@ Feature: Editing a zone
And I want to modify the zone named "America"
When I remove the "North America" zone member
And I save my changes
Then I should be notified about successful edition
Then I should be notified that it has been successfully edited
And this zone should have only the "South America" zone member
@ui
@ -53,7 +53,7 @@ Feature: Editing a zone
And I want to modify the zone named "European Union"
When I rename it to "EU"
And I save my changes
Then I should be notified about successful edition
Then I should be notified that it has been successfully edited
And this zone name should be "EU"
@ui

View file

@ -12,7 +12,7 @@ Feature: Zone unique code validation
@ui
Scenario: Trying to add zone with taken code
Given I want to create a new zone with country members
Given I want to create a new zone consisting of country
When I specify its code as "EU"
And I name it "European Union"
And I try to add it

View file

@ -10,7 +10,7 @@ Feature: Zone validation
@ui
Scenario: Trying to add a zone without specifying its code
Given I want to create a new zone with country members
Given I want to create a new zone consisting of country
When I name it "European Union"
But I do not specify its code
And I try to add it
@ -19,7 +19,7 @@ Feature: Zone validation
@ui
Scenario: Trying to add a zone without specifying its name
Given I want to create a new zone with country members
Given I want to create a new zone consisting of country
When I specify its code as "EU"
But I do not specify its name
And I try to add it
@ -27,8 +27,8 @@ Feature: Zone validation
And zone with code "EU" should not be added
@ui
Scenario: Trying to add a zone without adding country member
Given I want to create a new zone with country members
Scenario: Trying to add a zone without any countries
Given I want to create a new zone consisting of country
When I name it "European Union"
And I specify its code as "EU"
But I do not add a country member
@ -38,12 +38,12 @@ Feature: Zone validation
@ui
Scenario: Seeing a disabled type field when adding country type zone
Given I want to create a new zone with country members
Given I want to create a new zone consisting of country
Then the type field should be disabled
And it should be country type
@ui
Scenario: Seeing a disabled type field when adding province type zone
Given I want to create a new zone with province members
Given I want to create a new zone consisting of province
Then the type field should be disabled
And it should be province type

View file

@ -98,15 +98,21 @@ final class GeographicalContext implements Context
/**
* @Given /^the store operates in "([^"]*)"$/
* @Given /^the store has country "([^"]*)"$/
* @Given /^the store also has country "([^"]*)"$/
* @Given /^the store operates in "([^"]*)" and "([^"]*)"$/
* @Given /^the store(?:| also) has country "([^"]*)"$/
*/
public function theStoreOperatesIn($countryName)
public function theStoreOperatesIn($firstCountryName, $secondCountryName = null)
{
$country = $this->createCountryNamed(trim($countryName));
$this->sharedStorage->set('country', $country);
foreach ([$firstCountryName, $secondCountryName] as $countryName) {
if (null === $countryName) {
break;
}
$this->countryRepository->add($country);
$country = $this->createCountryNamed(trim($countryName));
$this->sharedStorage->set('country', $country);
$this->countryRepository->add($country);
}
}
/**
@ -121,6 +127,23 @@ final class GeographicalContext implements Context
$this->countryRepository->add($country);
}
/**
* @Given /^(this country) has the "([^"]+)" province with "([^"]+)" code$/
* @Given /^(country "[^"]+") has the "([^"]+)" province with "([^"]+)" code$/
*/
public function theCountryHasProvinceWithCode(CountryInterface $country, $name, $code)
{
/** @var ProvinceInterface $province */
$province = $this->provinceFactory->createNew();
$province->setName($name);
$province->setCode($code);
$country->addProvince($province);
$this->sharedStorage->set('province', $province);
$this->countryManager->flush();
}
/**
* @param string $name
*
@ -134,19 +157,4 @@ final class GeographicalContext implements Context
return $country;
}
/**
* @Given /^(this country) has the "([^"]+)" province with "([^"]+)" code$/
*/
public function theCountryHasProvinceWithCode(CountryInterface $country, $name, $code)
{
/** @var ProvinceInterface $province */
$province = $this->provinceFactory->createNew();
$province->setName($name);
$province->setCode($code);
$country->addProvince($province);
$this->countryManager->flush();
}
}

View file

@ -1,63 +0,0 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sylius\Behat\Context\Setup;
use Behat\Behat\Context\Context;
use Sylius\Component\Core\Test\Services\SharedStorageInterface;
use Sylius\Component\Resource\Factory\FactoryInterface;
use Sylius\Component\Resource\Repository\RepositoryInterface;
/**
* @author Arkadiusz Krakowiak <arkadiusz.krakowiak@lakion.com>
*/
final class ProvinceContext implements Context
{
/**
* @var SharedStorageInterface
*/
private $sharedStorage;
/**
* @var FactoryInterface
*/
private $provinceFactory;
/**
* @var RepositoryInterface
*/
private $provinceRepository;
/**
* @param SharedStorageInterface $sharedStorage
* @param FactoryInterface $provinceFactory
* @param RepositoryInterface $provinceRepository
*/
public function __construct(SharedStorageInterface $sharedStorage, FactoryInterface $provinceFactory, RepositoryInterface $provinceRepository)
{
$this->sharedStorage = $sharedStorage;
$this->provinceFactory = $provinceFactory;
$this->provinceRepository = $provinceRepository;
}
/**
* @Given the store has a province :provinceName with code :code
*/
public function theStoreHasAProvinceWithCode($provinceName, $code)
{
$province = $this->provinceFactory->createNew();
$province->setName($provinceName);
$province->setCode($code);
$this->sharedStorage->set('province', $province);
$this->provinceRepository->add($province);
}
}

View file

@ -12,11 +12,17 @@
namespace Sylius\Behat\Context\Setup;
use Behat\Behat\Context\Context;
use Doctrine\Common\Persistence\ObjectManager;
use Sylius\Bundle\AddressingBundle\Factory\ZoneFactoryInterface;
use Sylius\Bundle\SettingsBundle\Manager\SettingsManagerInterface;
use Sylius\Component\Addressing\Model\CountryInterface;
use Sylius\Component\Addressing\Model\ProvinceInterface;
use Sylius\Component\Addressing\Model\ZoneInterface;
use Sylius\Component\Addressing\Model\ZoneMemberInterface;
use Sylius\Component\Addressing\Repository\ZoneRepositoryInterface;
use Sylius\Component\Core\Test\Services\SharedStorageInterface;
use Sylius\Component\Resource\Factory\FactoryInterface;
use Sylius\Component\Resource\Model\CodeAwareInterface;
use Symfony\Component\Intl\Intl;
/**
@ -48,27 +54,43 @@ final class ZoneContext implements Context
*/
private $settingsManager;
/**
* @var ObjectManager
*/
private $objectManager;
/**
* @var ZoneFactoryInterface
*/
private $zoneFactory;
/**
* @var FactoryInterface
*/
private $zoneMemberFactory;
/**
* @param SharedStorageInterface $sharedStorage
* @param ZoneRepositoryInterface $zoneRepository
* @param SettingsManagerInterface $settingsManager
* @param ObjectManager $objectManager
* @param ZoneFactoryInterface $zoneFactory
* @param FactoryInterface $zoneMemberFactory
*/
public function __construct(
SharedStorageInterface $sharedStorage,
ZoneRepositoryInterface $zoneRepository,
SettingsManagerInterface $settingsManager,
ZoneFactoryInterface $zoneFactory
ObjectManager $objectManager,
ZoneFactoryInterface $zoneFactory,
FactoryInterface $zoneMemberFactory
) {
$this->sharedStorage = $sharedStorage;
$this->zoneRepository = $zoneRepository;
$this->settingsManager = $settingsManager;
$this->objectManager = $objectManager;
$this->zoneFactory = $zoneFactory;
$this->zoneMemberFactory = $zoneMemberFactory;
}
/**
@ -137,4 +159,61 @@ final class ZoneContext implements Context
$this->sharedStorage->set('zone', $zone);
$this->zoneRepository->add($zone);
}
/**
* @Given /^(it)(?:| also) has the ("([^"]+)" country) member$/
* @Given /^(this zone)(?:| also) has the ("([^"]+)" country) member$/
*/
public function itHasTheCountryMemberAndTheCountryMember(
ZoneInterface $zone,
CountryInterface $country
) {
$zone->setType(ZoneInterface::TYPE_COUNTRY);
$zone->addMember($this->createZoneMember($country));
$this->objectManager->flush();
}
/**
* @Given /^(it) has the ("([^"]+)" province) member$/
* @Given /^(it) also has the ("([^"]+)" province) member$/
*/
public function itHasTheProvinceMemberAndTheProvinceMember(
ZoneInterface $zone,
ProvinceInterface $province
) {
$zone->setType(ZoneInterface::TYPE_PROVINCE);
$zone->addMember($this->createZoneMember($province));
$this->objectManager->flush();
}
/**
* @Given /^(it) has the (zone named "([^"]+)")$/
* @Given /^(it) also has the (zone named "([^"]+)")$/
*/
public function itHasTheZoneMemberAndTheZoneMember(
ZoneInterface $parentZone,
ZoneInterface $childZone
) {
$parentZone->setType(ZoneInterface::TYPE_ZONE);
$parentZone->addMember($this->createZoneMember($childZone));
$this->objectManager->flush();
}
/**
* @param CodeAwareInterface $zoneMember
*
* @return ZoneMemberInterface
*/
private function createZoneMember(CodeAwareInterface $zoneMember)
{
$code = $zoneMember->getCode();
/** @var ZoneMemberInterface $zoneMember */
$zoneMember = $this->zoneMemberFactory->createNew();
$zoneMember->setCode($code);
return $zoneMember;
}
}

View file

@ -1,108 +0,0 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sylius\Behat\Context\Setup;
use Behat\Behat\Context\Context;
use Doctrine\Common\Persistence\ObjectManager;
use Sylius\Component\Addressing\Model\CountryInterface;
use Sylius\Component\Addressing\Model\ProvinceInterface;
use Sylius\Component\Addressing\Model\ZoneInterface;
use Sylius\Component\Addressing\Model\ZoneMemberInterface;
use Sylius\Component\Resource\Factory\FactoryInterface;
use Sylius\Component\Resource\Model\CodeAwareInterface;
/**
* @author Arkadiusz Krakowiak <arkadiusz.krakowiak@lakion.com>
*/
final class ZoneMemberContext implements Context
{
/**
* @var ObjectManager
*/
private $objectManager;
/**
* @var FactoryInterface
*/
private $zoneMemberFactory;
/**
* @param ObjectManager $objectManager
* @param FactoryInterface $zoneMemberFactory
*/
public function __construct(
ObjectManager $objectManager,
FactoryInterface $zoneMemberFactory
) {
$this->objectManager = $objectManager;
$this->zoneMemberFactory = $zoneMemberFactory;
}
/**
* @Given /^(it) has the ("([^"]*)" country) member$/
* @Given /^(this zone) has the ("([^"]*)" country) member$/
* @Given /^(it) also has the ("([^"]*)" country) member$/
* @Given /^(this zone) also has the ("([^"]*)" country) member$/
*/
public function itHasTheCountryMemberAndTheCountryMember(
ZoneInterface $zone,
CountryInterface $country
) {
$zone->setType(ZoneInterface::TYPE_COUNTRY);
$zone->addMember($this->createZoneMember($country));
$this->objectManager->flush();
}
/**
* @Given /^(it) has the ("([^"]*)" province) member$/
* @Given /^(it) also has the ("([^"]*)" province) member$/
*/
public function itHasTheProvinceMemberAndTheProvinceMember(
ZoneInterface $zone,
ProvinceInterface $province
) {
$zone->setType(ZoneInterface::TYPE_PROVINCE);
$zone->addMember($this->createZoneMember($province));
$this->objectManager->flush();
}
/**
* @Given /^(it) has the (zone named "([^"]*)")$/
* @Given /^(it) also has the (zone named "([^"]*)")$/
*/
public function itHasTheZoneMemberAndTheZoneMember(
ZoneInterface $parentZone,
ZoneInterface $childZone
) {
$parentZone->setType(ZoneInterface::TYPE_ZONE);
$parentZone->addMember($this->createZoneMember($childZone));
$this->objectManager->flush();
}
/**
* @param CodeAwareInterface $zoneMember
*
* @return ZoneMemberInterface
*/
private function createZoneMember(CodeAwareInterface $zoneMember)
{
$code = $zoneMember->getCode();
/** @var ZoneMemberInterface $zoneMember */
$zoneMember = $this->zoneMemberFactory->createNew();
$zoneMember->setCode($code);
return $zoneMember;
}
}

View file

@ -13,11 +13,12 @@ namespace Sylius\Behat\Context\Transform;
use Behat\Behat\Context\Context;
use Sylius\Component\Resource\Repository\RepositoryInterface;
use Webmozart\Assert\Assert;
/**
* @author Arkadiusz Krakowiak <arkadiusz.krakowiak@lakion.com>
*/
class ProvinceContext implements Context
final class ProvinceContext implements Context
{
/**
* @var RepositoryInterface
@ -39,10 +40,10 @@ class ProvinceContext implements Context
public function getProvinceByName($name)
{
$province = $this->provinceRepository->findOneBy(['name' => $name]);
if (null === $province) {
throw new \InvalidArgumentException(sprintf('Cannot find province %s', $name));
}
Assert::notNull(
$province,
sprintf('Cannot find province %s', $name)
);
return $province;
}

View file

@ -14,6 +14,7 @@ namespace Sylius\Behat\Context\Transform;
use Behat\Behat\Context\Context;
use Sylius\Component\Addressing\Model\ZoneInterface;
use Sylius\Component\Addressing\Repository\ZoneRepositoryInterface;
use Webmozart\Assert\Assert;
/**
* @author Łukasz Chruściel <lukasz.chrusciel@lakion.com>
@ -44,7 +45,7 @@ final class ZoneContext implements Context
}
/**
* @Transform zone named :zoneName
* @Transform /^zone named "([^"]+)"$/
*/
public function getZoneByName($name)
{
@ -73,9 +74,10 @@ final class ZoneContext implements Context
private function getZoneBy(array $parameters)
{
$existingZone = $this->zoneRepository->findOneBy($parameters);
if (null === $existingZone) {
throw new \InvalidArgumentException(sprintf('Zone does not exist.'));
}
Assert::notNull(
$existingZone,
'Zone does not exist.'
);
return $existingZone;
}

View file

@ -17,6 +17,7 @@ use Sylius\Component\Addressing\Model\ProvinceInterface;
use Sylius\Component\Addressing\Model\ZoneInterface;
use Sylius\Component\Addressing\Model\ZoneMemberInterface;
use Sylius\Component\Resource\Repository\RepositoryInterface;
use Webmozart\Assert\Assert;
/**
* @author Arkadiusz Krakowiak <arkadiusz.krakowiak@lakion.com>
@ -62,7 +63,7 @@ final class ZoneMemberContext implements Context
}
/**
* @Transform the :countryName country member
* @Transform the :name country member
*/
public function getCountryTypeZoneMemberByName($name)
{
@ -98,14 +99,16 @@ final class ZoneMemberContext implements Context
* @param string $code
*
* @return ZoneMemberInterface
*
* @throws \InvalidArgumentException
*/
private function getZoneMemberByCode($code)
{
$zoneMember = $this->zoneMemberRepository->findOneBy(['code' => $code]);
if (null === $zoneMember) {
throw new \InvalidArgumentException(sprintf('Zone member with code %s does not exist.', $code));
}
Assert::notNull(
$zoneMember,
sprintf('Zone member with code %s does not exist.', $code)
);
return $zoneMember;
}
@ -114,14 +117,16 @@ final class ZoneMemberContext implements Context
* @param string $name
*
* @return ProvinceInterface
*
* @throws \InvalidArgumentException
*/
private function getProvinceByName($name)
{
$province = $this->provinceRepository->findOneBy(['name' => $name]);
if (null === $province) {
throw new \InvalidArgumentException(sprintf('Province with name %s does not exist.', $name));
}
Assert::notNull(
$province,
sprintf('Province with name %s does not exist.', $name)
);
return $province;
}
@ -130,14 +135,16 @@ final class ZoneMemberContext implements Context
* @param string $name
*
* @return ZoneInterface
*
* @throws \InvalidArgumentException
*/
private function getZoneByName($name)
{
$zone = $this->zoneRepository->findOneBy(['name' => $name]);
if (null === $zone) {
throw new \InvalidArgumentException(sprintf('Zone with name %s does not exist.', $name));
}
Assert::notNull(
$zone,
sprintf('Zone with name %s does not exist.', $name)
);
return $zone;
}

View file

@ -17,7 +17,7 @@ use Sylius\Behat\Page\Admin\Zone\UpdatePageInterface;
use Sylius\Behat\Page\Admin\Zone\CreatePageInterface;
use Sylius\Behat\Service\CurrentPageResolverInterface;
use Sylius\Behat\Service\NotificationCheckerInterface;
use Sylius\Behat\Service\NotificationType;
use Sylius\Behat\NotificationType;
use Sylius\Component\Addressing\Model\ZoneInterface;
use Sylius\Component\Addressing\Model\ZoneMemberInterface;
use Webmozart\Assert\Assert;
@ -25,7 +25,7 @@ use Webmozart\Assert\Assert;
/**
* @author Arkadiusz Krakowiak <arkadiusz.krakowiak@lakion.com>
*/
final class ManagingZoneContext implements Context
final class ManagingZonesContext implements Context
{
const RESOURCE_NAME = 'zone';
@ -76,7 +76,7 @@ final class ManagingZoneContext implements Context
}
/**
* @Given I want to create a new zone with :memberType members
* @Given I want to create a new zone consisting of :memberType
*/
public function iWantToCreateANewZoneWithMembers($memberType)
{
@ -109,9 +109,7 @@ final class ManagingZoneContext implements Context
}
/**
* @When /^I remove (the "([^"]*)" province member)$/
* @When /^I remove (the "([^"]*)" country member)$/
* @When /^I remove (the "([^"]*)" zone member)$/
* @When /^I remove (the "([^"]*)" (?:country|province|zone) member)$/
*/
public function iRemoveTheMember(ZoneMemberInterface $zoneMember)
{
@ -167,11 +165,9 @@ final class ManagingZoneContext implements Context
}
/**
* @When I add a country :name
* @When I add a province :name
* @When I add a zone :name
* @When /^I add a(?: country| province| zone) "([^"]+)"$/
*/
public function iAddACountry($name)
public function iAddAZoneMember($name)
{
$this->createPage->addMember();
$this->createPage->chooseMember($name);
@ -195,7 +191,7 @@ final class ManagingZoneContext implements Context
}
/**
* @Then I should be notified about successful creation
* @Then I should be notified that it has been successfully created
*/
public function iShouldBeNotifiedAboutSuccessfulCreation()
{
@ -203,7 +199,7 @@ final class ManagingZoneContext implements Context
}
/**
* @Then I should be notified about successful edition
* @Then I should be notified that it has been successfully edited
*/
public function iShouldBeNotifiedAboutSuccessfulEdition()
{
@ -219,9 +215,7 @@ final class ManagingZoneContext implements Context
}
/**
* @Then /^the (zone named "[^"]+") with (the "[^"]+" country member) should appear in the registry$/
* @Then /^the (zone named "[^"]+") with (the "[^"]+" province member) should appear in the registry$/
* @Then /^the (zone named "[^"]+") with (the "[^"]+" zone member) should appear in the registry$/
* @Then /^the (zone named "[^"]+") with (the "[^"]+" (?:country|province|zone) member) should appear in the registry$/
*/
public function theZoneWithTheCountryShouldAppearInTheRegistry(ZoneInterface $zone, ZoneMemberInterface $zoneMember)
{
@ -229,9 +223,7 @@ final class ManagingZoneContext implements Context
}
/**
* @Then /^(this zone) should have only (the "([^"]*)" country member)$/
* @Then /^(this zone) should have only (the "([^"]*)" province member)$/
* @Then /^(this zone) should have only (the "([^"]*)" zone member)$/
* @Then /^(this zone) should have only (the "([^"]*)" (?:country|province|zone) member)$/
*/
public function thisZoneShouldHaveOnlyTheProvinceMember(ZoneInterface $zone, ZoneMemberInterface $zoneMember)
{
@ -251,7 +243,7 @@ final class ManagingZoneContext implements Context
{
Assert::true(
$this->updatePage->hasResourceValues(['code' => $zone->getCode(), 'name' => $name]),
'Zone name should be modified but it is not'
sprintf('Zone should be named %s, but is %s', $name, $zone->getName())
);
}
@ -288,7 +280,7 @@ final class ManagingZoneContext implements Context
Assert::true(
$this->indexPage->isResourceOnPage(['code' => $code]),
sprintf('Zone with code %s cannot be founded.', $code)
sprintf('Zone with code %s cannot be found.', $code)
);
}
@ -314,7 +306,7 @@ final class ManagingZoneContext implements Context
Assert::false(
$this->indexPage->isResourceOnPage([$element => $value]),
sprintf('Zone with %s %s was created, but it should not.', $element, $value)
sprintf('Zone with %s %s was added, but it should not.', $element, $value)
);
}
@ -323,11 +315,9 @@ final class ManagingZoneContext implements Context
*/
public function iShouldBeNotifiedThatAtLeastOneZoneMemberIsRequired()
{
$currentPage = $this->currentPageResolver->getCurrentPageWithForm($this->createPage, $this->updatePage);
Assert::true(
$currentPage->checkValidationMessageFor('member', 'Please add at least 1 zone member.'),
sprintf('I should be notified that zone needs at least one zone member.')
$this->createPage->checkValidationMessageForMembers('Please add at least 1 zone member.'),
'I should be notified that zone needs at least one zone member.'
);
}
@ -369,7 +359,7 @@ final class ManagingZoneContext implements Context
*/
public function iShouldSeeZonesInTheList($number)
{
$resourcesOnPage = $this->indexPage->countAllResourcesOnPage();
$resourcesOnPage = $this->indexPage->countItems();
Assert::eq(
$number,
@ -379,8 +369,7 @@ final class ManagingZoneContext implements Context
}
/**
* @Then /^I should see the (zone named "([^"]*)") in the list$/
* @Then /^I should still see the (zone named "([^"]*)") in the list$/
* @Then /^I should(?:| still) see the (zone named "([^"]+)") in the list$/
*/
public function iShouldSeeTheZoneNamedInTheList(ZoneInterface $zone)
{
@ -406,13 +395,11 @@ final class ManagingZoneContext implements Context
*/
private function assertZoneAndItsMember(ZoneInterface $zone, ZoneMemberInterface $zoneMember)
{
$expectedZoneValues = [
'code' => $zone->getCode(),
'name' => $zone->getName(),
];
Assert::true(
$this->updatePage->hasResourceValues($expectedZoneValues),
$this->updatePage->hasResourceValues([
'code' => $zone->getCode(),
'name' => $zone->getName(),
]),
sprintf('Zone %s is not valid', $zone->getName())
);

View file

@ -52,20 +52,6 @@ class IndexPage extends SymfonyPage implements IndexPageInterface
$this->resourceName = strtolower($resourceName);
}
/**
* {@inheritdoc}
*/
public function countAllResourcesOnPage()
{
try {
$rows = $this->getElement('table')->findAll('css', 'tbody > tr');
return count($rows);
} catch (ElementNotFoundException $exception) {
return 0;
}
}
/**
* {@inheritdoc}
*/

View file

@ -18,11 +18,6 @@ use Sylius\Behat\Page\PageInterface;
*/
interface IndexPageInterface extends PageInterface
{
/**
* @return int
*/
public function countAllResourcesOnPage();
/**
* @param array $parameters
*

View file

@ -11,41 +11,50 @@
namespace Sylius\Behat\Page\Admin\Zone;
use Behat\Mink\Exception\ElementNotFoundException;
use Sylius\Behat\Behaviour\NamesIt;
use Sylius\Behat\Behaviour\SpecifiesItsCode;
use Sylius\Behat\Page\Admin\Crud\CreatePage as BaseCreatePage;
use Sylius\Behat\Page\ElementNotFoundException;
use Webmozart\Assert\Assert;
/**
* @author Arkadiusz Krakowiak <arkadiusz.krakowiak@lakion.com>
*/
class CreatePage extends BaseCreatePage implements CreatePageInterface
{
use NamesIt, SpecifiesItsCode;
protected $elements = [
'code' => '#sylius_zone_code',
'name' => '#sylius_zone_name',
'type' => '#sylius_zone_type',
];
use NamesIt;
use SpecifiesItsCode;
public function addMember()
{
$this->getDocument()->clickLink('Add member');
}
/**
* {@inheritdoc}
*/
public function checkValidationMessageForMembers($message)
{
$membersValidationElement = $this->getElement('ui_segment')->find('css', '.ui.pointing');
if (null === $membersValidationElement) {
throw new ElementNotFoundException($this->getDriver(), 'members validation box', 'css', '.ui.pointing');
}
return $membersValidationElement->getText() === $message;
}
/**
* {@inheritdoc}
*/
public function chooseMember($name)
{
$selectItems = $this->getDocument()->waitFor(2*1000*1000, function () {
$selectItems = $this->getDocument()->waitFor(2, function () {
return $this->getDocument()->findAll('css', 'div[data-form-type="collection"] select');
});
$lastSelectItem = end($selectItems);
if (false === $lastSelectItem) {
throw new \RuntimeException('There is no select items.');
throw new ElementNotFoundException($this->getSession(), 'select', 'css', 'div[data-form-type="collection"] select');
}
$lastSelectItem->selectOption($name);
@ -56,14 +65,10 @@ class CreatePage extends BaseCreatePage implements CreatePageInterface
*/
public function hasType($type)
{
try {
$typeField = $this->getElement('type');
$selectedOption = $typeField->find('css', 'option[selected]');
$typeField = $this->getElement('type');
$selectedOption = $typeField->find('css', 'option[selected]');
return lcfirst($selectedOption->getText()) === $type;
} catch (ElementNotFoundException $exception) {
return false;
}
return lcfirst($selectedOption->getText()) === $type;
}
/**
@ -71,12 +76,19 @@ class CreatePage extends BaseCreatePage implements CreatePageInterface
*/
public function isTypeFieldDisabled()
{
try {
$typeField = $this->getElement('type');
return $this->getElement('type')->hasAttribute('disabled');
}
return $typeField->getAttribute('disabled') === 'disabled';
} catch (ElementNotFoundException $exception) {
return false;
}
/**
* {@inheritdoc}
*/
protected function getDefinedElements()
{
return array_merge(parent::getDefinedElements(), [
'code' => '#sylius_zone_code',
'name' => '#sylius_zone_name',
'type' => '#sylius_zone_type',
'ui_segment' => '.ui.segment',
]);
}
}

View file

@ -20,6 +20,11 @@ interface CreatePageInterface extends BaseCreatePageInterface
{
public function addMember();
/**
* @param string $message
*/
public function checkValidationMessageForMembers($message);
/**
* @param $name
*/

View file

@ -12,10 +12,10 @@
namespace Sylius\Behat\Page\Admin\Zone;
use Behat\Mink\Element\NodeElement;
use Behat\Mink\Exception\ElementNotFoundException;
use Sylius\Behat\Behaviour\ChecksCodeImmutability;
use Sylius\Behat\Behaviour\NamesIt;
use Sylius\Behat\Page\Admin\Crud\UpdatePage as BaseUpdatePage;
use Sylius\Behat\Page\ElementNotFoundException;
use Sylius\Component\Addressing\Model\ZoneMemberInterface;
/**
@ -23,31 +23,17 @@ use Sylius\Component\Addressing\Model\ZoneMemberInterface;
*/
class UpdatePage extends BaseUpdatePage implements UpdatePageInterface
{
use NamesIt, ChecksCodeImmutability;
/**
* @var array
*/
protected $elements = [
'code' => '#sylius_zone_code',
'name' => '#sylius_zone_name',
'type' => '#sylius_zone_type',
'member' => '.one.field',
'zone_members' => '#sylius_zone_members',
];
use NamesIt;
use ChecksCodeImmutability;
/**
* {@inheritdoc}
*/
public function countMembers()
{
try {
$selectedZoneMembers = $this->getSelectedZoneMembers();
$selectedZoneMembers = $this->getSelectedZoneMembers();
return count($selectedZoneMembers);
} catch (ElementNotFoundException $exception) {
return 0;
}
return count($selectedZoneMembers);
}
/**
@ -55,19 +41,15 @@ class UpdatePage extends BaseUpdatePage implements UpdatePageInterface
*/
public function hasMember(ZoneMemberInterface $zoneMember)
{
try {
$selectedZoneMembers = $this->getSelectedZoneMembers();
$selectedZoneMembers = $this->getSelectedZoneMembers();
foreach ($selectedZoneMembers as $selectedZoneMember) {
if ($selectedZoneMember->getValue() === $zoneMember->getCode()) {
return true;
}
foreach ($selectedZoneMembers as $selectedZoneMember) {
if ($selectedZoneMember->getValue() === $zoneMember->getCode()) {
return true;
}
return false;
} catch (ElementNotFoundException $exception) {
return false;
}
return false;
}
/**
@ -83,16 +65,11 @@ class UpdatePage extends BaseUpdatePage implements UpdatePageInterface
$selectedItem = $item->find('css', 'option[selected="selected"]');
if (null === $selectedItem) {
throw new \RuntimeException('Cannot find selected option');
throw new ElementNotFoundException($this->getDriver(), 'selected option', 'css', 'option[selected="selected"]');
}
if ($selectedItem->getValue() === $zoneMember->getCode()) {
$deleteButton = $item->find('css', 'a[data-form-collection="delete"]');
if (null === $deleteButton) {
throw new \RuntimeException('Cannot find delete button');
}
$deleteButton->click();
$this->getDeleteButtonForCollectionItem($item)->click();
break;
}
@ -109,6 +86,37 @@ class UpdatePage extends BaseUpdatePage implements UpdatePageInterface
return $this->getElement('code');
}
/**
* {@inheritdoc}
*/
protected function getDefinedElements()
{
return array_merge(parent::getDefinedElements(), [
'code' => '#sylius_zone_code',
'name' => '#sylius_zone_name',
'type' => '#sylius_zone_type',
'member' => '.one.field',
'zone_members' => '#sylius_zone_members',
]);
}
/**
* @param NodeElement $item
*
* @return NodeElement
*
* @throws ElementNotFoundException
*/
private function getDeleteButtonForCollectionItem(NodeElement $item)
{
$deleteButton = $item->find('css', 'a[data-form-collection="delete"]');
if (null === $deleteButton) {
throw new ElementNotFoundException($this->getDriver(), 'link', 'css', 'a[data-form-collection="delete"]');
}
return $deleteButton;
}
/**
* @return \Behat\Mink\Element\NodeElement[]
*

View file

@ -84,6 +84,12 @@ final class MainMenuBuilder extends AbstractAdminMenuBuilder
->setLabel('sylius.menu.admin.main.configuration.tax_rates')
->setLabelAttribute('icon', 'dollar')
;
$configurationSubMenu
->addChild('zones', ['route' => 'sylius_admin_zone_index'])
->setLabel('sylius.menu.admin.main.configuration.zones')
->setLabelAttribute('icon', 'world')
;
}
/**

View file

@ -15,13 +15,12 @@ sylius_grid:
type:
type: string
label: sylius.ui.type
scope:
type: string
label: sylius.ui.scope
actions:
main:
create:
type: create_zone
item:
delete:
type: delete
type: delete
update:
type: update

View file

@ -3,7 +3,7 @@ sylius_admin_zone:
alias: sylius.zone
section: admin
templates: SyliusAdminBundle:Crud
except: ['show']
except: ['show', 'create']
redirect: update
grid: sylius_admin_zone
vars:

View file

@ -9,6 +9,7 @@ sylius:
shipping_methods: Shipping methods
tax_categories: Tax categories
tax_rates: Tax rates
zones: Zones
marketing:
header: Marketing
promotions: Promotions

View file

@ -7,8 +7,8 @@
{{ 'sylius.ui.type'|trans }}
</div>
<div class="divider"></div>
<a class="item" href="{{ path(grid.requestConfiguration.getRouteName('create'), { 'type': 'country' }) }}"><i class="icon flag"></i>{{ 'sylius.form.zone.types.country'|trans }}</a>
<a class="item" href="{{ path(grid.requestConfiguration.getRouteName('create'), { 'type': 'province' }) }}"><i class="icon marker"></i>{{ 'sylius.form.zone.types.province'|trans }}</a>
<a class="item" href="{{ path(grid.requestConfiguration.getRouteName('create'), { 'type': 'zone' }) }}"><i class="icon location arrow"></i>{{ 'sylius.form.zone.types.zone'|trans }}</a>
<a class="item" href="{{ path(grid.requestConfiguration.getRouteName('create'), { 'type': 'country' }) }}">{{ 'sylius.form.zone.types.country'|trans }}</a>
<a class="item" href="{{ path(grid.requestConfiguration.getRouteName('create'), { 'type': 'province' }) }}">{{ 'sylius.form.zone.types.province'|trans }}</a>
<a class="item" href="{{ path(grid.requestConfiguration.getRouteName('create'), { 'type': 'zone' }) }}">{{ 'sylius.form.zone.types.zone'|trans }}</a>
</div>
</div>

View file

@ -6,4 +6,4 @@
{{ form_row(form.members) }}
{{ form_row(form.scope) }}
</div>
{{ form_rest(form) }}
{{ form_rest(form) }}

View file

@ -28,70 +28,6 @@
</div>
{%- endblock checkbox_row %}
{% block collection_widget -%}
{% from 'SyliusResourceBundle:Macros:notification.html.twig' import error %}
{% set attr = attr|merge({'class': attr.class|default ~ ' controls collection-widget'}) %}
{% spaceless %}
<div class="ui basic segment"
data-form-type="collection"
{{ block('widget_container_attributes') }}
{% if prototype is defined and allow_add %}
data-prototype='{{ _self.collectionItem(prototype, allow_delete, button_delete_label, '__name__')|e }}'
{%- endif -%}>
{{ error(form.vars.errors) }}
{% if prototypes|default is iterable %}
{% for key, subPrototype in prototypes %}
<input type="hidden"
data-form-prototype="{{ key }}"
value="{{ _self.collectionItem(subPrototype, allow_delete, button_delete_label, '__name__')|e }}" />
{% endfor %}
{% endif %}
<div data-form-collection="list"
class="ui segments">
{% for child in form %}
{{ _self.collectionItem(child, allow_delete, button_delete_label, loop.index0) }}
{% endfor %}
</div>
{% if prototype is defined and allow_add %}
<a href="#" class="ui green labeled icon button"
data-form-collection="add">
<i class="tag icon"></i>
{{ button_add_label|trans }}
</a>
{% endif %}
</div>
{% endspaceless %}
{%- endblock collection_widget %}
{% macro collectionItem(form, allow_delete, button_delete_label, index) %}
{% spaceless %}
<div data-form-collection="item"
data-form-collection-index="{{ index }}"
class="ui basic segment">
<div class="collection-box{% if form|length == 1 %} unique-field{% endif %}">
{% if not form.children|length %}
{{ form_widget(form) }}
{% else %}
{{ form_rest(form) }}
{% endif %}
{% if allow_delete %}
<p class="text-right">
<a href="#" data-form-collection="delete" class="ui red labeled icon button">
<i class="trash icon"></i>
{{ button_delete_label|trans }}
</a>
</p>
{% endif %}
</div>
</div>
{% endspaceless %}
{% endmacro %}
{% block money_widget -%}
<div class="ui labeled input">
<div class="ui label">{{ sylius_currency_symbol() }}</div>