Skip to content

Commit

Permalink
bug #14059 [Addressing] Enable orphan removal for zone members (coldic3)
Browse files Browse the repository at this point in the history
This PR was merged into the 1.11 branch.

Discussion
----------

| Q               | A                                                            |
|-----------------|--------------------------------------------------------------|
| Branch?         | 1.11          |
| Bug fix?        | yes                                                       |
| New feature?    | no                                                       |
| BC breaks?      | no                                                       |
| Deprecations?   | no |
| Related tickets | #14041                      |
| License         | MIT                                                          |

Without orphan removal, even if we delete the zone member, the corresponding province/country cannot be removed because orphans still exist in the database.

Commits
-------

47fef6e [Addressing] Enable orphan removal for zone members
  • Loading branch information
GSadee committed Jun 8, 2022
2 parents 7a66790 + 47fef6e commit 0be62fe
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 3 deletions.
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions src/Sylius/Behat/Context/Api/Admin/ManagingCountriesContext.php
Expand Up @@ -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
Expand Down Expand Up @@ -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
*/
Expand Down
13 changes: 13 additions & 0 deletions src/Sylius/Behat/Context/Setup/ZoneContext.php
Expand Up @@ -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$/
Expand Down
8 changes: 8 additions & 0 deletions src/Sylius/Behat/Context/Transform/ProvinceContext.php
Expand Up @@ -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]);
}
}
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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));
}
}

/**
Expand Down
Expand Up @@ -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
Expand Down
Expand Up @@ -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
Expand Down
Expand Up @@ -23,7 +23,7 @@
<field name="type" column="type" type="string" length="8" />
<field name="scope" column="scope" type="string" nullable="true"/>

<one-to-many field="members" target-entity="Sylius\Component\Addressing\Model\ZoneMemberInterface" mapped-by="belongsTo">
<one-to-many field="members" target-entity="Sylius\Component\Addressing\Model\ZoneMemberInterface" mapped-by="belongsTo" orphan-removal="true">
<cascade>
<cascade-all/>
</cascade>
Expand Down

0 comments on commit 0be62fe

Please sign in to comment.