diff --git a/features/addressing/managing_countries/managing_provinces_of_country.feature b/features/addressing/managing_countries/managing_provinces_of_country.feature
index ddc3b8f32d6..54e48630dbd 100644
--- a/features/addressing/managing_countries/managing_provinces_of_country.feature
+++ b/features/addressing/managing_countries/managing_provinces_of_country.feature
@@ -43,6 +43,23 @@ Feature: Managing provinces of a country
And this country should still have the "Scotland" province
And this country should still have the "England" province
+ @ui @javascript @api
+ Scenario: Removing a province that is not a zone member anymore should be possible
+ Given this country has the "Northern Ireland" province with "GB-NIR" code
+ And this country also has the "Scotland" province with "GB-SCT" code
+ And this country also has the "England" province with "GB-ENG" code
+ And the store has a zone "Great Britain" with code "GB"
+ And it has the "Northern Ireland" province member
+ And it also has the "Scotland" province member
+ And it also has the "England" province member
+ And the "England" province member has been removed from this zone
+ When I am editing this country
+ And I delete the "England" province of this country
+ And I save my changes
+ Then I should be notified that it has been successfully edited
+ And this country should not have the "England" province
+ And this country should still have the "Northern Ireland" and "Scotland" provinces
+
@ui @javascript @api
Scenario: Removing and adding a new province to an existing country
Given this country has the "Northern Ireland" province with "GB-NIR" code
diff --git a/src/Sylius/Behat/Context/Api/Admin/ManagingCountriesContext.php b/src/Sylius/Behat/Context/Api/Admin/ManagingCountriesContext.php
index 1db4dfe4977..0544aaf6259 100644
--- a/src/Sylius/Behat/Context/Api/Admin/ManagingCountriesContext.php
+++ b/src/Sylius/Behat/Context/Api/Admin/ManagingCountriesContext.php
@@ -75,6 +75,7 @@ public function iAddIt(): void
/**
* @When /^I want to edit (this country)$/
+ * @When /^I am editing (this country)$/
* @When /^I want to create a new province in (country "([^"]+)")$/
*/
public function iWantToEditThisCountry(CountryInterface $country): void
@@ -220,6 +221,16 @@ public function theCountryShouldHaveTheProvince(CountryInterface $country, Provi
));
}
+ /**
+ * @Then /^(this country) should(?:| still) have the ("[^"]*" and "[^"]*" provinces)$/
+ */
+ public function theCountryShouldHaveTheProvinceAndProvince(CountryInterface $country, array $provinces): void
+ {
+ foreach ($provinces as $province) {
+ $this->theCountryShouldHaveTheProvince($country, $province);
+ }
+ }
+
/**
* @Then the province should still be named :province in this country
*/
diff --git a/src/Sylius/Behat/Context/Setup/ZoneContext.php b/src/Sylius/Behat/Context/Setup/ZoneContext.php
index fa038133602..1a8a8a5cf3b 100644
--- a/src/Sylius/Behat/Context/Setup/ZoneContext.php
+++ b/src/Sylius/Behat/Context/Setup/ZoneContext.php
@@ -122,6 +122,19 @@ public function itHasTheCountryMemberAndTheCountryMember(
$this->objectManager->flush();
}
+ /**
+ * @Given /^(the "([^"]*)" (?:country|province|zone) member) has been removed from (this zone)$/
+ */
+ public function theZoneMemberHasBeenRemoved(
+ ZoneMemberInterface $zoneMember,
+ string $zoneMemberName,
+ ZoneInterface $zone
+ ): void {
+ $zone->removeMember($zoneMember);
+
+ $this->objectManager->flush();
+ }
+
/**
* @Given /^(it) has the ("[^"]+" province) member$/
* @Given /^(it) also has the ("[^"]+" province) member$/
diff --git a/src/Sylius/Behat/Context/Transform/ProvinceContext.php b/src/Sylius/Behat/Context/Transform/ProvinceContext.php
index 01d3060bfed..360ad1d5bf7 100644
--- a/src/Sylius/Behat/Context/Transform/ProvinceContext.php
+++ b/src/Sylius/Behat/Context/Transform/ProvinceContext.php
@@ -44,4 +44,12 @@ public function getProvinceByName(string $provinceName): ProvinceInterface
return $province;
}
+
+ /**
+ * @Transform /^"([^"]*)" and "([^"]*)" provinces$/
+ */
+ public function getProvincesByName(string ...$provinceNames): array
+ {
+ return $this->provinceRepository->findBy(['name' => $provinceNames]);
+ }
}
diff --git a/src/Sylius/Behat/Context/Ui/Admin/ManagingCountriesContext.php b/src/Sylius/Behat/Context/Ui/Admin/ManagingCountriesContext.php
index 2fc210aed13..ee65f760d62 100644
--- a/src/Sylius/Behat/Context/Ui/Admin/ManagingCountriesContext.php
+++ b/src/Sylius/Behat/Context/Ui/Admin/ManagingCountriesContext.php
@@ -45,6 +45,7 @@ public function iWantToAddNewCountry()
/**
* @When /^I want to edit (this country)$/
+ * @When /^I am editing (this country)$/
*/
public function iWantToEditThisCountry(CountryInterface $country)
{
@@ -158,13 +159,16 @@ public function theCodeFieldShouldBeDisabled()
/**
* @Then /^(this country) should(?:| still) have the "([^"]*)" province$/
+ * @Then /^(this country) should(?:| still) have the "([^"]*)" and "([^"]*)" provinces$/
* @Then /^the (country "[^"]*") should(?:| still) have the "([^"]*)" province$/
*/
- public function countryShouldHaveProvince(CountryInterface $country, $provinceName)
+ public function countryShouldHaveProvince(CountryInterface $country, string ...$provinceNames)
{
$this->iWantToEditThisCountry($country);
- Assert::true($this->updatePage->isThereProvince($provinceName));
+ foreach ($provinceNames as $provinceName) {
+ Assert::true($this->updatePage->isThereProvince($provinceName));
+ }
}
/**
diff --git a/src/Sylius/Behat/Resources/config/suites/api/addressing/managing_countries.yml b/src/Sylius/Behat/Resources/config/suites/api/addressing/managing_countries.yml
index 98b48398f6c..dde258e5135 100644
--- a/src/Sylius/Behat/Resources/config/suites/api/addressing/managing_countries.yml
+++ b/src/Sylius/Behat/Resources/config/suites/api/addressing/managing_countries.yml
@@ -12,6 +12,7 @@ default:
- sylius.behat.context.transform.shared_storage
- sylius.behat.context.transform.lexical
+ - sylius.behat.context.transform.zone_member
- sylius.behat.context.setup.admin_api_security
- sylius.behat.context.setup.geographical
diff --git a/src/Sylius/Behat/Resources/config/suites/ui/addressing/managing_countries.yml b/src/Sylius/Behat/Resources/config/suites/ui/addressing/managing_countries.yml
index c96142c9afa..e50e2e0c40c 100644
--- a/src/Sylius/Behat/Resources/config/suites/ui/addressing/managing_countries.yml
+++ b/src/Sylius/Behat/Resources/config/suites/ui/addressing/managing_countries.yml
@@ -10,6 +10,7 @@ default:
- sylius.behat.context.transform.country
- sylius.behat.context.transform.province
- sylius.behat.context.transform.shared_storage
+ - sylius.behat.context.transform.zone_member
- sylius.behat.context.setup.admin_security
- sylius.behat.context.setup.geographical
diff --git a/src/Sylius/Bundle/AddressingBundle/Resources/config/doctrine/model/Zone.orm.xml b/src/Sylius/Bundle/AddressingBundle/Resources/config/doctrine/model/Zone.orm.xml
index 71e67e00ed3..e0a1ad3b1cd 100644
--- a/src/Sylius/Bundle/AddressingBundle/Resources/config/doctrine/model/Zone.orm.xml
+++ b/src/Sylius/Bundle/AddressingBundle/Resources/config/doctrine/model/Zone.orm.xml
@@ -23,7 +23,7 @@
-
+