forked from Sylius/Sylius
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
minor Sylius#15324 Prevent from removing taxon that is in use by a pr…
…omotion rule (TheMilek) This PR was merged into the 1.13 branch. Discussion ---------- | Q | A | |-----------------|--------------------------------------------------------------| | Branch? | 1.13 <!-- see the comment below --> | | Bug fix? | yes | | New feature? | no | | BC breaks? | no | | Deprecations? | no <!-- don't forget to update the UPGRADE-*.md file --> | | License | MIT | <!-- - Bug fixes must be submitted against the 1.12 branch - Features and deprecations must be submitted against the 1.13 branch - Make sure that the correct base branch is set To be sure you are not breaking any Backward Compatibilities, check the documentation: https://docs.sylius.com/en/latest/book/organization/backward-compatibility-promise.html --> related to Sylius#15277 Commits ------- Prevent from removing taxon that is in use by a promotion rule [Upgrade] Update upgrade file Minor improvements
- Loading branch information
Showing
11 changed files
with
222 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
src/Sylius/Behat/Context/Api/Admin/RemovingTaxonContext.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Sylius package. | ||
* | ||
* (c) Sylius Sp. z o.o. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sylius\Behat\Context\Api\Admin; | ||
|
||
use Behat\Behat\Context\Context; | ||
use Sylius\Behat\Client\ApiClientInterface; | ||
use Sylius\Behat\Client\ResponseCheckerInterface; | ||
use Sylius\Behat\Context\Api\Resources; | ||
use Sylius\Behat\Service\SharedStorageInterface; | ||
use Sylius\Component\Core\Model\TaxonInterface; | ||
use Webmozart\Assert\Assert; | ||
|
||
final class RemovingTaxonContext implements Context | ||
{ | ||
public function __construct( | ||
private ApiClientInterface $client, | ||
private ResponseCheckerInterface $responseChecker, | ||
private SharedStorageInterface $sharedStorage, | ||
) { | ||
} | ||
|
||
/** | ||
* @When I (try to) delete taxon named :taxon | ||
*/ | ||
public function iDeleteTaxon(TaxonInterface $taxon): void | ||
{ | ||
$this->client->delete(Resources::TAXONS, $taxon->getCode()); | ||
$this->sharedStorage->set('taxon', $taxon); | ||
} | ||
|
||
/** | ||
* @Then /^(this taxon) should still exist$/ | ||
*/ | ||
public function theTaxonShouldStillExist(TaxonInterface $taxon): void | ||
{ | ||
$this->client->show(Resources::TAXONS, $taxon->getCode()); | ||
|
||
Assert::true($this->responseChecker->isShowSuccessful($this->client->getLastResponse())); | ||
} | ||
|
||
/** | ||
* @Then I should be notified that this taxon could not be deleted as it is in use by a promotion rule | ||
*/ | ||
public function iShouldBeNotifiedThatThisTaxonCouldNotBeDeleted(): void | ||
{ | ||
Assert::contains( | ||
$this->responseChecker->getError($this->client->getLastResponse()), | ||
'Cannot delete a taxon that is in use by a promotion rule.', | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/Sylius/Bundle/ApiBundle/Exception/TaxonCannotBeRemoved.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Sylius package. | ||
* | ||
* (c) Sylius Sp. z o.o. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sylius\Bundle\ApiBundle\Exception; | ||
|
||
/** @experimental */ | ||
final class TaxonCannotBeRemoved extends \RuntimeException | ||
{ | ||
public function __construct( | ||
string $message = 'Cannot delete, the taxon is in use.', | ||
int $code = 0, | ||
\Throwable $previous = null, | ||
) { | ||
parent::__construct($message, $code, $previous); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters